Fix new state updates.

This commit is contained in:
Paul 2021-08-07 16:55:14 +01:00
parent 4ec1ff5c59
commit 7d76a657fa

View file

@ -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) {