mirror of
https://github.com/schlagmichdoch/PairDrop.git
synced 2025-04-20 23:16:13 -04:00
clear peers on page hide
This commit is contained in:
parent
59671a751b
commit
651047cfa8
1 changed files with 9 additions and 7 deletions
|
@ -5,10 +5,10 @@ class ServerConnection {
|
||||||
|
|
||||||
constructor() {
|
constructor() {
|
||||||
this._connect();
|
this._connect();
|
||||||
Events.on('beforeunload', e => this._disconnect());
|
Events.on('beforeunload', _ => this._disconnect());
|
||||||
Events.on('pagehide', e => this._disconnect());
|
Events.on('pagehide', _ => this._disconnect());
|
||||||
document.addEventListener('visibilitychange', e => this._onVisibilityChange());
|
document.addEventListener('visibilitychange', _ => this._onVisibilityChange());
|
||||||
Events.on('online', this._connect);
|
Events.on('online', _ => this._connect());
|
||||||
}
|
}
|
||||||
|
|
||||||
_connect() {
|
_connect() {
|
||||||
|
@ -21,7 +21,7 @@ class ServerConnection {
|
||||||
ws.onclose = _ => this._onDisconnect();
|
ws.onclose = _ => this._onDisconnect();
|
||||||
ws.onerror = e => this._onError(e);
|
ws.onerror = e => this._onError(e);
|
||||||
this._socket = ws;
|
this._socket = ws;
|
||||||
Events.on('reconnect', this._connect);
|
Events.on('reconnect', _ => this._connect());
|
||||||
}
|
}
|
||||||
|
|
||||||
_onMessage(msg) {
|
_onMessage(msg) {
|
||||||
|
@ -67,7 +67,6 @@ class ServerConnection {
|
||||||
this.send({ type: 'disconnect' });
|
this.send({ type: 'disconnect' });
|
||||||
this._socket.onclose = null;
|
this._socket.onclose = null;
|
||||||
this._socket.close();
|
this._socket.close();
|
||||||
Events.fire('disconnect');
|
|
||||||
}
|
}
|
||||||
|
|
||||||
_onDisconnect() {
|
_onDisconnect() {
|
||||||
|
@ -79,7 +78,10 @@ class ServerConnection {
|
||||||
}
|
}
|
||||||
|
|
||||||
_onVisibilityChange() {
|
_onVisibilityChange() {
|
||||||
if (document.hidden) return;
|
if (document.hidden) {
|
||||||
|
Events.fire('disconnect');
|
||||||
|
return;
|
||||||
|
}
|
||||||
this._connect();
|
this._connect();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue