Twilio video — no video and mute methods

我只是一个虾纸丫 提交于 2019-12-11 04:54:58

问题


How do you mute and no-video the local participant? https://www.twilio.com/docs/api/video/getting-started

this code has been proposed elsewhere - but is this the track data?

var localMedia = conversation.localMedia;
localMedia.mute();

So would I get the tracks of the local participant

var tracks = Array.from(participant.tracks.values())

audioTrack.mute()? videoTrack.mute()?

document.getElementById('button-mute').onclick = function () {
  log('Mute call...')
  console.log('mute call')
  // var localMedia = conversation.localMedia
  // localMedia.mute()
}
document.getElementById('button-no-video').onclick = function () {
  log('No Vid call...')
  console.log('no vid')
}

回答1:


Twilio developer evangelist here.

You actually want to use the disable method on the local media tracks to mute them.

First, make sure you're using the Twilio Video Rooms API (you mention conversation in the question, the conversations API is deprecated).

Then, when you connect you can get hold of the local participants media tracks and disable or enable them when you like. Something like this:

Video.connect(token, { name: 'room-name' }).then(room => {
  const localParticipant = room.localParticipant;

  $button.on('click', event => {
    localParticipant.tracks.forEach((trackId, track) => {
      if (track.isEnabled) {
        track.disable();
      } else {
        track.enable();
      }
    })
  })
});

Let me know if that helps at all.




回答2:


Try following code, it worked for me.

    // name is video or audio
    vm.toggleMyDevices = function(kind){
        var localMedia = activeRoom.localParticipant;
        localMedia.tracks.forEach(function (track) {
            console.log(track);
            if(track.kind === kind){
                if (track.isEnabled) {
                    track.disable();
                    $scope.isPaused = true;
                } else {
                    track.enable();
                    $scope.isPaused = false;
                }
            }

        },kind);

    }


来源:https://stackoverflow.com/questions/45033029/twilio-video-no-video-and-mute-methods

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!