Error: cannot signal after peer is destroyed
This error happens to me when I try to connect for the second time between two same peers.
P1 - Person 1, P2 - Person 2
It goes like this:
P1 emits "Looking for partner" ->
P2 emits "Looking for partner" ->
Server emits to P2 "Partner found" ->
P2 creating new Peer with initiator: true
P2 emits to Server "I am ready" ->
Server emits to P1 "P2 wants to connect" ->
P1 creating new Peer with initiator: false
P1 emits to Server "P2 is accepted"
Server emits to P2 "You are accepted" ->
And they can talk at this point
Then When P2 is closing conversation
P2 is doing peer.destroy();
P2 emits to Server "Let P1 know that I disconnected"
Server emits to P1 "P2 is off"
P1 is doing peer.destroy();
And now when I want to do the exact same thing(P2 is again initiator) I receive this error. It happens exactly at Server emits to P2 "You are accepted" -> function when I do: peer.signal(data.signal);
This is how it looks like with peer._debug = console.log;
starting batched negotiation
start negotiation
signalingStateChange have-local-offer
createOffer success
iceStateChange (connection: new) (gathering: gathering)
started iceComplete timeout
iceStateChange (connection: new) (gathering: complete)
signal
iceStateChange (connection: checking) (gathering: complete)
signal()
on track
iceStateChange (connection: connected) (gathering: complete)
maybeReady pc true channel false
flushing sender queue []
negotiate
signalingStateChange stable
on channel open
maybeReady pc true channel true
connect local: 192.168.0.21:64575 remote: 192.168.0.21:64579
connect
destroy (error: undefined)
starting batched negotiation
start negotiation
signalingStateChange have-local-offer
createOffer success
iceStateChange (connection: new) (gathering: gathering)
started iceComplete timeout
iceStateChange (connection: new) (gathering: complete)
signal
iceStateChange (connection: checking) (gathering: complete)
Uncaught Error: cannot signal after peer is destroyed
Code is available here: https://codeshare.io/5OjVNx for Front https://codeshare.io/2KlpWK for Back
@ChrisK1994 Did you find a fix for this problem? I am having the same issue
@ChrisK1994 Did you find a fix for this problem? I am having the same issue
it's about sockets, when you redeclare your socket listener you need to delete the previous hook
https://github.com/feross/simple-peer/issues/753
Can you be more precise about how to ? i have the same problem
cordialy
Can you be more precise about how to ? i have the same problem
cordialy
check the repo on my profile, there is a solution to that problem and an working example
Can you be more precise about how to ? i have the same problem cordialy
check the repo on my profile, there is a solution to that problem and an working example
i looked in your repo can you please help me to find the lines to fix ?
Can you be more precise about how to ? i have the same problem cordialy
check the repo on my profile, there is a solution to that problem and an working example
I'm facing similar problem it would be nice if you can show us the solution.
the solution is available in my repo, when you redeclare your socket listener you need to delete the previous hook
Uncaught Error: cannot signal after peer is destroyed
it means that you are trying to signal on a peer that is destroyed, because you haven't delete the previous hook with this peer so before declaring the hook you can just delete the previous one
I confirm this is a socket issue. Once I close old socket connection together with peer.destroy() and create a new one afterwards, everything works