simple-peer icon indicating copy to clipboard operation
simple-peer copied to clipboard

peer.addTrack(), peer.addStream() throwing error when adding the user's displayMedia to an existing peer stream(camera and mic stream).

Open cold-magma opened this issue 3 years ago • 1 comments

What version of this package are you using? 9.11.0

What operating system, Node.js, and npm version? Windows 10 Node version - 14.16.0 npm version - 6.14.11

What happened? I created a mesh network of peers and passed the users' video and audio streams as the stream when establishing the connection. When I tried to add the user's navigator.mediaDevices.getDisplayMedia() stream to the existing peer, the peer connection gets destroyed and the following error stack is observed: image_2021-04-30_113232

the same peer signaling method was working fine when I used it for establishing the peer connection. However, this error is observed when I try to add the new Stream or add a new Track to the existing stream which was passed when creating the peer.

// initiator peer
const peer1 = new Peer({
    initiator:true,
    trickle: false,
    stream1 /* stream is a state variable containing a MediaStream object with the user's video and audio stream */ 
});

const peer2 = new Peer({
    initiator:false,
    trickle: false,
    stream2 /* stream is a state variable containing a MediaStream object with the user's video and audio stream */ 
});

//both peers got their respective streams. the signals were exchanged via socket.io
//adding screen stream/ track

navigator.mediaDevices.getDisplayMedia({cursor:true}).then(str =>{           
    let track = str.getTracks()[0] // only has one track        
    peer1.addTrack(track , stream1);
    /* tried adding a stream as well and observed the same error 
    peer1.addStream(str);
});

What did you expect to happen? The expectation was to still have the peer connection established with the new streams/tracks being provided to the users.

Are you willing to submit a pull request to fix this bug? No.

cold-magma avatar Apr 30 '21 06:04 cold-magma

Just a suggestion here, it helped me solve some reliability issues (but I'm not exactly sure if your issue might be related to your signaling instead).

Try importing webrtc-adapter before importing simple-peer: https://www.npmjs.com/package/webrtc-adapter


Or try this fork which has it included (and not yet published on npm): https://github.com/zenOSmosis/webrtc-peer It can be installed into your package w/

$  npm install github:https://github.com/zenOSmosis/webrtc-peer

i.e. You'd then use it by doing require('webrtc-peer') instead of require('simple-peer)

jzombie avatar May 09 '21 19:05 jzombie