Open event never fires for connection
When I initiate a connection, the receiving end gets the event but the sending side never actually opens. There are no errors or anything, and the websocket traffic looks like it's working just fine. Just no 'open' event ever. I did have it working yesterday but today it just stopped for some reason.
Here is the code I'm using to send and receive:
Sending:
function initiateConnection() {
setConnectionState(1);
const _connection = peer.connect(code);
setConnection(_connection);
_connection.on('open', () => {
// never happens!
setConnectionState(2);
});
_connection.on('error', e => {
alert(e.message);
});
_connection.on('close', () => {
setConnectionState(0);
});
_connection.on('data', (data) => {
console.log(data);
})
}
Receiving ('connection' event fires when the other machine calls initiateConnection()):
peer.on('connection', connection => {
setConnected(true);
connection.on('data', chunk => {
console.log(chunk);
})
connection.on('error', e => {
alert(e.message);
});
connection.on('close', () => {
setConnected(false);
})
})
Wild guess here.... I've found that connections will work perfectly when both sides are only using 'stun' as soon as one side has to use 'turn' then connections don't materialize unless the turn server is operating and is configured properly. If you are using someone else's turn server I would spend the time to set up your own.
Thanks, I'll give that a try this afternoon and report back if it fixes things for me. I was using the default server that the library uses, so this might not solve the issue though.
If you want to run your own stun and turn server its done in less then 10 minutes with Coturn, https://github.com/coturn/coturn
For an example configuration check out https://pastebin.com/tAnnRZNs
Testing your server can be done here: https://webrtc.github.io/samples/src/content/peerconnection/trickle-ice/
I am having the same issue, which I referenced here : #899
Browser I am using is MS Edge
@xylude please reopen the issue if it still exists for you after checking with custom STUN/TURN.
It happened with me today. for me the problem was that I was creating two peers with the same ID. changing that solved this for me.
Faced the same issue, turns out that the way I set up my code it was taking a lot of time before the event listeners are attached after the peer instance initialization, that by the time they were finally attached the open event would have already fired.