Video streaming 本地VideoTrack上的Twilio可编程视频调用.disable()不';不要停止它的传播

Video streaming 本地VideoTrack上的Twilio可编程视频调用.disable()不';不要停止它的传播,video-streaming,webrtc,twilio,videochat,Video Streaming,Webrtc,Twilio,Videochat,我试图让我的用户通过禁用视频来减少带宽使用量,如果他们的呼叫是断断续续的。文件说: “禁用或暂停单个媒体曲目 要控制LocalVideoTrack的单个LocalAudioTrack的静音/非静音或暂停/非暂停状态,可以使用LocalTrack#enable和LocalTrack#disable方法。 " 然而,当我使用它时,本地媒体元素变黑(即停止渲染),但远程流(在另一个窗口中打开)仍然接收视频。下面是我正在使用的代码 createLocalVideoTrack().then(track =

我试图让我的用户通过禁用视频来减少带宽使用量,如果他们的呼叫是断断续续的。文件说:

“禁用或暂停单个媒体曲目

要控制LocalVideoTrack的单个LocalAudioTrack的静音/非静音或暂停/非暂停状态,可以使用LocalTrack#enable和LocalTrack#disable方法。 "

然而,当我使用它时,本地媒体元素变黑(即停止渲染),但远程流(在另一个窗口中打开)仍然接收视频。下面是我正在使用的代码

createLocalVideoTrack().then(track => {
            var localMediaContainer = document.getElementById(self.local_vid_id);
            var title = document.createElement('span')
            title.innerText = "Me";
            localMediaContainer.appendChild(title);
            var videoIcon = document.createElement('span')
            videoIcon.className = 'glyphicon glyphicon-facetime-video';
            videoIcon.title = 'Disable Video';
            videoIcon.videoTrack = track;
            videoIcon.onclick = (event) => {
                if (event.target.videoTrack.isEnabled) {
                    event.target.videoTrack.disable();
                    event.target.title = 'Enable Video';
                } else {
                    event.target.videoTrack.enable();
                    event.target.title = 'Disable Video';
                }
            }
            localMediaContainer.appendChild(videoIcon);
            localMediaContainer.appendChild(track.attach());
        });

有没有其他人遇到过这个问题,有没有简单的解决方法?

在这里回答我自己的问题,但希望其他人会发现它很有用

您需要删除videoTrack以停止发送。 我使用的代码的最终版本是

videoIcon.onclick = function(event) {
  if (event.target.videoTrack){
    self.room.localParticipant.videoTracks.forEach( (track) => {
      self.room.localParticipant.removeTrack(track,true);
    })
    trackRemoved(event.target.videoTrack);
    event.target.videoTrack.stop();
    event.target.title = 'Enable Video';
    event.target.videoTrack = undefined;
  } else {
    // Totally reconnect to the room
    self.stop();
    self.reconnect();
    self.startPreview();
  }
}

潜在的问题是,在调用
connect(token,options)
函数时,很可能没有使用新创建的本地曲目。因此,如果不在中指定
轨迹
,它将创建具有不同ID的新本地轨迹。因此,您可以通过通过
createLocalVideoTrack()
createLocalTrack()
函数创建的本地视频曲目查看本地视频,并通过在
connect()
函数期间创建的完全不同的本地视频曲目向远程参与者发送视频数据

因此,为了解决这个问题,您应该在选项中指定创建的轨迹,以便使用相同的轨迹或获取从connect()函数创建的轨迹。在此之后,如果调用
disable()
函数,它将在对话双方都静音

选项1-指定曲目。

const { connect, createLocalTracks } = require('twilio-video');

createLocalTracks({
  audio: true,
  video: true
}).then(localTracks => {
  return connect('$TOKEN', {
    name: 'my-room-name',
    tracks: localTracks
  });
}).then(room => {
  console.log('Connected to Room:', room.name);
  localTracks.forEach((track)=>{
     // hide camera after 5 seconds
     if(track.kind === 'video'){
       setTimeout(()=>{
         track.disable();
       } ,5000)  
     }
  }) 
});
选项1-使用通过连接创建的曲目

Twilio.Video.connect('$TOKEN', {name:'my-new-room'}).then(function(room) {
  console.log('Successfully joined a Room: ', room);
  room.localParticipant.tracks.forEach((track)=>{
     // hide camera after 5 seconds
     if(track.kind === 'video'){
       setTimeout(()=>{
         track.disable();
       } ,5000)  
     }
  });
  room.on('participantConnected', function(participant) {
    console.log('A remote Participant connected: ', participant);
  })
}, function(error) {
    console.error('Unable to connect to Room: ' +  error.message);
});

您好,您应该仍然无法在远程流上看到视频。您能否联系并描述一下这个问题,以便视频团队能够对此进行调查?谢谢。@philnash我通过调用
removeTrack
找到了记录在案的方法。在不完全重新连接到房间的情况下,无法创建新的视频曲目(重新启用),因此我认为这可能是与团队讨论的问题。嘿,是的,删除曲目会完全从连接中删除曲目,需要完全重新连接才能重新开始。禁用它不应该产生这样的成本,但如果它不起作用,那是没有用的!我已经让团队意识到了这个问题。谢谢