Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
22 changes: 20 additions & 2 deletions src/Player/Connection.ts
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,7 @@ export class Connection {
public voice: IVoiceServer | PartialNull<IVoiceServer>;
public self_mute: boolean;
public self_deaf: boolean;
private unpauseTimeout: NodeJS.Timeout | null;

/**
* The connection class
Expand All @@ -70,6 +71,7 @@ export class Connection {
};
this.self_mute = false;
this.self_deaf = false;
this.unpauseTimeout = null;
}

/**
Expand All @@ -87,12 +89,18 @@ export class Connection {
guildId: this.player.guildId,
data: { voice: this.voice },
});
setTimeout(async () => {

// Clear any existing timeout to prevent memory leaks
if (this.unpauseTimeout) {
clearTimeout(this.unpauseTimeout);
}

this.unpauseTimeout = setTimeout(async () => {
await this.player.node.rest.updatePlayer({
guildId: this.player.guildId,
data: { paused: false },
})

this.unpauseTimeout = null;
}, 1000)

this.player.poru.emit(
Expand Down Expand Up @@ -120,4 +128,14 @@ export class Connection {
this.self_mute = self_mute;
this.voice.sessionId = session_id || null;
};

/**
* Clean up connection resources
*/
public cleanup(): void {
if (this.unpauseTimeout) {
clearTimeout(this.unpauseTimeout);
this.unpauseTimeout = null;
}
};
};
6 changes: 5 additions & 1 deletion src/Player/CustomFilters.ts
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,11 @@ export class customFilter extends Filters {
if (!this.player) return this;
this.slowmode = val;

await this.setFilters(val ? { timescale: { speed: 0.5, pitch: 1.0, rate: 0.8 } } as FiltersOptions : await this.clearFilters());
if (val) {
await this.setFilters({ timescale: { speed: 0.5, pitch: 1.0, rate: 0.8 } } as FiltersOptions);
} else {
await this.clearFilters();
}
return this;
};

Expand Down
7 changes: 5 additions & 2 deletions src/Player/Player.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,10 @@ type Loop = "NONE" | "TRACK" | "QUEUE"

const escapeRegExp = (str: string) => {
try {
str.replace(/[.*+?^${}()|[\]\\]/g, "\\$&")
} catch { }
return str.replace(/[.*+?^${}()|[\]\\]/g, "\\$&")
} catch {
return str
}
}

interface BaseVoiceReceiverEvent {
Expand Down Expand Up @@ -464,6 +466,7 @@ export class Player extends EventEmitter {
*/
public async destroy(): Promise<boolean> {
await this.disconnect()
this.connection.cleanup() // Clean up connection resources
await this.node.rest.destroyPlayer(this.guildId)
this.poru.emit("debug", this.guildId, `[Poru Player] destroyed the player`)
this.poru.emit("playerDestroy", this)
Expand Down