feross / simple-peer

📡 Simple WebRTC video, voice, and data channels
MIT License
7.36k stars 972 forks source link

Adding streams after connection is made #557

Closed omar94f closed 4 years ago

omar94f commented 4 years ago

Hi, I am trying to dynamically add a stream after onConnect event has fired, this makes the peer fire another offer which I didnt know would happen. I tried to to signal this offer back to the receiving peer but that caused a crash. So what would be the proper way to handle dynamically adding a stream to an established connection. Im sure Im missing something which is not clear from the documentation.

    var peer = new SimplePeer({
      initiator: true,
      trickle: false,

    })

this is how I am creating the initiating peer. On 'connect' I getUserMedia and call addStream(). Exactly how should I handle renegotiation for adding a stream? Thanks

t-mullen commented 4 years ago

Your signalling code should be prepared for any number of signalling events from both peers. There’s more events than just the second offer that you may not be passing.

Also consider using a signalling library like signalhub or simple-signal.

omar94f commented 4 years ago
Screen Shot 2019-10-14 at 4 54 07 PM

This is the error I get when I signal back the new offer after the addStream. Any idea as to what can be wrong?

t-mullen commented 4 years ago

data is the object or JSON string you passed into peer.signal(). It’s undefined, which means you passed undefined to peer.signal().

Make sure you’re passing signalling data and nothing else.

omar94f commented 4 years ago

Wow it was as simple as that cant believe I missed that, it did the job. Thanks for the help man really appreciate it.