mirror of
https://github.com/schlagmichdoch/PairDrop.git
synced 2025-04-23 00:06:18 -04:00
When switching public rooms disconnect from devices in old room (fixes #298)
This commit is contained in:
parent
9b3571feac
commit
be381ea438
3 changed files with 24 additions and 18 deletions
|
@ -1502,9 +1502,12 @@ class PeersManager {
|
|||
Events.on('peer-connected', e => this._onPeerConnected(e.detail.peerId));
|
||||
Events.on('peer-disconnected', e => this._onPeerDisconnected(e.detail));
|
||||
|
||||
// ROOMS
|
||||
Events.on('join-public-room', e => this._onJoinPublicRoom(e.detail.roomId));
|
||||
|
||||
// this device closes connection
|
||||
Events.on('room-secrets-deleted', e => this._onRoomSecretsDeleted(e.detail));
|
||||
Events.on('leave-public-room', e => this._onLeavePublicRoom(e.detail));
|
||||
Events.on('leave-public-room', _ => this._onLeavePublicRoom());
|
||||
|
||||
// peer closes connection
|
||||
Events.on('secret-room-deleted', e => this._onSecretRoomDeleted(e.detail));
|
||||
|
@ -1682,6 +1685,9 @@ class PeersManager {
|
|||
}
|
||||
|
||||
_onJoinPublicRoom(roomId) {
|
||||
if (roomId !== this._device.publicRoomId) {
|
||||
this._disconnectFromPublicRoom();
|
||||
}
|
||||
this._device.publicRoomId = roomId;
|
||||
}
|
||||
|
||||
|
|
|
@ -2046,8 +2046,8 @@ class PublicRoomDialog extends Dialog {
|
|||
|
||||
Events.on('keydown', e => this._onKeyDown(e));
|
||||
Events.on('public-room-created', e => this._onPublicRoomCreated(e.detail));
|
||||
Events.on('peers', e => this._onPeers(e.detail));
|
||||
Events.on('peer-joined', e => this._onPeerJoined(e.detail.peer, e.detail.roomId));
|
||||
Events.on('peers', e => this._onPeers(e.detail.peers, e.detail.roomId));
|
||||
Events.on('peer-joined', e => this._onPeerJoined(e.detail.roomId));
|
||||
Events.on('public-room-id-invalid', e => this._onPublicRoomIdInvalid(e.detail));
|
||||
Events.on('public-room-left', _ => this._onPublicRoomLeft());
|
||||
this.$el.addEventListener('paste', e => this._onPaste(e));
|
||||
|
@ -2177,29 +2177,30 @@ class PublicRoomDialog extends Dialog {
|
|||
}
|
||||
}
|
||||
|
||||
_onPeers(message) {
|
||||
message.peers.forEach(messagePeer => {
|
||||
this._evaluateJoinedPeer(messagePeer.id, message.roomId);
|
||||
});
|
||||
_onPeers(peers, roomId) {
|
||||
// Do not evaluate if creating new room
|
||||
if (this.roomId && !peers.length) return;
|
||||
|
||||
this._evaluateJoinedPeer(roomId);
|
||||
}
|
||||
|
||||
_onPeerJoined(peer, roomId) {
|
||||
this._evaluateJoinedPeer(peer.id, roomId);
|
||||
_onPeerJoined(roomId) {
|
||||
this._evaluateJoinedPeer(roomId);
|
||||
}
|
||||
|
||||
_evaluateJoinedPeer(peerId, roomId) {
|
||||
const isInitiatedRoomId = roomId === this.roomId;
|
||||
const isJoinedRoomId = roomId === this.roomIdJoin;
|
||||
_evaluateJoinedPeer(roomId) {
|
||||
const peerJoinedThisRoom = roomId === this.roomId;
|
||||
const switchedToOtherRoom = roomId === this.roomIdJoin;
|
||||
|
||||
if (!peerId || !roomId || (!isInitiatedRoomId && !isJoinedRoomId)) return;
|
||||
if (!roomId || (!peerJoinedThisRoom && !switchedToOtherRoom)) return;
|
||||
|
||||
this.hide();
|
||||
|
||||
sessionStorage.setItem('public_room_id', roomId);
|
||||
|
||||
if (isJoinedRoomId) {
|
||||
if (switchedToOtherRoom) {
|
||||
this.roomIdJoin = null;
|
||||
this.roomId = roomId;
|
||||
this.roomIdJoin = false;
|
||||
this._setKeyAndQrCode();
|
||||
}
|
||||
}
|
||||
|
@ -2212,7 +2213,7 @@ class PublicRoomDialog extends Dialog {
|
|||
}
|
||||
|
||||
_leavePublicRoom() {
|
||||
Events.fire('leave-public-room', this.roomId);
|
||||
Events.fire('leave-public-room');
|
||||
}
|
||||
|
||||
_onPublicRoomLeft() {
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue