Simple-peer: Error: cannot signal after peer is destroyed

Created on 3 Jul 2018  路  5Comments  路  Source: feross/simple-peer

What is the proper way to tear down the connection?

I establish a WebRTC connection using a SimplePeer object, but then I need to drop the connection and reconnect. I call the simplePeer.destroy(), create a new SimplePeer object and do the signalling part, but I get the following error:

Error: cannot signal after peer is destroyed

What am I doing wrong? Same issue as this one: https://github.com/feross/simple-peer/issues/101

need more info question

Most helpful comment

Do you create new Peer objects on both sides of the connection? Destroying a peer locally will destroy the remote peer it鈥檚 connected to.

All 5 comments

Do you create new Peer objects on both sides of the connection? Destroying a peer locally will destroy the remote peer it鈥檚 connected to.

Also, please post your console logs with debugging enabled.

peer._debug = console.log

I also have the same problem, please show me the solution to this error.

@phamthecuong it is impossible to help you without any details. It is typically caused by wrong order of methods calls, but where exactly depends on your code.

@RationalCoding was right after all. I did call a simple peer object after it was destroyed due to the fact that I didn't remove the event listener on the signalling source, so I would signal the old peers with offers intended for new peers

@phamthecuong you can check out my implementation below. It's a client-server wrapper around simple-peer with auto reconnect with signalling performed over websockets, but you can easily replace the latter with whatever means of exchanging offers you use
https://github.com/olgeorge/react-electron-webrtc-phaser/blob/master/app/services/peerConnection.js

Was this page helpful?
0 / 5 - 0 ratings