Skip to content
Snippets Groups Projects
Commit 18efa45e authored by lazorfuzz's avatar lazorfuzz
Browse files

Retry peer ping

parent 2d181551
No related branches found
No related tags found
No related merge requests found
...@@ -172,8 +172,13 @@ class LioWebRTC extends WildEmitter { ...@@ -172,8 +172,13 @@ class LioWebRTC extends WildEmitter {
if (peer.id) { if (peer.id) {
removeConnection(this.id, peer.id); removeConnection(this.id, peer.id);
} }
});
if (this.config.dataOnly && this.config.network.maxPeers > 0 && getNeighbors(this.id).length < this.config.network.minPeers) { self.on('channelClose', (channel) => {
if (channel.label === 'liowebrtc' &&
this.config.dataOnly &&
this.config.network.maxPeers > 0 &&
getNeighbors(this.id).length < this.config.network.minPeers) {
this.connectToRandomPeer(); this.connectToRandomPeer();
} }
}); });
...@@ -261,20 +266,23 @@ class LioWebRTC extends WildEmitter { ...@@ -261,20 +266,23 @@ class LioWebRTC extends WildEmitter {
} }
sendPing(peer, peerId, firstPing = false, channel = defaultChannel) { sendPing(peer, peerId, firstPing = false, channel = defaultChannel) {
const self = this;
if (firstPing) peer.start(); if (firstPing) peer.start();
setTimeout(() => { setTimeout(this.ping.bind(this, peer, peerId, firstPing, channel), 1000);
if (peer.sendDirectly('_ping', Date.now(), channel)) { }
// this.logger.log('sent ping to', peer.id);
if (firstPing) this.emit('createdPeer', peer); ping(peer, peerId, firstPing, channel, tries = 0) {
} else { if (peer.sendDirectly('_ping', Date.now(), channel)) {
// The channel is closed, remove the peer // this.logger.log('sent ping to', peer.id);
// console.log('removing peer, ping failed', peerId); if (firstPing) this.emit('createdPeer', peer);
self.unconnectivePeers[peerId] = true; } else {
peer.end(); // The channel is closed
this.connectToRandomPeer(); if (tries === 2) {
this.unconnectivePeers[peerId] = true;
peer.end(false);
return;
} }
}, 1000); setTimeout(this.ping.bind(this, peer, peerId, firstPing, channel, tries + 1), 1000);
}
} }
connectToRandomPeer() { connectToRandomPeer() {
...@@ -310,6 +318,10 @@ class LioWebRTC extends WildEmitter { ...@@ -310,6 +318,10 @@ class LioWebRTC extends WildEmitter {
}); });
} }
getSlowestPeers() {
const peers = getDroppablePeers();
}
leaveRoom() { leaveRoom() {
if (this.roomName) { if (this.roomName) {
this.connection.emit('leave'); this.connection.emit('leave');
......
...@@ -61,7 +61,6 @@ class Peer extends WildEmitter { ...@@ -61,7 +61,6 @@ class Peer extends WildEmitter {
break; break;
case 'closed': case 'closed':
this.handleStreamRemoved(false); this.handleStreamRemoved(false);
self.parent.emit('removedPeer', self);
break; break;
default: default:
break; break;
...@@ -231,10 +230,13 @@ class Peer extends WildEmitter { ...@@ -231,10 +230,13 @@ class Peer extends WildEmitter {
this.pc.offer(constraints, (err, success) => { }); this.pc.offer(constraints, (err, success) => { });
} }
end() { end(emitRemoval = true) {
if (this.closed) return; if (this.closed) return;
this.pc.close(); this.pc.close();
this.handleStreamRemoved(); this.handleStreamRemoved(emitRemoval);
if (emitRemoval) {
this.parent.emit('removedPeer', this);
}
} }
handleRemoteStreamAdded(event) { handleRemoteStreamAdded(event) {
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment