0

我在 React 应用程序中使用 Twilio Video JS SDK ( https://www.twilio.com/docs/video )。我想允许用户使用以下功能在移动设备上切换摄像机:

  switchCamera = (isRear = false) => {
    const { videoToken } = this.props;
    const { videoCameras } = this.state;

    if (videoToken) {
      let videoInput;

      if (isRear) {
        videoInput = videoCameras.filter(camera => camera.label.toLowerCase().includes('back'));
      } else {
        videoInput = videoCameras.filter(camera =>camera.label.toLowerCase().includes('front'));
      }
      createLocalVideoTrack({
        facingMode: isRear ? 'environment' : 'user',
        deviceId: { exact: videoInput[0].deviceId },
      }).then(async localVideoTrack => {
        if (this.state.room) {
          const { localParticipant } = this.state.room;
          const tracks = Array.from(localParticipant.videoTracks.values())
            .map(trackPublication => trackPublication.track);
          localParticipant.unpublishTracks(tracks);
          tracks.forEach(track => track.detach().forEach(element => element.remove()));
          await localParticipant.publishTrack(localVideoTrack);
          localVideoTrack.attach();
        }
      });
    }
  };

但是,当 localParticipant 切换摄像头时,他自己的视频源会消失,但所有其他参与者都可以看到切换的摄像头源。

如何防止 localParticipant 的视频源消失?

4

0 回答 0