Twilio Rooms API未按预期工作

时间:2016-10-24 12:26:32

标签: javascript ember.js twilio ruby-on-rails-5

我正在构建一个视频会议应用程序,之前使用的是Twilio会话API。根据Twilio最近的updates,我在twilio's quick start app的帮助下尝试了Rooms API。我在获取和附加远程参与者媒体轨道方面遇到了问题。在这里,我附上了代码示例,我正在使用的Twilio库和用于生成令牌的ruby代码。

注意:我使用Ember JS作为前端,ROR作为后端。

JavaScript代码:

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

Ruby代码:

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端启用任何内容?我正在使用此tutorial

1 个答案:

答案 0 :(得分:0)

没有日志,我不能确定出了什么问题;但是,我确实看到了一些改进。

  1. 您创建LocalMedia并向其添加MediaStream,但您从不使用它。相反,我认为你应该将它传递给你的connect电话,例如

    twilioClient.connect({to: 'randomRoomname', localMedia: localMedia}).then(function(activeRoom) {
    
  2. 您应该将audio: truevideo: true传递给getUserMedia来电,例如

    twilioVideo.getUserMedia({ audio: true, video: true }).then(function(mediaStream){
    
  3. 在最后一行,我认为如果getUserMedia失败,你应该处理错误情况,例如

    twilioVideo.getUserMedia({ audio: true, video: true }).then(function(mediaStream){
      // ...
    }, function(error) {
      console.error('getUserMedia failed:' + error);
    });
    
  4. 您可能还希望启用调试日志记录,例如

    var twilioClient = new twilioVideo.Client(data.video_token, { logLevel: 'debug' });
    
  5. 进行这些更改后可以重试吗?