mirror of
https://github.com/schlagmichdoch/PairDrop.git
synced 2025-04-20 23:16:13 -04:00
add 'visbilitychange' event support for older browsers
This commit is contained in:
parent
fdf20cfdd9
commit
2a837eb195
2 changed files with 22 additions and 4 deletions
|
@ -3,12 +3,21 @@ window.isRtcSupported = !!(window.RTCPeerConnection || window.mozRTCPeerConnecti
|
||||||
|
|
||||||
if (!window.isRtcSupported) alert("WebRTC must be enabled for PairDrop to work");
|
if (!window.isRtcSupported) alert("WebRTC must be enabled for PairDrop to work");
|
||||||
|
|
||||||
|
window.hiddenProperty = 'hidden' in document ? 'hidden' :
|
||||||
|
'webkitHidden' in document ? 'webkitHidden' :
|
||||||
|
'mozHidden' in document ? 'mozHidden' :
|
||||||
|
null;
|
||||||
|
window.visibilityChangeEvent = 'visibilitychange' in document ? 'visibilitychange' :
|
||||||
|
'webkitvisibilitychange' in document ? 'webkitvisibilitychange' :
|
||||||
|
'mozvisibilitychange' in document ? 'mozvisibilitychange' :
|
||||||
|
null;
|
||||||
|
|
||||||
class ServerConnection {
|
class ServerConnection {
|
||||||
|
|
||||||
constructor() {
|
constructor() {
|
||||||
this._connect();
|
this._connect();
|
||||||
Events.on('pagehide', _ => this._disconnect());
|
Events.on('pagehide', _ => this._disconnect());
|
||||||
document.addEventListener('visibilitychange', _ => this._onVisibilityChange());
|
document.addEventListener(window.visibilityChangeEvent, _ => this._onVisibilityChange());
|
||||||
if (navigator.connection) navigator.connection.addEventListener('change', _ => this._reconnect());
|
if (navigator.connection) navigator.connection.addEventListener('change', _ => this._reconnect());
|
||||||
Events.on('room-secrets', e => this._sendRoomSecrets(e.detail));
|
Events.on('room-secrets', e => this._sendRoomSecrets(e.detail));
|
||||||
Events.on('room-secrets-deleted', e => this.send({ type: 'room-secrets-deleted', roomSecrets: e.detail}));
|
Events.on('room-secrets-deleted', e => this.send({ type: 'room-secrets-deleted', roomSecrets: e.detail}));
|
||||||
|
@ -186,7 +195,7 @@ class ServerConnection {
|
||||||
}
|
}
|
||||||
|
|
||||||
_onVisibilityChange() {
|
_onVisibilityChange() {
|
||||||
if (document.hidden) return;
|
if (window.hiddenProperty) return;
|
||||||
this._connect();
|
this._connect();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -1,12 +1,21 @@
|
||||||
window.URL = window.URL || window.webkitURL;
|
window.URL = window.URL || window.webkitURL;
|
||||||
window.isRtcSupported = !!(window.RTCPeerConnection || window.mozRTCPeerConnection || window.webkitRTCPeerConnection);
|
window.isRtcSupported = !!(window.RTCPeerConnection || window.mozRTCPeerConnection || window.webkitRTCPeerConnection);
|
||||||
|
|
||||||
|
window.hiddenProperty = 'hidden' in document ? 'hidden' :
|
||||||
|
'webkitHidden' in document ? 'webkitHidden' :
|
||||||
|
'mozHidden' in document ? 'mozHidden' :
|
||||||
|
null;
|
||||||
|
window.visibilityChangeEvent = 'visibilitychange' in document ? 'visibilitychange' :
|
||||||
|
'webkitvisibilitychange' in document ? 'webkitvisibilitychange' :
|
||||||
|
'mozvisibilitychange' in document ? 'mozvisibilitychange' :
|
||||||
|
null;
|
||||||
|
|
||||||
class ServerConnection {
|
class ServerConnection {
|
||||||
|
|
||||||
constructor() {
|
constructor() {
|
||||||
this._connect();
|
this._connect();
|
||||||
Events.on('pagehide', _ => this._disconnect());
|
Events.on('pagehide', _ => this._disconnect());
|
||||||
document.addEventListener('visibilitychange', _ => this._onVisibilityChange());
|
document.addEventListener(window.visibilityChangeEvent, _ => this._onVisibilityChange());
|
||||||
if (navigator.connection) navigator.connection.addEventListener('change', _ => this._reconnect());
|
if (navigator.connection) navigator.connection.addEventListener('change', _ => this._reconnect());
|
||||||
Events.on('room-secrets', e => this._sendRoomSecrets(e.detail));
|
Events.on('room-secrets', e => this._sendRoomSecrets(e.detail));
|
||||||
Events.on('room-secrets-deleted', e => this.send({ type: 'room-secrets-deleted', roomSecrets: e.detail}));
|
Events.on('room-secrets-deleted', e => this.send({ type: 'room-secrets-deleted', roomSecrets: e.detail}));
|
||||||
|
@ -197,7 +206,7 @@ class ServerConnection {
|
||||||
}
|
}
|
||||||
|
|
||||||
_onVisibilityChange() {
|
_onVisibilityChange() {
|
||||||
if (document.hidden) return;
|
if (window.hiddenProperty) return;
|
||||||
this._connect();
|
this._connect();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue