From edf2ab5eb3541797d9da3a70508077d1a59e6406 Mon Sep 17 00:00:00 2001 From: schlagmichdoch Date: Mon, 6 Mar 2023 03:36:46 +0100 Subject: [PATCH] revert some changes to regain stability --- index.js | 4 ++++ public/scripts/network.js | 14 ++++---------- public_included_ws_fallback/scripts/network.js | 14 ++++---------- 3 files changed, 12 insertions(+), 20 deletions(-) diff --git a/index.js b/index.js index 80ffe22..0fa6dae 100644 --- a/index.js +++ b/index.js @@ -368,6 +368,10 @@ class PairDropServer { // delete the peer delete this._rooms[room][peer.id]; + if (roomType === 'ip') { + peer.socket.terminate(); + } + //if room is empty, delete the room if (!Object.keys(this._rooms[room]).length) { delete this._rooms[room]; diff --git a/public/scripts/network.js b/public/scripts/network.js index 55fdc89..f40093a 100644 --- a/public/scripts/network.js +++ b/public/scripts/network.js @@ -8,7 +8,6 @@ class ServerConnection { constructor() { this._connect(); Events.on('pagehide', _ => this._disconnect()); - Events.on('beforeunload', _ => this._onBeforeUnload()); document.addEventListener('visibilitychange', _ => this._onVisibilityChange()); if (navigator.connection) navigator.connection.addEventListener('change', _ => this._reconnect()); Events.on('room-secrets', e => this._sendRoomSecrets(e.detail)); @@ -137,7 +136,8 @@ class ServerConnection { return ws_url.toString(); } - _onBeforeUnload() { + _disconnect() { + this.send({ type: 'disconnect' }); if (this._socket) { this._socket.onclose = null; this._socket.close(); @@ -147,10 +147,6 @@ class ServerConnection { } } - _disconnect() { - this.send({ type: 'disconnect' }); - } - _onDisconnect() { console.log('WS: server disconnected'); Events.fire('notify-user', 'Connecting..'); @@ -573,7 +569,7 @@ class RTCPeer extends Peer { const channel = event.channel || event.target; channel.binaryType = 'arraybuffer'; channel.onmessage = e => this._onMessage(e.data); - channel.onclose = e => this._onChannelClosed(e); + channel.onclose = _ => this._onChannelClosed(); this._channel = channel; Events.on('beforeunload', e => this._onBeforeUnload(e)); Events.on('pagehide', _ => this._onPageHide()); @@ -617,8 +613,6 @@ class RTCPeer extends Peer { if (this._busy) { e.preventDefault(); return "There are unfinished transfers. Are you sure you want to close?"; - } else { - this._disconnect(); } } @@ -798,7 +792,7 @@ class PeersManager { _notifyPeerDisplayNameChanged(peerId) { const peer = this.peers[peerId]; - if (!peer || (peer._conn && (peer._conn.signalingState !== "stable" || !peer._channel || peer._channel.readyState !== "open"))) return; + if (!peer) return; this.peers[peerId].sendJSON({type: 'display-name-changed', displayName: this._displayName}); } diff --git a/public_included_ws_fallback/scripts/network.js b/public_included_ws_fallback/scripts/network.js index 4c5b255..ea8f946 100644 --- a/public_included_ws_fallback/scripts/network.js +++ b/public_included_ws_fallback/scripts/network.js @@ -6,7 +6,6 @@ class ServerConnection { constructor() { this._connect(); Events.on('pagehide', _ => this._disconnect()); - Events.on('beforeunload', _ => this._onBeforeUnload()); document.addEventListener('visibilitychange', _ => this._onVisibilityChange()); if (navigator.connection) navigator.connection.addEventListener('change', _ => this._reconnect()); Events.on('room-secrets', e => this._sendRoomSecrets(e.detail)); @@ -148,7 +147,8 @@ class ServerConnection { return ws_url.toString(); } - _onBeforeUnload() { + _disconnect() { + this.send({ type: 'disconnect' }); if (this._socket) { this._socket.onclose = null; this._socket.close(); @@ -158,10 +158,6 @@ class ServerConnection { } } - _disconnect() { - this.send({ type: 'disconnect' }); - } - _onDisconnect() { console.log('WS: server disconnected'); Events.fire('notify-user', 'Connecting..'); @@ -584,7 +580,7 @@ class RTCPeer extends Peer { const channel = event.channel || event.target; channel.binaryType = 'arraybuffer'; channel.onmessage = e => this._onMessage(e.data); - channel.onclose = e => this._onChannelClosed(e); + channel.onclose = _ => this._onChannelClosed(); this._channel = channel; Events.on('beforeunload', e => this._onBeforeUnload(e)); Events.on('pagehide', _ => this._onPageHide()); @@ -628,8 +624,6 @@ class RTCPeer extends Peer { if (this._busy) { e.preventDefault(); return "There are unfinished transfers. Are you sure you want to close?"; - } else { - this._disconnect(); } } @@ -879,7 +873,7 @@ class PeersManager { _notifyPeerDisplayNameChanged(peerId) { const peer = this.peers[peerId]; - if (!peer || (peer._conn && (peer._conn.signalingState !== "stable" || !peer._channel || peer._channel.readyState !== "open"))) return; + if (!peer) return; this.peers[peerId].sendJSON({type: 'display-name-changed', displayName: this._displayName}); }