Skip to content

Commit

Permalink
fixed some bugs
Browse files Browse the repository at this point in the history
  • Loading branch information
parasop committed Jul 12, 2024
1 parent 9a6bd60 commit fb33857
Show file tree
Hide file tree
Showing 7 changed files with 32 additions and 38 deletions.
1 change: 0 additions & 1 deletion dist/src/Node/Node.d.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
/// <reference types="node" />
import { Poru, PoruOptions, NodeGroup } from "../Poru";
import WebSocket from "ws";
import { Rest } from "./Rest";
Expand Down
1 change: 0 additions & 1 deletion dist/src/Node/Rest.d.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
/// <reference types="node" />
import { ErrorResponses, Node } from "./Node";
import { Poru } from "../Poru";
import { trackData } from "../guild/Track";
Expand Down
2 changes: 0 additions & 2 deletions dist/src/Player/Player.d.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
/// <reference types="node" />
/// <reference types="node" />
import { Poru, ResolveOptions, EventData, ConnectionOptions } from "../Poru";
import { Node, NodeLinkGetLyrics } from "../Node/Node";
import { Track } from "../guild/Track";
Expand Down
4 changes: 2 additions & 2 deletions dist/src/Player/Player.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion dist/src/Player/Player.js.map

Large diffs are not rendered by default.

2 changes: 0 additions & 2 deletions dist/src/Poru.d.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
/// <reference types="node" />
/// <reference types="node" />
import { Node, NodeLinkGetLyrics, NodeStats } from "./Node/Node";
import { EndSpeakingEventVoiceReceiverData, Player, StartSpeakingEventVoiceReceiverData } from "./Player/Player";
import { EventEmitter } from "events";
Expand Down
58 changes: 29 additions & 29 deletions src/Player/Player.ts
Original file line number Diff line number Diff line change
Expand Up @@ -33,18 +33,18 @@ export interface StartSpeakingEventVoiceReceiverData {
};

