0

我想在lynckia/licode中实现打开和关闭相机功能。

当按下视频关闭按钮时,视频应该在本地和远程停止,而音轨仍然存在,并且相机灯也会关闭。当按下视频按钮时,视频轨道被添加到流中并开始在本地和远程显示,

下面的代码部分工作。当视频关闭时,本地和远程视频停止,但当再次打开时,视频在本地开始,但不在远程。

视频关闭:

   const tracks = this.localStream.stream.getTracks();
    
    tracks.forEach(function (track: any) {
        if (track.readyState == 'live' && track.kind === 'video') {
            track.stop();
        }
    });

    this.localStream.stream.removeTrack(this.localStream.stream.getVideoTracks()[0]);

    // @ts-ignore
    document.getElementById('streamlocal').srcObject = null;

视频开启:

    navigator.mediaDevices.getUserMedia({
        video: true
    }).then(stream => {

        this.localStream.stream.addTrack(stream.getVideoTracks()[0]);
        // @ts-ignore
        document.getElementById('streamlocal').srcObject = null;
        // @ts-ignore
        document.getElementById('streamlocal').srcObject = this.localStream.stream;
    })
4

0 回答 0