Skip to content

Commit

Permalink
refactor(VoiceConnection): restructure property
Browse files Browse the repository at this point in the history
  • Loading branch information
Fab1o0107 committed Dec 26, 2023
1 parent c166275 commit ac2c545
Showing 1 changed file with 8 additions and 8 deletions.
16 changes: 8 additions & 8 deletions src/guild/VoiceConnection.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,8 @@ import { State, VoiceState } from "../Constants";
import { Icelink, VoiceChannelOptions } from "../Icelink";

export interface StateUpdatePartial {
channel_id?: string;
session_id?: string;
channel_id: string | null;
self_deaf: boolean;
self_mute: boolean;
}
Expand Down Expand Up @@ -153,7 +153,10 @@ export class VoiceConnection extends EventEmitter {
*/
public setStateUpdate({ session_id, channel_id, self_deaf, self_mute }: StateUpdatePartial): void {
this.lastChannelId = this.channelId?.repeat(1) ?? null;
this.channelId = channel_id ?? null;
this.channelId = channel_id;
this.deafened = self_deaf;
this.muted = self_mute;
this.sessionId = session_id ?? null;

if (this.channelId && this.lastChannelId !== this.channelId)
this.manager.emit(
Expand All @@ -165,11 +168,9 @@ export class VoiceConnection extends EventEmitter {
this.state = State.Disconnected;

this.manager.emit("debug", `[VOICE => DISCORD] Channel disconnected, guild: ${this.guildId}`);
}

this.deafened = self_deaf;
this.muted = self_mute;
this.sessionId = session_id ?? null;
return undefined;
}

this.manager.emit(
"debug",
Expand All @@ -195,15 +196,14 @@ export class VoiceConnection extends EventEmitter {

this.lastRegion = this.region?.repeat(1) ?? null;
this.region = data.endpoint.split(".").shift()?.replace(/[0-9]/g, "") ?? null;
this.serverUpdate = data;

if (this.region && this.lastRegion !== this.region)
this.manager.emit(
"debug",
`[VOICE => DISCORD] Voice region changed, old region: ${this.lastRegion}, new region: ${this.region}, guild: ${this.guildId}`
);

this.serverUpdate = data;

this.emit("connectionUpdate", VoiceState.SessionReady);
this.manager.emit("debug", `[VOICE => DISCORD] Server update received, guild: ${this.guildId}`);
}
Expand Down

0 comments on commit ac2c545

Please sign in to comment.