【问题标题】:Twilio Rooms API not working as expectedTwilio Rooms API 未按预期工作
【发布时间】:2016-10-24 12:26:31
【问题描述】:

我正在构建一个视频会议应用程序,以前使用的是 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:我使用 action cable 在参与者之间共享消息,以满足我的一些其他功能的要求。

我是否缺少任何其他配置,或者我是否需要从 twilio 方面启用任何东西?我正在使用这个tutorial

【问题讨论】:

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


    【解决方案1】:

    没有日志,我无法确定出了什么问题;不过,我确实看到您可以做出一些改进。

    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' });
      

    您可以在进行这些更改后重试吗?

    【讨论】:

    • 感谢您的回复。我已尝试根据您的建议改进我的代码。但仍然没有帮助我。在此附上我的 twilio 配置 logs。此外,在浏览日志时,我发现 tracks 正在通过 wss 消息发送。这阻碍了我增强应用程序的这个模块。 :(
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2011-07-23
    • 2016-01-29
    • 2023-03-21
    • 2017-10-24
    • 2016-03-16
    • 1970-01-01
    • 2020-08-12
    相关资源
    最近更新 更多