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

Error: cannot signal after peer is destroyed

Open ChrisK1994 opened this issue 6 years ago • 8 comments

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 avatar Oct 21 '20 22:10 ChrisK1994

@ChrisK1994 Did you find a fix for this problem? I am having the same issue

joshua0308 avatar Jan 24 '21 23:01 joshua0308

@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

ChrisK1994 avatar Jan 25 '21 14:01 ChrisK1994

Can you be more precise about how to ? i have the same problem

cordialy

filoucrackeur avatar Sep 24 '21 12:09 filoucrackeur

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

ChrisK1994 avatar Sep 24 '21 13:09 ChrisK1994

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 ?

filoucrackeur avatar Sep 27 '21 09:09 filoucrackeur

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.

adarshaacharya avatar Oct 01 '21 16:10 adarshaacharya

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

ChrisK1994 avatar Oct 07 '21 09:10 ChrisK1994

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

phdog avatar Apr 20 '22 23:04 phdog