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

peer.addStream(stream) doesn't raise event one other peer

Open Gruski opened this issue 3 years ago • 2 comments

using: v9.11.0 library directly referenced:

peer.addStream(stream) call on the initiator peer doesn't raise peer.on('stream', ...) event on the other peer after successful data connection. When stream is passed through the initiator peer constructor, the event does get raised. I was expecting the same to happen when peer.addStream(stream) was called in situations where the stream is no yet known at peer construction time.

Also when inspecting the 'peer' object in the console, after the peer.addStream() is called, the "streams" prop, which is an array, still has a length of 0. No stream is added. Probably a regression bug.

Gruski avatar Sep 10 '21 18:09 Gruski

I am having the same problem. Looking at #370 if a peer connection with no stream is initialized and the streams added later, we are supposed to pass constraints into our constructors:

var p1 = new Peer({initiator:true, offerConstraints: { offerToReceiveVideo: false, offerToReceiveAudio: false }) var p2 = new Peer({initiator:false, answerConstraints: { offerToReceiveVideo: false, offerToReceiveAudio: false })

Then once the new stream is to be added, before doing so the initiator must be signaled to accept audio/video using the setConstraints method:

var newConstraints = { offerToReceiveAudio: true, offerToReceiveVideo: true } signalingChannel.send('requestToChangeConstraints', newConstraints) this.peer.addStream(stream); signalingChannel.on('requestToChangeConstraints', (newConstraints) { this.peer.setConstraints(newConstraints); })

However when I do it, newConstraints, offerToReceiveAudio, and offerToReceiveVideo are all undefined. I'm thinking there is probably a new way of doing it, but can't tell from the readme and am unable to find more detailed documentation.

Bernard-Murphy avatar May 17 '22 10:05 Bernard-Murphy

any updates on this one ?

Mill1995 avatar Jun 16 '23 09:06 Mill1995