【发布时间】: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