mirror of
https://github.com/schlagmichdoch/PairDrop.git
synced 2026-04-07 10:22:15 +00:00
Compare commits
2 Commits
implement-
...
domain_spe
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
6f194db843 | ||
|
|
9dae6d588d |
@@ -118,8 +118,8 @@ class PairDrop {
|
||||
this.$headerNotificationBtn.removeAttribute('hidden');
|
||||
}
|
||||
|
||||
let roomSecrets = await PersistentStorage.getAllRoomSecrets();
|
||||
if (roomSecrets.length > 0) {
|
||||
let roomSecretsCount = await PersistentStorage.getAllRoomSecretsCount();
|
||||
if (roomSecretsCount > 0) {
|
||||
this.$headerEditPairedDevicesBtn.removeAttribute('hidden');
|
||||
this.$footerPairedDevicesBadge.removeAttribute('hidden');
|
||||
}
|
||||
@@ -137,7 +137,6 @@ class PairDrop {
|
||||
let stylesheet = document.createElement('link');
|
||||
stylesheet.rel = 'preload';
|
||||
stylesheet.as = 'style';
|
||||
stylesheet.defer = true;
|
||||
stylesheet.href = url;
|
||||
stylesheet.onload = _ => {
|
||||
stylesheet.onload = null;
|
||||
|
||||
@@ -8,13 +8,13 @@ class ServerConnection {
|
||||
navigator.connection.addEventListener('change', _ => this._reconnect());
|
||||
}
|
||||
|
||||
Events.on('room-secrets', e => this.send({ type: 'room-secrets', roomSecrets: e.detail }));
|
||||
Events.on('join-ip-room', _ => this.send({ type: 'join-ip-room'}));
|
||||
Events.on('room-secrets-deleted', e => this.send({ type: 'room-secrets-deleted', roomSecrets: e.detail}));
|
||||
Events.on('regenerate-room-secret', e => this.send({ type: 'regenerate-room-secret', roomSecret: e.detail}));
|
||||
Events.on('pair-device-initiate', _ => this._onPairDeviceInitiate());
|
||||
Events.on('pair-device-join', e => this._onPairDeviceJoin(e.detail));
|
||||
Events.on('pair-device-cancel', _ => this.send({ type: 'pair-device-cancel' }));
|
||||
Events.on('join-ip-room', _ => this._sendJoinIpRoom());
|
||||
Events.on('room-secrets', e => this._sendRoomSecrets(e.detail));
|
||||
Events.on('room-secrets-deleted', e => this._sendRoomSecretsDeleted(e.detail));
|
||||
Events.on('regenerate-room-secret', e => this._sendRegenerateRoomSecret(e.detail));
|
||||
Events.on('pair-device-initiate', _ => this._sendPairDeviceInitiate());
|
||||
Events.on('pair-device-join', e => this._sendPairDeviceJoin(e.detail));
|
||||
Events.on('pair-device-cancel', _ => this._sendPairDeviceCancel());
|
||||
|
||||
Events.on('create-public-room', _ => this._onCreatePublicRoom());
|
||||
Events.on('join-public-room', e => this._onJoinPublicRoom(e.detail.roomId, e.detail.createIfInvalid));
|
||||
@@ -63,8 +63,8 @@ class ServerConnection {
|
||||
}
|
||||
|
||||
_setWsConfig(wsConfig) {
|
||||
window._wsConfig = wsConfig;
|
||||
Events.fire('ws-config-loaded');
|
||||
this._wsConfig = wsConfig;
|
||||
Events.fire('ws-config', wsConfig);
|
||||
}
|
||||
|
||||
_connect() {
|
||||
@@ -93,7 +93,23 @@ class ServerConnection {
|
||||
}
|
||||
}
|
||||
|
||||
_onPairDeviceInitiate() {
|
||||
_sendJoinIpRoom() {
|
||||
this.send({ type: 'join-ip-room'});
|
||||
}
|
||||
|
||||
_sendRoomSecrets(roomSecrets) {
|
||||
this.send({ type: 'room-secrets', roomSecrets: roomSecrets });
|
||||
}
|
||||
|
||||
_sendRoomSecretsDeleted(roomSecrets) {
|
||||
this.send({ type: 'room-secrets-deleted', roomSecrets: roomSecrets});
|
||||
}
|
||||
|
||||
_sendRegenerateRoomSecret(roomSecret) {
|
||||
this.send({ type: 'regenerate-room-secret', roomSecret: roomSecret});
|
||||
}
|
||||
|
||||
_sendPairDeviceInitiate() {
|
||||
if (!this._isConnected()) {
|
||||
Events.fire('notify-user', Localization.getTranslation("notifications.online-requirement-pairing"));
|
||||
return;
|
||||
@@ -101,15 +117,19 @@ class ServerConnection {
|
||||
this.send({ type: 'pair-device-initiate' });
|
||||
}
|
||||
|
||||
_onPairDeviceJoin(pairKey) {
|
||||
_sendPairDeviceJoin(pairKey) {
|
||||
if (!this._isConnected()) {
|
||||
// Todo: instead use pending outbound ws queue
|
||||
setTimeout(() => this._onPairDeviceJoin(pairKey), 1000);
|
||||
setTimeout(() => this._sendPairDeviceJoin(pairKey), 1000);
|
||||
return;
|
||||
}
|
||||
this.send({ type: 'pair-device-join', pairKey: pairKey });
|
||||
}
|
||||
|
||||
_sendPairDeviceCancel() {
|
||||
this.send({ type: 'pair-device-cancel' });
|
||||
}
|
||||
|
||||
_onCreatePublicRoom() {
|
||||
if (!this._isConnected()) {
|
||||
Events.fire('notify-user', Localization.getTranslation("notifications.online-requirement-public-room"));
|
||||
@@ -137,7 +157,7 @@ class ServerConnection {
|
||||
_onMessage(message) {
|
||||
const messageJSON = JSON.parse(message);
|
||||
if (messageJSON.type !== 'ping' && messageJSON.type !== 'ws-relay') {
|
||||
Logger.debug('WS Receive:', messageJSON);
|
||||
Logger.debug('WS receive:', messageJSON);
|
||||
}
|
||||
switch (messageJSON.type) {
|
||||
case 'ws-config':
|
||||
@@ -193,15 +213,15 @@ class ServerConnection {
|
||||
break;
|
||||
case 'ws-relay':
|
||||
// ws-fallback
|
||||
if (window._wsConfig.wsFallback) {
|
||||
if (this._wsConfig.wsFallback) {
|
||||
Events.fire('ws-relay', {peerId: messageJSON.sender.id, message: message});
|
||||
}
|
||||
else {
|
||||
Logger.warn("WS Receive: message type is for websocket fallback only but websocket fallback is not activated on this instance.")
|
||||
Logger.warn("WS receive: message type is for websocket fallback only but websocket fallback is not activated on this instance.")
|
||||
}
|
||||
break;
|
||||
default:
|
||||
Logger.error('WS Receive: unknown message type', messageJSON);
|
||||
Logger.error('WS receive: unknown message type', messageJSON);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1005,17 +1025,15 @@ class Peer {
|
||||
|
||||
class RTCPeer extends Peer {
|
||||
|
||||
constructor(serverConnection, isCaller, peerId, roomType, roomId) {
|
||||
constructor(serverConnection, isCaller, peerId, roomType, roomId, rtcConfig) {
|
||||
super(serverConnection, isCaller, peerId, roomType, roomId);
|
||||
|
||||
this.rtcSupported = true;
|
||||
this.rtcConfig = window._wsConfig.rtcConfig;
|
||||
this.rtcConfig = rtcConfig;
|
||||
|
||||
this.pendingInboundServerSignalMessages = [];
|
||||
this.pendingOutboundMessages = [];
|
||||
|
||||
this.errorCount = 0;
|
||||
|
||||
this._connect();
|
||||
}
|
||||
|
||||
@@ -1116,14 +1134,12 @@ class RTCPeer extends Peer {
|
||||
_onConnectionStateChange() {
|
||||
Logger.debug('RTC: Connection state changed:', this._conn.connectionState);
|
||||
switch (this._conn.connectionState) {
|
||||
case 'connected':
|
||||
this.errorCount = 0;
|
||||
break;
|
||||
case 'disconnected':
|
||||
this._refresh();
|
||||
break;
|
||||
case 'failed':
|
||||
Logger.warn('RTC connection failed');
|
||||
// Todo: if error is "TURN server needed" -> fallback to WS if activated
|
||||
this._refresh();
|
||||
}
|
||||
}
|
||||
@@ -1132,28 +1148,8 @@ class RTCPeer extends Peer {
|
||||
this._handleLocalCandidate(event.candidate);
|
||||
}
|
||||
|
||||
_onIceCandidateError(event) {
|
||||
this.errorCount++
|
||||
|
||||
// Todo: remove this
|
||||
// Todo: test which errorCode is thrown on "TURN server needed" and what other codes are relevant
|
||||
console.debug(this.errorCount, event.errorCode, event)
|
||||
|
||||
Logger.error(event);
|
||||
if (event.errorCode === 701) {
|
||||
this._retryOrFallback();
|
||||
}
|
||||
}
|
||||
|
||||
_retryOrFallback() {
|
||||
// If fallback is activated, fallback to WS Peer if third retry fails
|
||||
if (this.errorCount > 3 && window._wsConfig.wsFallback) {
|
||||
Events.fire('fallback-to-ws', { peerId: this._peerId });
|
||||
this._sendFallbackToWs();
|
||||
}
|
||||
else {
|
||||
this._refresh();
|
||||
}
|
||||
_onIceCandidateError(error) {
|
||||
Logger.error(error);
|
||||
}
|
||||
|
||||
_openMessageChannel() {
|
||||
@@ -1188,7 +1184,7 @@ class RTCPeer extends Peer {
|
||||
// wait until all channels are open
|
||||
if (!this._stable()) return;
|
||||
|
||||
Events.fire('peer-connected', { peerId: this._peerId, connectionHash: this.getConnectionHash(), rtcSupported: this.rtcSupported });
|
||||
Events.fire('peer-connected', {peerId: this._peerId, connectionHash: this.getConnectionHash()});
|
||||
super._onPeerConnected();
|
||||
|
||||
this._sendPendingOutboundMessaged();
|
||||
@@ -1349,20 +1345,6 @@ class RTCPeer extends Peer {
|
||||
|
||||
_sendSignal(message) {
|
||||
message.type = 'signal';
|
||||
this._sendMessageViaServer(message);
|
||||
}
|
||||
|
||||
_sendFallbackToWs() {
|
||||
const message = {
|
||||
type: 'ws-relay',
|
||||
message: {
|
||||
type: 'fallback-to-ws'
|
||||
}
|
||||
};
|
||||
this._sendMessageViaServer(message);
|
||||
}
|
||||
|
||||
_sendMessageViaServer(message) {
|
||||
message.to = this._peerId;
|
||||
message.roomType = this._getRoomTypes()[0];
|
||||
message.roomId = this._roomIds[this._getRoomTypes()[0]];
|
||||
@@ -1382,7 +1364,7 @@ class RTCPeer extends Peer {
|
||||
}
|
||||
|
||||
async _onMessage(message) {
|
||||
Logger.debug('RTCPeer Receive:', JSON.parse(message));
|
||||
Logger.debug('RTC Receive:', JSON.parse(message));
|
||||
try {
|
||||
message = JSON.parse(message);
|
||||
} catch (e) {
|
||||
@@ -1481,7 +1463,7 @@ class WSPeer extends Peer {
|
||||
}
|
||||
|
||||
async _onMessage(message) {
|
||||
Logger.debug('WSPeer Receive:', message);
|
||||
Logger.debug('WS Receive:', message);
|
||||
await super._onMessage(message);
|
||||
}
|
||||
|
||||
@@ -1527,44 +1509,39 @@ class PeersManager {
|
||||
constructor(serverConnection) {
|
||||
this.peers = {};
|
||||
this._server = serverConnection;
|
||||
// Initiation
|
||||
Events.on('signal', e => this._onSignal(e.detail));
|
||||
Events.on('peers', e => this._onPeers(e.detail));
|
||||
|
||||
// File / Message transfer
|
||||
Events.on('files-selected', e => this._onFilesSelected(e.detail));
|
||||
Events.on('respond-to-files-transfer-request', e => this._onRespondToFileTransferRequest(e.detail))
|
||||
Events.on('send-text', e => this._onSendText(e.detail));
|
||||
|
||||
// Peer
|
||||
Events.on('peer-left', e => this._onPeerLeft(e.detail));
|
||||
Events.on('peer-joined', e => this._onPeerJoined(e.detail));
|
||||
Events.on('peer-connected', e => this._onPeerConnected(e.detail.peerId));
|
||||
Events.on('peer-disconnected', e => this._onPeerDisconnected(e.detail));
|
||||
|
||||
// WS-Peer specific
|
||||
Events.on('ws-disconnected', _ => this._onWsDisconnected());
|
||||
Events.on('ws-relay', e => this._onWsRelay(e.detail.peerId, e.detail.message));
|
||||
Events.on('fallback-to-ws', e => this._onFallbackToWs(e.detail.peerId));
|
||||
|
||||
// Rooms and secrets: this device closes connection
|
||||
// this device closes connection
|
||||
Events.on('room-secrets-deleted', e => this._onRoomSecretsDeleted(e.detail));
|
||||
Events.on('leave-public-room', e => this._onLeavePublicRoom(e.detail));
|
||||
|
||||
// Rooms and secrets: other peer closes connection
|
||||
// peer closes connection
|
||||
Events.on('secret-room-deleted', e => this._onSecretRoomDeleted(e.detail));
|
||||
|
||||
// Room secret, displayname, auto-accept
|
||||
Events.on('room-secret-regenerated', e => this._onRoomSecretRegenerated(e.detail));
|
||||
Events.on('display-name', e => this._onDisplayName(e.detail.displayName));
|
||||
Events.on('self-display-name-changed', e => this._notifyPeersDisplayNameChanged(e.detail));
|
||||
Events.on('notify-peer-display-name-changed', e => this._notifyPeerDisplayNameChanged(e.detail));
|
||||
Events.on('auto-accept-updated', e => this._onAutoAcceptUpdated(e.detail.roomSecret, e.detail.autoAccept));
|
||||
Events.on('ws-disconnected', _ => this._onWsDisconnected());
|
||||
Events.on('ws-relay', e => this._onWsRelay(e.detail.peerId, e.detail.message));
|
||||
Events.on('ws-config', e => this._onWsConfig(e.detail));
|
||||
|
||||
// NoSleep evaluation
|
||||
Events.on('evaluate-no-sleep', _ => this._onEvaluateNoSleep());
|
||||
}
|
||||
|
||||
_onWsConfig(wsConfig) {
|
||||
this._wsConfig = wsConfig;
|
||||
}
|
||||
|
||||
_onSignal(message) {
|
||||
const peerId = message.sender.id;
|
||||
this.peers[peerId]._onServerSignalMessage(message);
|
||||
@@ -1610,9 +1587,9 @@ class PeersManager {
|
||||
|
||||
_createPeer(isCaller, peerId, roomType, roomId, rtcSupported) {
|
||||
if (window.isRtcSupported && rtcSupported) {
|
||||
this.peers[peerId] = new RTCPeer(this._server, isCaller, peerId, roomType, roomId);
|
||||
this.peers[peerId] = new RTCPeer(this._server, isCaller, peerId, roomType, roomId, this._wsConfig.rtcConfig);
|
||||
}
|
||||
else if (window._wsConfig.wsFallback) {
|
||||
else if (this._wsConfig.wsFallback) {
|
||||
this.peers[peerId] = new WSPeer(this._server, isCaller, peerId, roomType, roomId);
|
||||
}
|
||||
else {
|
||||
@@ -1632,20 +1609,11 @@ class PeersManager {
|
||||
}
|
||||
|
||||
_onWsRelay(peerId, message) {
|
||||
if (!window._wsConfig.wsFallback) return;
|
||||
if (!this._wsConfig.wsFallback) return;
|
||||
|
||||
const peer = this.peers[peerId];
|
||||
|
||||
if (!peer) return;
|
||||
|
||||
// Check if RTCPeer wants to fall back to WS fallback
|
||||
if (peer.rtcSupported && JSON.parse(message).message.type === 'fallback-to-ws') {
|
||||
this._onFallbackToWs(peerId);
|
||||
return;
|
||||
}
|
||||
|
||||
// Relay messages to WSPeers only
|
||||
if (peer.rtcSupported) return;
|
||||
if (!peer || peer.rtcSupported) return;
|
||||
|
||||
peer._onWsRelay(message);
|
||||
}
|
||||
@@ -1667,23 +1635,20 @@ class PeersManager {
|
||||
if (this._peerExists(message.peerId) && !this._webRtcSupported(message.peerId)) {
|
||||
Logger.debug('WSPeer left:', message.peerId);
|
||||
}
|
||||
else if (message.disconnect !== true) {
|
||||
// if RTCPeer and disconnect is false -> abort and wait for reconnect
|
||||
return;
|
||||
}
|
||||
if (message.disconnect === true) {
|
||||
// if user actively disconnected from PairDrop server, disconnect all peer to peer connections immediately
|
||||
this._disconnectOrRemoveRoomTypeByPeerId(message.peerId, message.roomType);
|
||||
|
||||
// if user actively disconnected from PairDrop server or is WSPeer, disconnect all peer to peer connections immediately
|
||||
this._disconnectOrRemoveRoomTypeByPeerId(message.peerId, message.roomType);
|
||||
|
||||
// If no peers are connected anymore, we can safely assume that no other tab on the same browser is connected:
|
||||
// Tidy up peerIds in localStorage
|
||||
if (Object.keys(this.peers).length === 0) {
|
||||
BrowserTabsConnector
|
||||
.removeOtherPeerIdsFromLocalStorage()
|
||||
.then(peerIds => {
|
||||
if (!peerIds) return;
|
||||
Logger.debug("successfully removed other peerIds from localStorage");
|
||||
});
|
||||
// If no peers are connected anymore, we can safely assume that no other tab on the same browser is connected:
|
||||
// Tidy up peerIds in localStorage
|
||||
if (Object.keys(this.peers).length === 0) {
|
||||
BrowserTabsConnector
|
||||
.removeOtherPeerIdsFromLocalStorage()
|
||||
.then(peerIds => {
|
||||
if (!peerIds) return;
|
||||
Logger.debug("successfully removed other peerIds from localStorage");
|
||||
});
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1700,7 +1665,7 @@ class PeersManager {
|
||||
}
|
||||
|
||||
_onWsDisconnected() {
|
||||
if (!window._wsConfig || !window._wsConfig.wsFallback) return;
|
||||
if (!this._wsConfig || !this._wsConfig.wsFallback) return;
|
||||
|
||||
for (const peerId in this.peers) {
|
||||
if (!this._webRtcSupported(peerId)) {
|
||||
@@ -1709,28 +1674,6 @@ class PeersManager {
|
||||
}
|
||||
}
|
||||
|
||||
_onFallbackToWs(peerId) {
|
||||
const peer = this.peers[peerId];
|
||||
|
||||
if (!peer || !window._wsConfig.wsFallback) return;
|
||||
|
||||
peer._onDisconnected();
|
||||
|
||||
const isCaller = peer._isCaller;
|
||||
const roomType = peer._getRoomTypes()[0];
|
||||
const roomId = peer._roomIds[roomType];
|
||||
|
||||
// create WSPeer with same arguments
|
||||
this._createPeer(isCaller, peerId, roomType, roomId, false);
|
||||
|
||||
// add missing room ids
|
||||
for (let i = 1; i < peer._roomIds.length; i++) {
|
||||
let roomType = peer._getRoomTypes()[i];
|
||||
let roomId = peer._roomIds[roomType];
|
||||
this.peers[peerId]._updateRoomIds(roomType, roomId);
|
||||
}
|
||||
}
|
||||
|
||||
_onPeerDisconnected(peerId) {
|
||||
const peer = this.peers[peerId];
|
||||
delete this.peers[peerId];
|
||||
|
||||
@@ -4,7 +4,7 @@ class PersistentStorage {
|
||||
PersistentStorage.logBrowserNotCapable();
|
||||
return;
|
||||
}
|
||||
const DBOpenRequest = window.indexedDB.open('pairdrop_store', 5);
|
||||
const DBOpenRequest = window.indexedDB.open('pairdrop_store', 6);
|
||||
DBOpenRequest.onerror = e => {
|
||||
PersistentStorage.logBrowserNotCapable();
|
||||
Logger.error('Error initializing database:', e);
|
||||
@@ -49,6 +49,28 @@ class PersistentStorage {
|
||||
await PersistentStorage.delete('editedDisplayName');
|
||||
}
|
||||
}
|
||||
if (e.oldVersion <= 5) {
|
||||
// migrate to v6
|
||||
let roomSecretsObjectStore5 = txn.objectStore('room_secrets');
|
||||
roomSecretsObjectStore5.createIndex('ws_domain', 'ws_domain');
|
||||
// add current ws_domain to existing peer secret entries once the config has loaded
|
||||
Events.on('config-loaded', _ => PersistentStorage.addCurrentWsDomainToAllRoomSecrets(), { once: true });
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
static getCurrentWsDomain() {
|
||||
return window._config && window._config.signalingServer
|
||||
? window._config.signalingServer
|
||||
: location.host + location.pathname;
|
||||
}
|
||||
|
||||
static async addCurrentWsDomainToAllRoomSecrets() {
|
||||
const wsServerDomain = this.getCurrentWsDomain();
|
||||
|
||||
const roomSecrets = await PersistentStorage.getAllRoomSecrets(false);
|
||||
for (let i = 0; i < roomSecrets.length; i++) {
|
||||
await PersistentStorage.updateRoomSecret(roomSecrets[i], null, null, null, null, wsServerDomain);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -124,7 +146,8 @@ class PersistentStorage {
|
||||
'secret': roomSecret,
|
||||
'display_name': displayName,
|
||||
'device_name': deviceName,
|
||||
'auto_accept': false
|
||||
'auto_accept': false,
|
||||
'ws_domain': PersistentStorage.getCurrentWsDomain()
|
||||
});
|
||||
objectStoreRequest.onsuccess = e => {
|
||||
Logger.debug(`Request successful. RoomSecret added: ${e.target.result}`);
|
||||
@@ -137,22 +160,28 @@ class PersistentStorage {
|
||||
})
|
||||
}
|
||||
|
||||
static async getAllRoomSecrets() {
|
||||
try {
|
||||
const roomSecrets = await this.getAllRoomSecretEntries();
|
||||
let secrets = [];
|
||||
for (let i = 0; i < roomSecrets.length; i++) {
|
||||
secrets.push(roomSecrets[i].secret);
|
||||
}
|
||||
Logger.debug(`Request successful. Retrieved ${secrets.length} room_secrets`);
|
||||
return(secrets);
|
||||
} catch (e) {
|
||||
this.logBrowserNotCapable();
|
||||
return [];
|
||||
}
|
||||
static async getAllRoomSecretsCount(currentWsDomainOnly = true) {
|
||||
return (await PersistentStorage.getAllRoomSecrets(currentWsDomainOnly)).length;
|
||||
}
|
||||
|
||||
static getAllRoomSecretEntries() {
|
||||
static async getAllRoomSecrets(currentWsDomainOnly = true) {
|
||||
let secrets = [];
|
||||
try {
|
||||
const roomSecrets = await this.getAllRoomSecretEntries(currentWsDomainOnly);
|
||||
|
||||
secrets = roomSecrets.map(roomSecret => roomSecret.secret);
|
||||
|
||||
Logger.debug(`Request successful. Retrieved ${secrets.length} room_secrets`);
|
||||
}
|
||||
catch (e) {
|
||||
console.debug(e)
|
||||
this.logBrowserNotCapable();
|
||||
}
|
||||
|
||||
return secrets;
|
||||
}
|
||||
|
||||
static getAllRoomSecretEntries(currentWsDomainOnly = true) {
|
||||
return new Promise((resolve, reject) => {
|
||||
const DBOpenRequest = window.indexedDB.open('pairdrop_store');
|
||||
DBOpenRequest.onsuccess = (e) => {
|
||||
@@ -161,7 +190,19 @@ class PersistentStorage {
|
||||
const objectStore = transaction.objectStore('room_secrets');
|
||||
const objectStoreRequest = objectStore.getAll();
|
||||
objectStoreRequest.onsuccess = e => {
|
||||
resolve(e.target.result);
|
||||
let roomSecrets = e.target.result;
|
||||
let roomSecretEntries = [];
|
||||
|
||||
for (let i = 0; i < roomSecrets.length; i++) {
|
||||
const currentWsDomainDiffers = roomSecrets[i].ws_domain !== PersistentStorage.getCurrentWsDomain();
|
||||
|
||||
// if the saved ws domain differs from the current ws domain and only peers for the current ws domain should be returned -> skip this entry
|
||||
if (currentWsDomainOnly && currentWsDomainDiffers) continue;
|
||||
|
||||
roomSecretEntries.push(roomSecrets[i]);
|
||||
}
|
||||
|
||||
resolve(roomSecretEntries);
|
||||
}
|
||||
}
|
||||
DBOpenRequest.onerror = (e) => {
|
||||
@@ -262,7 +303,7 @@ class PersistentStorage {
|
||||
return this.updateRoomSecret(roomSecret, null, null, null, autoAccept);
|
||||
}
|
||||
|
||||
static updateRoomSecret(roomSecret, updatedRoomSecret = null, updatedDisplayName = null, updatedDeviceName = null, updatedAutoAccept = null) {
|
||||
static updateRoomSecret(roomSecret, updatedRoomSecret = null, updatedDisplayName = null, updatedDeviceName = null, updatedAutoAccept = null, wsDomain = null) {
|
||||
return new Promise((resolve, reject) => {
|
||||
const DBOpenRequest = window.indexedDB.open('pairdrop_store');
|
||||
DBOpenRequest.onsuccess = e => {
|
||||
@@ -280,7 +321,8 @@ class PersistentStorage {
|
||||
'secret': updatedRoomSecret !== null ? updatedRoomSecret : roomSecretEntry.entry.secret,
|
||||
'display_name': updatedDisplayName !== null ? updatedDisplayName : roomSecretEntry.entry.display_name,
|
||||
'device_name': updatedDeviceName !== null ? updatedDeviceName : roomSecretEntry.entry.device_name,
|
||||
'auto_accept': updatedAutoAccept !== null ? updatedAutoAccept : roomSecretEntry.entry.auto_accept
|
||||
'auto_accept': updatedAutoAccept !== null ? updatedAutoAccept : roomSecretEntry.entry.auto_accept,
|
||||
'ws_domain': wsDomain !== null ? wsDomain : roomSecretEntry.entry.ws_domain
|
||||
};
|
||||
|
||||
const objectStoreRequestUpdate = objectStore.put(updatedRoomSecretEntry, roomSecretEntry.key);
|
||||
|
||||
@@ -25,7 +25,7 @@ class PeersUI {
|
||||
this.shareMode.text = "";
|
||||
|
||||
Events.on('peer-joined', e => this._onPeerJoined(e.detail.peer, e.detail.roomType, e.detail.roomId));
|
||||
Events.on('peer-connected', e => this._onPeerConnected(e.detail.peerId, e.detail.connectionHash, e.detail.rtcSupported));
|
||||
Events.on('peer-connected', e => this._onPeerConnected(e.detail.peerId, e.detail.connectionHash));
|
||||
Events.on('peer-connecting', e => this._onPeerConnecting(e.detail));
|
||||
Events.on('peer-disconnected', e => this._onPeerDisconnected(e.detail));
|
||||
Events.on('peers', e => this._onPeers(e.detail));
|
||||
@@ -110,12 +110,12 @@ class PeersUI {
|
||||
this.peerUIs[peer.id] = peerUI;
|
||||
}
|
||||
|
||||
_onPeerConnected(peerId, connectionHash, rtcSupported) {
|
||||
_onPeerConnected(peerId, connectionHash) {
|
||||
const peerUI = this.peerUIs[peerId];
|
||||
|
||||
if (!peerUI) return;
|
||||
|
||||
peerUI._peerConnected(true, connectionHash, rtcSupported);
|
||||
peerUI._peerConnected(true, connectionHash);
|
||||
|
||||
this._addPeerUIIfMissing(peerUI);
|
||||
}
|
||||
@@ -598,7 +598,7 @@ class PeerUI {
|
||||
});
|
||||
}
|
||||
|
||||
_peerConnected(connected = true, connectionHash = "", rtcSupported = false) {
|
||||
_peerConnected(connected = true, connectionHash = "") {
|
||||
if (connected) {
|
||||
this._connected = true;
|
||||
|
||||
@@ -606,9 +606,7 @@ class PeerUI {
|
||||
this.setStatus(this._oldStatus);
|
||||
this._oldStatus = null;
|
||||
|
||||
this._peer.rtcSupported = rtcSupported;
|
||||
this._connectionHash = connectionHash;
|
||||
this.updateTypesClassList();
|
||||
}
|
||||
else {
|
||||
this._connected = false;
|
||||
@@ -1697,6 +1695,7 @@ class PairDeviceDialog extends Dialog {
|
||||
Events.on('pair-device-join-key-invalid', _ => this._onPublicRoomJoinKeyInvalid());
|
||||
Events.on('pair-device-canceled', e => this._onPairDeviceCanceled(e.detail));
|
||||
Events.on('evaluate-number-room-secrets', _ => this._evaluateNumberRoomSecrets())
|
||||
Events.on('config-loaded', _ => this._evaluateNumberRoomSecrets())
|
||||
Events.on('secret-room-deleted', e => this._onSecretRoomDeleted(e.detail));
|
||||
this.$el.addEventListener('paste', e => this._onPaste(e));
|
||||
this.$qrCode.addEventListener('click', _ => this._copyPairUrl());
|
||||
@@ -1885,9 +1884,9 @@ class PairDeviceDialog extends Dialog {
|
||||
|
||||
_evaluateNumberRoomSecrets() {
|
||||
PersistentStorage
|
||||
.getAllRoomSecrets()
|
||||
.then(roomSecrets => {
|
||||
if (roomSecrets.length > 0) {
|
||||
.getAllRoomSecretsCount()
|
||||
.then(roomSecretsCount => {
|
||||
if (roomSecretsCount > 0) {
|
||||
this.$editPairedDevicesHeaderBtn.removeAttribute('hidden');
|
||||
this.$footerInstructionsPairedDevices.removeAttribute('hidden');
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user