From 7d76a657fa704c43130a6ffe645c7c87985c2c0c Mon Sep 17 00:00:00 2001 From: Paul Date: Sat, 7 Aug 2021 16:55:14 +0100 Subject: [PATCH] Fix new state updates. --- src/lib/vortex/VoiceState.ts | 17 ++++++++++++++--- 1 file changed, 14 insertions(+), 3 deletions(-) diff --git a/src/lib/vortex/VoiceState.ts b/src/lib/vortex/VoiceState.ts index d7fd6c9f..0c32fc16 100644 --- a/src/lib/vortex/VoiceState.ts +++ b/src/lib/vortex/VoiceState.ts @@ -34,6 +34,10 @@ class VoiceStateReference { this.status = VoiceStatus.UNLOADED; this.participants = new Map(); + this.syncState = this.syncState.bind(this); + this.connect = this.connect.bind(this); + this.disconnect = this.disconnect.bind(this); + makeAutoObservable(this, { client: false, connecting: false, @@ -58,6 +62,13 @@ class VoiceStateReference { const { default: VoiceClient } = await import("./VoiceClient"); const client = new VoiceClient(); + client.on("startProduce", this.syncState); + client.on("stopProduce", this.syncState); + client.on("userJoined", this.syncState); + client.on("userLeft", this.syncState); + client.on("userStartProduce", this.syncState); + client.on("userStopProduce", this.syncState); + runInAction(() => { if (!client.supported()) { this.status = VoiceStatus.UNAVAILABLE; @@ -91,6 +102,7 @@ class VoiceStateReference { }); await this.client.authenticate(call.token); + this.syncState(); runInAction(() => { this.status = VoiceStatus.RTC_CONNECTING; @@ -117,12 +129,11 @@ class VoiceStateReference { // Disconnect from current channel. @action disconnect() { - if (!this.client?.supported()) throw new Error("RTC is unavailable"); - this.connecting = false; this.status = VoiceStatus.READY; - this.client.disconnect(); + this.client?.disconnect(); + this.syncState(); } isProducing(type: ProduceType) {