简体   繁体   中英

WebRTC PeerConnection addTrack after connection established

I'm doing a video conference website. The use case is a user are showing camera and everyone already see here camera. It mean the connection is stable. And user want to share screen. After I have screen stream, I add track to peerConnection but remote computer not fire ontrack event.

Here is my code after I got screen stream:

       if (this.screenStream != null && 'getTracks' in this.screenStream) {
          this.screenStream.getTracks().forEach(track => {
            console.log('ADD TRACK FOR CONNECTION');
            // const sender = peerConnection.getSenders();
            peerConnection.addTrack(track, this.screenStream);
          });

        }

Please tell me what I was wrong, or guide me some solutions, thank you so much!

You need to renegotiate after addTrack. You can either do so manually by calling createOffer, setLocalDescription and setRemoteDescription or rely on the onnegotiationneeded callback to happen as described in https://blog.mozilla.org/webrtc/perfect-negotiation-in-webrtc/

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM