From 9771b551df8f8176ff66f3a3954e8f6fe0e82654 Mon Sep 17 00:00:00 2001 From: m1k1o Date: Fri, 19 Mar 2021 20:16:08 +0100 Subject: [PATCH] proper disconnect. --- README.md | 1 + client/src/neko/base.ts | 34 ++++++++++++++++++++++++++++++---- 2 files changed, 31 insertions(+), 4 deletions(-) diff --git a/README.md b/README.md index 82d1d4db..dd20b590 100644 --- a/README.md +++ b/README.md @@ -41,6 +41,7 @@ For n.eko room management software visit https://github.com/m1k1o/neko-rooms. - Fixed sessions manager thread safety by adding mutexes (caused panic in rare edge cases). - Now when user gets kicked, he won't join as a ghost user again but will be logged out. - **iOS compatibility!** Fixed really strange CSS bug, which prevented iOS from loading the video. +- Proper disconnect only once with unsubscribing events. When webrtc fails, user won't be logged in without username again. ### Misc - Custom docker workflow. diff --git a/client/src/neko/base.ts b/client/src/neko/base.ts index de2532b1..dbc70971 100644 --- a/client/src/neko/base.ts +++ b/client/src/neko/base.ts @@ -76,17 +76,43 @@ export abstract class BaseClient extends EventEmitter { clearTimeout(this._timeout) } - if (this.socketOpen) { + if (this._ws) { + // reset all events + this._ws.onmessage = () => {} + this._ws.onerror = () => {} + this._ws.onclose = () => {} + try { - this._ws!.close() + this._ws.close() } catch (err) {} + this._ws = undefined } - if (this.peerConnected) { + if (this._channel) { + // reset all events + this._channel.onmessage = () => {} + this._channel.onerror = () => {} + this._channel.onclose = () => {} + try { - this._peer!.close() + this._channel.close() } catch (err) {} + + this._channel = undefined + } + + if (this._peer) { + // reset all events + this._peer.onconnectionstatechange = () => {} + this._peer.onsignalingstatechange = () => {} + this._peer.oniceconnectionstatechange = () => {} + this._peer.ontrack = () => {} + + try { + this._peer.close() + } catch (err) {} + this._peer = undefined }