remove forceDisconnect() and add change name notification

This commit is contained in:
schlagmichdoch 2022-12-30 22:55:48 +01:00
parent cb86e96ffc
commit 1b7aced340
2 changed files with 8 additions and 10 deletions

View file

@ -21,13 +21,12 @@ 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._reconnect);
Events.on('force-disconnect', this._onForceDisconnect);
} }
_onMessage(msg) { _onMessage(msg) {
msg = JSON.parse(msg); msg = JSON.parse(msg);
console.log('WS:', msg); if (msg.type !== 'ping') console.log('WS:', msg);
switch (msg.type) { switch (msg.type) {
case 'peers': case 'peers':
Events.fire('peers', msg.peers); Events.fire('peers', msg.peers);
@ -79,11 +78,6 @@ class ServerConnection {
Events.fire('disconnect'); Events.fire('disconnect');
} }
_onForceDisconnect() {
document.cookie = "peerid=; expires=Thu, 01 Jan 1970 00:00:00 UTC; path=/;";
this._connect();
}
_onVisibilityChange() { _onVisibilityChange() {
if (document.hidden) return; if (document.hidden) return;
this._connect(); this._connect();
@ -105,7 +99,7 @@ class ServerConnection {
_onError(e) { _onError(e) {
console.error(e); console.error(e);
this._onForceDisconnect(); this._connect();
} }
} }
@ -353,7 +347,7 @@ class RTCPeer extends Peer {
switch (this._conn.iceConnectionState) { switch (this._conn.iceConnectionState) {
case 'failed': case 'failed':
console.error('ICE Gathering failed'); console.error('ICE Gathering failed');
Events.fire('force-disconnect'); Events.fire('reconnect');
break; break;
default: default:
console.log('ICE Gathering', this._conn.iceConnectionState); console.log('ICE Gathering', this._conn.iceConnectionState);

View file

@ -9,6 +9,9 @@ window.iOS = /iPad|iPhone|iPod/.test(navigator.userAgent) && !window.MSStream;
Events.on('display-name', e => { Events.on('display-name', e => {
const me = e.detail.message; const me = e.detail.message;
const $displayName = $('displayName') const $displayName = $('displayName')
if ($displayName.textContent !== '') {
Events.fire('notify-user', 'Your name has changed.');
}
$displayName.textContent = 'You are known as ' + me.displayName; $displayName.textContent = 'You are known as ' + me.displayName;
$displayName.title = me.deviceName; $displayName.title = me.deviceName;
}); });
@ -65,6 +68,7 @@ class PeersUI {
_clearPeers() { _clearPeers() {
const $peers = $$('x-peers').innerHTML = ''; const $peers = $$('x-peers').innerHTML = '';
Object.keys(this.peers).forEach(peerId => delete this.peers[peerId]); Object.keys(this.peers).forEach(peerId => delete this.peers[peerId]);
setTimeout(e => window.animateBackground(true), 1750); // Start animation again
} }
_onPaste(e) { _onPaste(e) {