lundi 24 octobre 2016

Twilio Rooms API not working as expected

I'm building a video conference application, previously which was using Twilio conversation API. As per recent updates from Twilio,I tried the Rooms API with help of twilio's quick start app. I faced problem in fetching and attaching the remote participants media tracks. Here with I have attached the code sample, the Twilio library I'm using and ruby code for generating tokens.

Note: I use Ember JS for front end and ROR for back end.

JavaScript code:

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 Video library taken from this CDN.

Ruby code:

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 used: version 4.13.0.

PS: I use action cable to share messages between participants for some other features as my requirements.

Am I missing any other configurations or Do I need to enable anything from twilio side? I'm using this tutorial.




Aucun commentaire:

Enregistrer un commentaire