Restart an existing SimplePeer connection
See original GitHub issueI’m trying to “restart” an existing connection.
Assuming connection const peer = { first: new Peer(... args) }
, I can’t recreate a new connection between the same two peers on peer.first
without reloading the page (when reloading the page the connection is (re)established without any issue).
I have tried to the following:
// "first" connection - [displaying only the code of the initiator]
const peer = { userA: new Peer({ initiator: true, trickle: false }) };
// [omitted code up to `.connected = true`]
peer.userA.destroy(); // with and without the optional `error message`
destroy peer.userA; // both after calling `destroy()` and without calling `destroy()`
// "second" connection - [displaying only the code of the initiator]
peer.userA = new Peer({ initiator: true, trickle: false });
Unfortunately the “second” connection won’t connect, both when the “first” connected, and when it did not.
The “first” connection in the console appears like this:
allowHalfOpen:false
answerConstraints:{}
channelConfig:{}
channelName:"7127337a05636fb1ba616871719788627bd22941"
config:{iceServers: Array(2)}
connected:true
constraints:{}
initiator:true
localAddress:"XXX.XXX.XXX.XXX" // correct IP
localPort:58308
offerConstraints:{}
readable:true
remoteAddress:"XXX.XXX.XXX.XXX" // correct IP
remoteFamily:"IPv4"
remotePort:61205
sdpTransform:ƒ (e)
streams:[]
trickle:false
writable:true
...
The “second” connection, however, is missing some crucial data (e.g. IP), both in the initiator
and in the receiver
. The initiator appears like this in the console:
allowHalfOpen:false
answerConstraints:{}
channelConfig:{}
channelName:"dfe7107551bf3ebf4e812b463882b5b52f6715ed"
config:{iceServers: Array(2)}
connected:false
constraints:{}
initiator:true
localAddress:undefined
localPort:undefined
offerConstraints:{}
readable:true
remoteAddress:undefined
remoteFamily:undefined
remotePort:undefined
sdpTransform:ƒ (e)
streams:[]
trickle:false
writable:true
...
The second receiver has also channelName:null
.
Is it a but, am I missing something, or is it forbidden to reinitiate a connection between the same two peers without reloading the page?
Issue Analytics
- State:
- Created 5 years ago
- Comments:7
Top GitHub Comments
Here is the issue:
You are calling
.signal()
on the userA side after the first peer object was destroyed but before the second even sends an offer.The
Error: Ice connection failed.
is just because theuserA
side failed to connect.It seems there’s quite a few problems with how you are signalling. Try to keep messages intended for a connection completely separate, so they don’t accidentally go to the wrong peer object. Signalling can go wrong in a lot of places when using multiple peers, especially if you are trying to use the same signalling channel.
I do have a signalling module that can give you basic channel separation and a connection model if you’re interested in using it or reading the code: https://github.com/RationalCoding/simple-signal
Closing as this doesn’t appear to be an issue in simple-peer, but feel free to continue discussion.
Have you found a solution for this? I have a exact issue like this. @ilDon