webrtc video stream stop sharing

前端 未结 3 828
暗喜
暗喜 2021-02-04 19:12

I have created webrtc based video chat suing peerjs.

The local and remote video element is created using control:

local: \'video id= [local_peer_id] autoplay=\"t

3条回答
  •  日久生厌
    2021-02-04 19:38

    You need to know the difference between the HTML tags and the WebRTC streams...

    You can have streams running, without having them attached to any HTML tag, and the media can still be sent and received by each peer. So, each peer can attach the stream to a audio/video tag, and the tag will only act as a player that you use to play a stream that is already running.

    So, if you mute the HTML tag, you will only be muting the player, and not the stream. If you want to make anything to have effect on the other peer, you need to do stuff on the stream or in the peer connection.

    In particular, to mute and resume audio or video, you need to toggle the media tracks in the media stream

        // create a button to toggle video 
        var button = document.createElement("button");
        button.appendChild(document.createTextNode("Toggle Hold"));
    
        button.onclick = function(){
            mediaStream.getVideoTracks()[0].enabled =
             !(mediaStream.getVideoTracks()[0].enabled);
        }
    

    To pause/resume audio, use getAudioTracks() instead.

提交回复
热议问题