export interface EndSpeakingEventVoiceReceiverData {
/**
* The user ID of the user who stopped speaking.
*/
/**
* The user ID of the user who stopped speaking.
*/
userId: string;
/**
* The guild ID of the guild where the user stopped speaking.
*/
guildId: string;
guildId: string;
/**
* The audio data received from the user in base64.
*/
data: string;
data: string;
/**
* The type of the audio data. Can be either opus or pcm. Older versions may include ogg/opus.
*/
Expand Down Expand Up @@ -290,7 +290,7 @@ export class Player extends EventEmitter {
if (!this.node.isNodeLink) node = (Array.from(this.poru.nodes) as [string, Node][])?.find(([, node]) => node.isNodeLink)?.[1];
if (!node || !node.isNodeLink) throw new Error("[Poru Exception] No NodeLink node found in the Poru instance.");

if (!encodedTrack && !this.currentTrack) throw new Error("[Poru Exception] A track must be playing right now or be supplied.") ;
if (!encodedTrack && !this.currentTrack) throw new Error("[Poru Exception] A track must be playing right now or be supplied.");

encodedTrack = this.currentTrack?.track;

Expand Down Expand Up @@ -498,7 +498,7 @@ export class Player extends EventEmitter {
throw new Error("Provided Node is not connected")

try {
await this.node.rest.destroyPlayer(this.guildId).catch(() => {})
await this.node.rest.destroyPlayer(this.guildId).catch(() => { })
this.poru.players.delete(this.guildId)
this.node = node
this.poru.players.set(this.guildId, this)
Expand Down Expand Up @@ -571,17 +571,17 @@ export class Player extends EventEmitter {
}
case "TrackEndEvent": {
this.previousTrack = this.currentTrack
if (["loadFailed", "cleanup","replaced"].includes(data.reason)) {
if (["loadFailed", "cleanup", "replaced"].includes(data.reason)) {
return this.poru.emit("trackEnd", this, this.currentTrack!, data)
}
}

if (this.loop === "TRACK") {
this.queue.unshift(this.previousTrack!)
this.poru.emit("trackEnd", this, this.currentTrack!, data)
await this.poru.emit("trackEnd", this, this.currentTrack!, data)
return await this.play()
} else if (this.currentTrack && this.loop === "QUEUE") {
this.queue.push(this.previousTrack!)
this.poru.emit("trackEnd", this, this.currentTrack, data)
await this.poru.emit("trackEnd", this, this.currentTrack, data)
return await this.play()
}

Expand Down Expand Up @@ -700,17 +700,17 @@ export class Player extends EventEmitter {
*/
private async voiceReceiverClose(event: any): Promise<void> {
try {
await this.voiceReceiverDisconnect();
this.poru.emit("debug", this.node.name, `[Voice Receiver Web Socket] Connection was closed with the following Error code: ${event || "Unknown code"}`);
await this.voiceReceiverDisconnect();
this.poru.emit("debug", this.node.name, `[Voice Receiver Web Socket] Connection was closed with the following Error code: ${event || "Unknown code"}`);

if (event !== 1000) await this.voiceReceiverReconnect();
if (event !== 1000) await this.voiceReceiverReconnect();
} catch (error) {
this.poru.emit("debug", "[Voice Receiver Web Socket] Error while closing the connection with the node.", error);
this.poru.emit("debug", "[Voice Receiver Web Socket] Error while closing the connection with the node.", error);
};
};

private startsWithMultiple (s: string, words: string[]) {
return words.some( w => s.startsWith(w))
private startsWithMultiple(s: string, words: string[]) {
return words.some(w => s.startsWith(w))
};

/**
Expand All @@ -721,9 +721,9 @@ export class Player extends EventEmitter {
private async voiceReceiverReconnect(): Promise<void> {
this.voiceReceiverReconnectTimeout = setTimeout(async () => {
if (this.voiceReceiverAttempt > this.voiceReceiverReconnectTries) {
throw new Error(
`[Poru Voice Receiver Websocket] Unable to connect with ${this.node.name} node to the voice Receiver Websocket after ${this.voiceReceiverReconnectTries} tries`
);
throw new Error(
`[Poru Voice Receiver Websocket] Unable to connect with ${this.node.name} node to the voice Receiver Websocket after ${this.voiceReceiverReconnectTries} tries`
);
}
// Delete the ws instance
this.isConnected = false;
Expand Down Expand Up @@ -756,15 +756,15 @@ export class Player extends EventEmitter {
*/
private async voiceReceiverOpen(): Promise<void> {
try {
if (this.voiceReceiverReconnectTimeout) {
clearTimeout(this.voiceReceiverReconnectTimeout);
this.voiceReceiverReconnectTimeout = null;
};
if (this.voiceReceiverReconnectTimeout) {
clearTimeout(this.voiceReceiverReconnectTimeout);
this.voiceReceiverReconnectTimeout = null;
};

this.isConnectToVoiceReceiver = true;
this.poru.emit("voiceReceiverConnected", this, `[Voice Receiver Web Socket] Connection ready ${this.node.socketURL}/connection/data`)
this.isConnectToVoiceReceiver = true;
this.poru.emit("voiceReceiverConnected", this, `[Voice Receiver Web Socket] Connection ready ${this.node.socketURL}/connection/data`)
} catch (error) {
this.poru.emit("debug", `[Voice Receiver Web Socket] Error while opening the connection with the node ${this.node.name}. to the voice Receiver Websocket.`, error)
this.poru.emit("debug", `[Voice Receiver Web Socket] Error while opening the connection with the node ${this.node.name}. to the voice Receiver Websocket.`, error)
};
};

Expand Down Expand Up @@ -800,7 +800,7 @@ export class Player extends EventEmitter {
}
}
} catch (err) {
this.poru.emit("voiceReceiverError", this, "[Voice Receiver Web Socket] Error while parsing the payload. " + err);
this.poru.emit("voiceReceiverError", this, "[Voice Receiver Web Socket] Error while parsing the payload. " + err);
};
};
/**
Expand Down

0 comments on commit fb33857

Please sign in to comment.