0

我正在使用 twilio-video v2.7。

客观的:

停止后重新启动视频轨道。

用例:

视频关闭时关闭摄像头 LED 指示灯,反之亦然,就像 google meet 一样。

const toggleVideo = () => {
    const isOff = !isVideoOn;
    room.localParticipant.videoTracks.forEach((t) => {
      if (isOff) {
        t.track.enable();
        t.track.attach(screenRef.current)
      } else {
        t.track.disable();
        t.track.stop()
        t.unpublish()
        t.track.detach()
      }
    });
    setVideoToggle(isOff);
  };
4

2 回答 2

1

不久前,我使用此代码将媒体静音/取消静音。你可以随意改变它。如果有什么不清楚的,请在评论中告诉我。

/**
 * Mute/unmute your media in a Room.
 * @param {Room} room - The Room you have joined
 * @param {'audio'|'video'} kind - The type of media you want to mute/unmute
 * @param {'mute'|'unmute'} action - Whether you want to mute/unmute
 */
function muteOrUnmuteYourMedia(room, kind, action) {
  const publications = kind === 'audio'
    ? room.localParticipant.audioTracks
    : room.localParticipant.videoTracks;

  publications.forEach(function(publication) {
    if (action === 'mute') {
      publication.track.disable();
    } else {
      publication.track.enable();
    }
  });
}
/**
 * Mute your video in a Room.
 * @param {Room} room - The Room you have joined
 * @returns {void}
 */
function muteYourVideo(room) {
  muteOrUnmuteYourMedia(room, 'video', 'mute');
}
/**
 * UnMute your video in a Room.
 * @param {Room} room - The Room you have joined
 * @returns {void}
 */
function muteYourVideo(room) {
  muteOrUnmuteYourMedia(room, 'video', 'unmute');
}

于 2020-12-02T10:53:22.653 回答
0

我相信您需要重新发布视频轨道。只要您正在处理已发布的事件,这就足够了。

t.track.publish()

于 2020-09-28T16:48:44.573 回答