revert some changes to regain stability
This commit is contained in:
parent
c3863a9dd3
commit
edf2ab5eb3
3 changed files with 12 additions and 20 deletions
4
index.js
4
index.js
|
@ -368,6 +368,10 @@ class PairDropServer {
|
||||||
// delete the peer
|
// delete the peer
|
||||||
delete this._rooms[room][peer.id];
|
delete this._rooms[room][peer.id];
|
||||||
|
|
||||||
|
if (roomType === 'ip') {
|
||||||
|
peer.socket.terminate();
|
||||||
|
}
|
||||||
|
|
||||||
//if room is empty, delete the room
|
//if room is empty, delete the room
|
||||||
if (!Object.keys(this._rooms[room]).length) {
|
if (!Object.keys(this._rooms[room]).length) {
|
||||||
delete this._rooms[room];
|
delete this._rooms[room];
|
||||||
|
|
|
@ -8,7 +8,6 @@ class ServerConnection {
|
||||||
constructor() {
|
constructor() {
|
||||||
this._connect();
|
this._connect();
|
||||||
Events.on('pagehide', _ => this._disconnect());
|
Events.on('pagehide', _ => this._disconnect());
|
||||||
Events.on('beforeunload', _ => this._onBeforeUnload());
|
|
||||||
document.addEventListener('visibilitychange', _ => this._onVisibilityChange());
|
document.addEventListener('visibilitychange', _ => 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));
|
||||||
|
@ -137,7 +136,8 @@ class ServerConnection {
|
||||||
return ws_url.toString();
|
return ws_url.toString();
|
||||||
}
|
}
|
||||||
|
|
||||||
_onBeforeUnload() {
|
_disconnect() {
|
||||||
|
this.send({ type: 'disconnect' });
|
||||||
if (this._socket) {
|
if (this._socket) {
|
||||||
this._socket.onclose = null;
|
this._socket.onclose = null;
|
||||||
this._socket.close();
|
this._socket.close();
|
||||||
|
@ -147,10 +147,6 @@ class ServerConnection {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
_disconnect() {
|
|
||||||
this.send({ type: 'disconnect' });
|
|
||||||
}
|
|
||||||
|
|
||||||
_onDisconnect() {
|
_onDisconnect() {
|
||||||
console.log('WS: server disconnected');
|
console.log('WS: server disconnected');
|
||||||
Events.fire('notify-user', 'Connecting..');
|
Events.fire('notify-user', 'Connecting..');
|
||||||
|
@ -573,7 +569,7 @@ class RTCPeer extends Peer {
|
||||||
const channel = event.channel || event.target;
|
const channel = event.channel || event.target;
|
||||||
channel.binaryType = 'arraybuffer';
|
channel.binaryType = 'arraybuffer';
|
||||||
channel.onmessage = e => this._onMessage(e.data);
|
channel.onmessage = e => this._onMessage(e.data);
|
||||||
channel.onclose = e => this._onChannelClosed(e);
|
channel.onclose = _ => this._onChannelClosed();
|
||||||
this._channel = channel;
|
this._channel = channel;
|
||||||
Events.on('beforeunload', e => this._onBeforeUnload(e));
|
Events.on('beforeunload', e => this._onBeforeUnload(e));
|
||||||
Events.on('pagehide', _ => this._onPageHide());
|
Events.on('pagehide', _ => this._onPageHide());
|
||||||
|
@ -617,8 +613,6 @@ class RTCPeer extends Peer {
|
||||||
if (this._busy) {
|
if (this._busy) {
|
||||||
e.preventDefault();
|
e.preventDefault();
|
||||||
return "There are unfinished transfers. Are you sure you want to close?";
|
return "There are unfinished transfers. Are you sure you want to close?";
|
||||||
} else {
|
|
||||||
this._disconnect();
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -798,7 +792,7 @@ class PeersManager {
|
||||||
|
|
||||||
_notifyPeerDisplayNameChanged(peerId) {
|
_notifyPeerDisplayNameChanged(peerId) {
|
||||||
const peer = this.peers[peerId];
|
const peer = this.peers[peerId];
|
||||||
if (!peer || (peer._conn && (peer._conn.signalingState !== "stable" || !peer._channel || peer._channel.readyState !== "open"))) return;
|
if (!peer) return;
|
||||||
this.peers[peerId].sendJSON({type: 'display-name-changed', displayName: this._displayName});
|
this.peers[peerId].sendJSON({type: 'display-name-changed', displayName: this._displayName});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -6,7 +6,6 @@ class ServerConnection {
|
||||||
constructor() {
|
constructor() {
|
||||||
this._connect();
|
this._connect();
|
||||||
Events.on('pagehide', _ => this._disconnect());
|
Events.on('pagehide', _ => this._disconnect());
|
||||||
Events.on('beforeunload', _ => this._onBeforeUnload());
|
|
||||||
document.addEventListener('visibilitychange', _ => this._onVisibilityChange());
|
document.addEventListener('visibilitychange', _ => 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));
|
||||||
|
@ -148,7 +147,8 @@ class ServerConnection {
|
||||||
return ws_url.toString();
|
return ws_url.toString();
|
||||||
}
|
}
|
||||||
|
|
||||||
_onBeforeUnload() {
|
_disconnect() {
|
||||||
|
this.send({ type: 'disconnect' });
|
||||||
if (this._socket) {
|
if (this._socket) {
|
||||||
this._socket.onclose = null;
|
this._socket.onclose = null;
|
||||||
this._socket.close();
|
this._socket.close();
|
||||||
|
@ -158,10 +158,6 @@ class ServerConnection {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
_disconnect() {
|
|
||||||
this.send({ type: 'disconnect' });
|
|
||||||
}
|
|
||||||
|
|
||||||
_onDisconnect() {
|
_onDisconnect() {
|
||||||
console.log('WS: server disconnected');
|
console.log('WS: server disconnected');
|
||||||
Events.fire('notify-user', 'Connecting..');
|
Events.fire('notify-user', 'Connecting..');
|
||||||
|
@ -584,7 +580,7 @@ class RTCPeer extends Peer {
|
||||||
const channel = event.channel || event.target;
|
const channel = event.channel || event.target;
|
||||||
channel.binaryType = 'arraybuffer';
|
channel.binaryType = 'arraybuffer';
|
||||||
channel.onmessage = e => this._onMessage(e.data);
|
channel.onmessage = e => this._onMessage(e.data);
|
||||||
channel.onclose = e => this._onChannelClosed(e);
|
channel.onclose = _ => this._onChannelClosed();
|
||||||
this._channel = channel;
|
this._channel = channel;
|
||||||
Events.on('beforeunload', e => this._onBeforeUnload(e));
|
Events.on('beforeunload', e => this._onBeforeUnload(e));
|
||||||
Events.on('pagehide', _ => this._onPageHide());
|
Events.on('pagehide', _ => this._onPageHide());
|
||||||
|
@ -628,8 +624,6 @@ class RTCPeer extends Peer {
|
||||||
if (this._busy) {
|
if (this._busy) {
|
||||||
e.preventDefault();
|
e.preventDefault();
|
||||||
return "There are unfinished transfers. Are you sure you want to close?";
|
return "There are unfinished transfers. Are you sure you want to close?";
|
||||||
} else {
|
|
||||||
this._disconnect();
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -879,7 +873,7 @@ class PeersManager {
|
||||||
|
|
||||||
_notifyPeerDisplayNameChanged(peerId) {
|
_notifyPeerDisplayNameChanged(peerId) {
|
||||||
const peer = this.peers[peerId];
|
const peer = this.peers[peerId];
|
||||||
if (!peer || (peer._conn && (peer._conn.signalingState !== "stable" || !peer._channel || peer._channel.readyState !== "open"))) return;
|
if (!peer) return;
|
||||||
this.peers[peerId].sendJSON({type: 'display-name-changed', displayName: this._displayName});
|
this.peers[peerId].sendJSON({type: 'display-name-changed', displayName: this._displayName});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue