From a418fa916f1c14d4a5695dc6b2204938ddb3fe21 Mon Sep 17 00:00:00 2001 From: Kevin Jahns Date: Mon, 29 Jun 2020 00:55:47 +0200 Subject: [PATCH] Reconnect after conn close & always propagate update messages --- src/y-webrtc.js | 18 ++++++++++-------- 1 file changed, 10 insertions(+), 8 deletions(-) diff --git a/src/y-webrtc.js b/src/y-webrtc.js index 503de31..88bb29b 100644 --- a/src/y-webrtc.js +++ b/src/y-webrtc.js @@ -219,9 +219,13 @@ export class WebrtcConn { this.peer.destroy() log('closed connection to ', logging.BOLD, remotePeerId) }) - this.peer.on('error', err => { + this.peer.on('close', () => { + log('Connection to remote peer ', logging.BOLD, remotePeerId, logging.UNBOLD, ' has been closed') + announceSignalingInfo(room) + }) + this.peer.on('error', err => { + log('Error in connection to ', logging.BOLD, remotePeerId, ': ', err) announceSignalingInfo(room) - log('error in connection to ', logging.BOLD, remotePeerId, ': ', err) }) this.peer.on('data', data => { const answer = readPeerMessage(this, data) @@ -339,12 +343,10 @@ export class Room { * @param {any} origin */ this._docUpdateHandler = (update, origin) => { - if (origin !== this) { - const encoder = encoding.createEncoder() - encoding.writeVarUint(encoder, messageSync) - syncProtocol.writeUpdate(encoder, update) - broadcastRoomMessage(this, encoding.toUint8Array(encoder)) - } + const encoder = encoding.createEncoder() + encoding.writeVarUint(encoder, messageSync) + syncProtocol.writeUpdate(encoder, update) + broadcastRoomMessage(this, encoding.toUint8Array(encoder)) } /** * Listens to Awareness updates and sends them to remote peers