问题描述
当我第二次尝试在两个同级之间连接时,会发生此错误。
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 for Front https://codeshare.io/2KlpWK for Back
解决方法
好吧,原来我的代码是一个完整的垃圾,不应该这样处理!我正在关注一些糟糕的教程。这里的问题是信号以恒定的循环结束,并以一些错误结束,它以这种方式工作,但是您不能在不导致应用程序崩溃的情况下销毁同位体。