Twilio视频 - 没有视频和静音方法

时间:2017-07-11 11:16:43

标签: javascript twilio

您如何对本地参与者进行静音和禁止录像? https://www.twilio.com/docs/api/video/getting-started

此代码已在别处提出 - 但这是跟踪数据吗?

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

所以我会得到当地参与者的曲目

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

2 个答案:

答案 0 :(得分:3)

Twilio开发者传道者在这里。

您确实希望使用disable method on the local media tracks将其静音。

首先,请确保您使用的是Twilio Video Rooms API(在问题中提及conversation,不推荐使用对话API。)

然后,当您连接时,您可以获取本地参与者的媒体曲目,并在您喜欢时禁用或启用它们。像这样:

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

让我知道这是否有帮助。

答案 1 :(得分:0)

尝试以下代码,它对我有用。

    // 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);

    }