Reconnect on rejoin room
This commit is contained in:
parent
83ff45da15
commit
3601ace829
1 changed files with 15 additions and 3 deletions
|
@ -4,6 +4,8 @@ class ServerConnection {
|
||||||
this._connect();
|
this._connect();
|
||||||
Events.on('beforeunload', e => this._disconnect(), false);
|
Events.on('beforeunload', e => this._disconnect(), false);
|
||||||
Events.on('pagehide', e => this._disconnect(), false);
|
Events.on('pagehide', e => this._disconnect(), false);
|
||||||
|
document.addEventListener('visibilitychange', e => this._onVisibilityChange());
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
_connect() {
|
_connect() {
|
||||||
|
@ -71,6 +73,11 @@ class ServerConnection {
|
||||||
clearTimeout(this._reconnectTimer);
|
clearTimeout(this._reconnectTimer);
|
||||||
this._reconnectTimer = setTimeout(_ => this._connect(), 5000);
|
this._reconnectTimer = setTimeout(_ => this._connect(), 5000);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
_onVisibilityChange() {
|
||||||
|
if (document.hidden) return;
|
||||||
|
this._connect();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
class Peer {
|
class Peer {
|
||||||
|
@ -296,7 +303,12 @@ class RTCPeer extends Peer {
|
||||||
_onConnectionStateChange(e) {
|
_onConnectionStateChange(e) {
|
||||||
console.log('RTC: state changed:', this._peer.connectionState);
|
console.log('RTC: state changed:', this._peer.connectionState);
|
||||||
switch (this._peer.connectionState) {
|
switch (this._peer.connectionState) {
|
||||||
case 'disconnected': this._onChannelClosed();
|
case 'disconnected':
|
||||||
|
this._onChannelClosed();
|
||||||
|
break;
|
||||||
|
case 'failed':
|
||||||
|
this._peer = null;
|
||||||
|
this._onChannelClosed();
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -312,7 +324,7 @@ class RTCPeer extends Peer {
|
||||||
refresh() {
|
refresh() {
|
||||||
// check if channel open. otherwise create one
|
// check if channel open. otherwise create one
|
||||||
if (this._peer && this._channel && this._channel.readyState !== 'open') return;
|
if (this._peer && this._channel && this._channel.readyState !== 'open') return;
|
||||||
this._createChannel(this._peerId, this._isCaller);
|
this._start(this._peerId, this._isCaller);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue