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

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

当我第二次尝试在两个对等点之间进行连接时,我遇到了这个错误。

P1 - Person 1, P2 - Person 2

它是这样的:

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();

现在,当我想做完全相同的事情时(P2 再次成为发起者),我收到此错误。 当我这样做时,它恰好发生在 Server emits to P2 "You are accepted" -> 函数中:peer.signal(data.signal);

这是 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

代码可在此处获得: https://codeshare.io/5OjVNx 前面 https://codeshare.io/2KlpWK 返回

好的,原来我的代码完全是垃圾,不应该这样做!我正在学习一些糟糕的教程。这里的问题是信号在不断循环中以一些错误结束,不知何故它像这样工作但是你不能在不让应用程序崩溃的情况下销毁对等点。