[英]Twilio Rooms API not working as expected
我正在構建一個視頻會議應用程序,該應用程序以前使用的是Twilio對話API。 根據Twilio的最新更新 ,我在twilio的快速啟動應用程序的幫助下嘗試了Rooms API。 我在獲取和附加遠程參與者媒體軌道時遇到問題。 在這里,我附加了代碼示例,我正在使用的Twilio庫以及用於生成令牌的ruby代碼。
注意:我將Ember JS用於前端,並將ROR用於后端。
var twilioVideo = Twilio.Video;
Ember.debug('Initiaizing Video Client for ' + data.identity);
var twilioClient = new twilioVideo.Client(data.video_token);
Ember.debug('Initiaizing LocalMedia for ' + data.identity);
var localMedia = new twilioVideo.LocalMedia();
twilioVideo.getUserMedia().then(function(mediaStream){
localMedia.addStream(mediaStream);
localMedia.attach('#video-local');
twilioClient.connect({to: 'randomRoomname'}). then(function(activeRoom){
Ember.debug('Connected to the Room: ' + activeRoom.name);
activeRoom.participants.forEach(function(participant) {
participant.media.attach('div#remote-media');
Ember.debug("Already in activeRoom: '" + participant.identity + "'");
});
activeRoom.once('participantConnected', function(participant){
participant.media.attach('div#remote-media');
Ember.debug('Participant '+participant.identity+' is connected');
});
activeRoom.once('participantDisconnected', function(participant){
Ember.debug('Participant '+participant.identity+' is disconnected');
});
}, function(error) {
Ember.debug('Failed to connect to room as ' + error);
});
});
Twilio來自此CDN的視頻庫。
video_token = Twilio::Util::AccessToken.new(ENV['TWILIO_ACCOUNT_SID'], ENV['TWILIO_API_KEY'], ENV['TWILIO_API_SECRET'], 3600, identity)}
grant = Twilio::Util::AccessToken::VideoGrant.new
grant.configuration_profile_sid = ENV['TWILIO_CONFIGURATION_SID']
video_token.add_grant grant
json :identity => identity, :video_token => video_token.to_jwt
使用的Twilio-ruby gem:版本4.13.0。
PS:我使用動作電纜在參與者之間共享消息,以實現其他一些功能。
我是否缺少任何其他配置,還是需要從twilio方面啟用任何功能? 我正在使用本教程 。
沒有日志,我無法確定出了什么問題。 但是,我確實看到您可以進行一些改進。
您創建LocalMedia並向其中添加MediaStream,但是從不使用它。 相反,我認為您應該將其傳遞給您的connect
呼叫,例如
twilioClient.connect({to: 'randomRoomname', localMedia: localMedia}).then(function(activeRoom) {
您可能應該將audio: true
和video: true
傳遞給getUserMedia
調用,例如
twilioVideo.getUserMedia({ audio: true, video: true }).then(function(mediaStream){
在最后一行,我認為如果getUserMedia
失敗,您應該處理錯誤情況,例如
twilioVideo.getUserMedia({ audio: true, video: true }).then(function(mediaStream){ // ... }, function(error) { console.error('getUserMedia failed:' + error); });
您可能還希望啟用調試日志記錄,例如
var twilioClient = new twilioVideo.Client(data.video_token, { logLevel: 'debug' });
進行這些更改后,您可以重試嗎?
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.