diff --git a/src/component/internal/webrtc.ts b/src/component/internal/webrtc.ts index 5024184f..56f0f468 100644 --- a/src/component/internal/webrtc.ts +++ b/src/component/internal/webrtc.ts @@ -455,15 +455,13 @@ export class NekoWebRTC extends EventEmitter { } private onDisconnected(error?: Error) { + const wasConnected = this._connected this.disconnect() - if (!this._connected) { - return + if (wasConnected) { + this._log.info(`disconnected`, { error }) + this.emit('disconnected', error) } - - this._log.info(`disconnected`, { error }) - this.emit('disconnected', error) - this._connected = false } private statsEmitter(ms: number = 2000) {