mirror of
https://github.com/schlagmichdoch/PairDrop.git
synced 2025-04-20 15:06:15 -04:00
readd persistent peerId via sessionStorage
This commit is contained in:
parent
8dc0f1cb0c
commit
621c525d11
2 changed files with 16 additions and 5 deletions
12
index.js
12
index.js
|
@ -102,7 +102,8 @@ class SnapdropServer {
|
||||||
type: 'display-name',
|
type: 'display-name',
|
||||||
message: {
|
message: {
|
||||||
displayName: peer.name.displayName,
|
displayName: peer.name.displayName,
|
||||||
deviceName: peer.name.deviceName
|
deviceName: peer.name.deviceName,
|
||||||
|
peerId: peer.id
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
@ -230,7 +231,7 @@ class Peer {
|
||||||
this._setIP(request);
|
this._setIP(request);
|
||||||
|
|
||||||
// set peer id
|
// set peer id
|
||||||
this._setPeerId()
|
this._setPeerId(request)
|
||||||
|
|
||||||
// is WebRTC supported ?
|
// is WebRTC supported ?
|
||||||
this.rtcSupported = request.url.indexOf('webrtc') > -1;
|
this.rtcSupported = request.url.indexOf('webrtc') > -1;
|
||||||
|
@ -297,9 +298,14 @@ class Peer {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
_setPeerId() {
|
_setPeerId(request) {
|
||||||
|
let peer_id = new URL(request.url, "http://server").searchParams.get("peer_id");
|
||||||
|
if (peer_id && /^([0-9]|[a-f]){8}-(([0-9]|[a-f]){4}-){3}([0-9]|[a-f]){12}$/.test(peer_id)) {
|
||||||
|
this.id = peer_id;
|
||||||
|
} else {
|
||||||
this.id = Peer.uuid();
|
this.id = Peer.uuid();
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
toString() {
|
toString() {
|
||||||
return `<Peer id=${this.id} ip=${this.ip} rtcSupported=${this.rtcSupported}>`
|
return `<Peer id=${this.id} ip=${this.ip} rtcSupported=${this.rtcSupported}>`
|
||||||
|
|
|
@ -43,6 +43,7 @@ class ServerConnection {
|
||||||
this.send({ type: 'pong' });
|
this.send({ type: 'pong' });
|
||||||
break;
|
break;
|
||||||
case 'display-name':
|
case 'display-name':
|
||||||
|
sessionStorage.setItem("peer_id", msg.message.peerId);
|
||||||
Events.fire('display-name', msg);
|
Events.fire('display-name', msg);
|
||||||
break;
|
break;
|
||||||
default:
|
default:
|
||||||
|
@ -59,7 +60,11 @@ class ServerConnection {
|
||||||
// hack to detect if deployment or development environment
|
// hack to detect if deployment or development environment
|
||||||
const protocol = location.protocol.startsWith('https') ? 'wss' : 'ws';
|
const protocol = location.protocol.startsWith('https') ? 'wss' : 'ws';
|
||||||
const webrtc = window.isRtcSupported ? '/webrtc' : '/fallback';
|
const webrtc = window.isRtcSupported ? '/webrtc' : '/fallback';
|
||||||
return protocol + '://' + location.host + location.pathname + 'server' + webrtc;
|
let url = new URL(protocol + '://' + location.host + location.pathname + 'server' + webrtc);
|
||||||
|
if (sessionStorage.getItem('peer_id')) {
|
||||||
|
url.searchParams.append('peer_id', sessionStorage.getItem('peer_id'))
|
||||||
|
}
|
||||||
|
return url.toString();
|
||||||
}
|
}
|
||||||
|
|
||||||
_disconnect() {
|
_disconnect() {
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue