diff --git a/index.js b/index.js index 247b9c7..c50cc91 100644 --- a/index.js +++ b/index.js @@ -263,10 +263,12 @@ class PairDropServer { this._send(sender, { type: 'pair-device-joined', roomSecret: roomSecret, + peerId: creator.id }); this._send(creator, { type: 'pair-device-joined', roomSecret: roomSecret, + peerId: sender.id }); this._joinRoom(sender, 'secret', roomSecret); this._removeRoomKey(sender.roomKey); diff --git a/public/scripts/network.js b/public/scripts/network.js index 71c0831..71ee034 100644 --- a/public/scripts/network.js +++ b/public/scripts/network.js @@ -85,7 +85,7 @@ class ServerConnection { Events.fire('pair-device-initiated', msg); break; case 'pair-device-joined': - Events.fire('pair-device-joined', msg.roomSecret); + Events.fire('pair-device-joined', msg); break; case 'pair-device-join-key-invalid': Events.fire('pair-device-join-key-invalid'); @@ -671,7 +671,7 @@ class PeersManager { msg.peers.forEach(peer => { if (this.peers[peer.id]) { // if different roomType -> abort - if (this.peers[peer.id].roomType !== msg.roomType) return; + if (this.peers[peer.id].roomType !== msg.roomType || this.peers[peer.id].roomSecret !== msg.roomSecret) return; this.peers[peer.id].refresh(); return; } diff --git a/public/scripts/ui.js b/public/scripts/ui.js index c49396f..671c245 100644 --- a/public/scripts/ui.js +++ b/public/scripts/ui.js @@ -729,7 +729,7 @@ class PairDeviceDialog extends Dialog { Events.on('ws-connected', _ => this._onWsConnected()); Events.on('ws-disconnected', _ => this.hide()); Events.on('pair-device-initiated', e => this._pairDeviceInitiated(e.detail)); - Events.on('pair-device-joined', e => this._pairDeviceJoined(e.detail)); + Events.on('pair-device-joined', e => this._pairDeviceJoined(e.detail.peerId, e.detail.roomSecret)); Events.on('pair-device-join-key-invalid', _ => this._pairDeviceJoinKeyInvalid()); Events.on('pair-device-canceled', e => this._pairDeviceCanceled(e.detail)); Events.on('clear-room-secrets', e => this._onClearRoomSecrets(e.detail)) @@ -859,22 +859,25 @@ class PairDeviceDialog extends Dialog { } } - _pairDeviceJoined(roomSecret) { + _pairDeviceJoined(peerId, roomSecret) { this.hide(); PersistentStorage.addRoomSecret(roomSecret).then(_ => { - Events.fire('notify-user', 'Devices paired successfully.') + Events.fire('notify-user', 'Devices paired successfully.'); + const oldRoomSecret = $(peerId).ui.roomSecret; + if (oldRoomSecret) PersistentStorage.deleteRoomSecret(oldRoomSecret); + $(peerId).ui.roomSecret = roomSecret; this._evaluateNumberRoomSecrets(); }).finally(_ => { this._cleanUp(); }) .catch(_ => { - Events.fire('notify-user', 'Paired devices are not persistent.') - PersistentStorage.logBrowserNotCapable() + Events.fire('notify-user', 'Paired devices are not persistent.'); + PersistentStorage.logBrowserNotCapable(); }); } _pairDeviceJoinKeyInvalid() { - Events.fire('notify-user', 'Key not valid') + Events.fire('notify-user', 'Key not valid'); } _pairDeviceCancel() { @@ -884,7 +887,7 @@ class PairDeviceDialog extends Dialog { } _pairDeviceCanceled(roomKey) { - Events.fire('notify-user', `Key ${roomKey} invalidated.`) + Events.fire('notify-user', `Key ${roomKey} invalidated.`); } _cleanUp() { diff --git a/public_included_ws_fallback/scripts/network.js b/public_included_ws_fallback/scripts/network.js index ad35916..aa622e7 100644 --- a/public_included_ws_fallback/scripts/network.js +++ b/public_included_ws_fallback/scripts/network.js @@ -83,7 +83,7 @@ class ServerConnection { Events.fire('pair-device-initiated', msg); break; case 'pair-device-joined': - Events.fire('pair-device-joined', msg.roomSecret); + Events.fire('pair-device-joined', msg); break; case 'pair-device-join-key-invalid': Events.fire('pair-device-join-key-invalid'); @@ -726,7 +726,7 @@ class PeersManager { msg.peers.forEach(peer => { if (this.peers[peer.id]) { // if different roomType -> abort - if (this.peers[peer.id].roomType !== msg.roomType) return; + if (this.peers[peer.id].roomType !== msg.roomType || this.peers[peer.id].roomSecret !== msg.roomSecret) return; this.peers[peer.id].refresh(); return; } diff --git a/public_included_ws_fallback/scripts/ui.js b/public_included_ws_fallback/scripts/ui.js index a0bb58b..97a64d2 100644 --- a/public_included_ws_fallback/scripts/ui.js +++ b/public_included_ws_fallback/scripts/ui.js @@ -730,7 +730,7 @@ class PairDeviceDialog extends Dialog { Events.on('ws-connected', _ => this._onWsConnected()); Events.on('ws-disconnected', _ => this.hide()); Events.on('pair-device-initiated', e => this._pairDeviceInitiated(e.detail)); - Events.on('pair-device-joined', e => this._pairDeviceJoined(e.detail)); + Events.on('pair-device-joined', e => this._pairDeviceJoined(e.detail.peerId, e.detail.roomSecret)); Events.on('pair-device-join-key-invalid', _ => this._pairDeviceJoinKeyInvalid()); Events.on('pair-device-canceled', e => this._pairDeviceCanceled(e.detail)); Events.on('clear-room-secrets', e => this._onClearRoomSecrets(e.detail)) @@ -860,22 +860,25 @@ class PairDeviceDialog extends Dialog { } } - _pairDeviceJoined(roomSecret) { + _pairDeviceJoined(peerId, roomSecret) { this.hide(); PersistentStorage.addRoomSecret(roomSecret).then(_ => { - Events.fire('notify-user', 'Devices paired successfully.') + Events.fire('notify-user', 'Devices paired successfully.'); + const oldRoomSecret = $(peerId).ui.roomSecret; + if (oldRoomSecret) PersistentStorage.deleteRoomSecret(oldRoomSecret); + $(peerId).ui.roomSecret = roomSecret; this._evaluateNumberRoomSecrets(); }).finally(_ => { this._cleanUp(); }) .catch(_ => { - Events.fire('notify-user', 'Paired devices are not persistent.') - PersistentStorage.logBrowserNotCapable() + Events.fire('notify-user', 'Paired devices are not persistent.'); + PersistentStorage.logBrowserNotCapable(); }); } _pairDeviceJoinKeyInvalid() { - Events.fire('notify-user', 'Key not valid') + Events.fire('notify-user', 'Key not valid'); } _pairDeviceCancel() { @@ -885,7 +888,7 @@ class PairDeviceDialog extends Dialog { } _pairDeviceCanceled(roomKey) { - Events.fire('notify-user', `Key ${roomKey} invalidated.`) + Events.fire('notify-user', `Key ${roomKey} invalidated.`); } _cleanUp() {