いつも皆様にお世話になっております。
ただいま、twilioのビデオ通話について試しています。
環境
ローカルに立てたlinuxサーバー
言語:ruby,javascript
フレームワーク:rails
Quickstartを元に以下の形で書いてみました。
【クライアント側】
Javascript
1var conversationsClient; 2var activeConversation; 3var previewMedia; 4var identity; 5 6// Check for WebRTC 7if (!navigator.webkitGetUserMedia && !navigator.mozGetUserMedia) { 8 alert('WebRTC is not available in your browser.'); 9} 10 11$.getJSON('/token', function(data) { 12 console.log(data.token); 13 var token = data.token; 14 15 var accessManager = new Twilio.AccessManager(token); 16 conversationsClient = new Twilio.Conversations.Client(accessManager); 17 conversationsClient.listen().then(clientConnected, function (error) { 18 log('Could not connect to Twilio: ' + error.message); 19 }); 20}); 21 22// Successfully connected! 23function clientConnected() { 24 document.getElementById('invite-controls').style.display = 'block'; 25 log("Connected to Twilio. Listening for incoming Invites as '" + conversationsClient.identity + "'"); 26 27 conversationsClient.on('invite', function (invite) { 28 log('Incoming invite from: ' + invite.from); 29 invite.accept().then(conversationStarted); 30 }); 31 32 // Bind button to create conversation 33 document.getElementById('button-invite').onclick = function () { 34 var inviteTo = document.getElementById('invite-to').value; 35 if (activeConversation) { 36 // Add a participant 37 activeConversation.invite(inviteTo); 38 } else { 39 // Create a conversation 40 var options = {}; 41 if (previewMedia) { 42 options.localMedia = previewMedia; 43 } 44 conversationsClient.inviteToConversation(inviteTo, options).then(conversationStarted, function (error) { 45 log('Unable to create conversation'); 46 console.error('Unable to create conversation', error); 47 }); 48 } 49 }; 50}
【サーバー側】
Ruby
1def token 2 identity = "user" 3 # Create an Access Token for Video usage 4 token = Twilio::Util::AccessToken.new <ACCOUNT_SID>, 5 <API_KEY>, <API_SECRET>, 3600, "user" 6 7 # Grant access to Conversations 8 grant = Twilio::Util::AccessToken::ConversationsGrant.new 9 grant.configuration_profile_sid = <CONFIG_SID> 10 token.add_grant grant 11 12 # Generate the token and send to client 13 render json: {identity: identity, token: token.to_jwt} 14end
この時,ウェブ側で見ると「Could not connect to Twilio: Gateway responded with: 31201 Authentication failed...」となってしまい接続することができません。上記の内容からTokenに問題があると思い試しに公式のテスターを使いそこで吐き出されたトークンを使用することで接続が可能でした。
【原因】
以上のことから、サーバー側で出力しているTokenの値が正しくないものを出力されているということはわかるのですが、なぜそのようなことになるのかがわかりません。
【求めているアドバイス】
上記の内容で疑わしい部分などありましたらご指摘いただければと思います。また不足している情報などありましたらそちらについてもご指摘いただければ捕捉、追記致します。
以上、どうぞ宜しくお願い致します。
あなたの回答
tips
プレビュー