fix(music): resolve autoplay candidate exhaustion and voice connection stalls

- Expand autoplay candidate search pool to 20 tracks and increase mix pool TTL to 2 hours
- Support multi-stage recommendations using both seed and last-played track
- Add resilient fallback in pickAutoplayTrack to prevent playback from halting
- Prevent race condition by clearing _playingNext before queueEnd playNext()
- Auto-reconnect voice connection before track advancement if connection dropped
This commit is contained in:
NoLogicAlan committed 2026-11-04 03:19:55 +03:00
1 parent 7df4e0cd36
commit ed76a6ebfe
3 files changed
+106 -55

No files matched your search

+9
View File
@@ -186,6 +186,15 @@ const PlaybackMixin = {
this._stopInactivityTimer();
this._wasRadio = songData.type === "radio";
if ((!this._voiceConn || (typeof this._voiceConn.isConnected === "function" && !this._voiceConn.isConnected())) && this._channelId && !this.leaving && !this._destroyed) {
try {
logger.player(`[Player] Reconnecting voice channel before play: ${this._channelId}`);
await this.join(this._channelId);
} catch (joinErr) {
logger.warn(`[Player] Reconnect before play failed: ${joinErr.message}`);
}
}
if (!this._voiceConn || this.leaving) return;
if (this._voiceConn) {
+9 -1
View File
@@ -486,7 +486,8 @@ class Player extends EventEmitter {
logger.player(`[Player] Busy joining. Ignoring: ${channelId}`);
return;
}
if (this._voiceConn && this._channelId === channelId) {
const isConnActive = this._voiceConn && (typeof this._voiceConn.isConnected !== "function" || this._voiceConn.isConnected());
if (isConnActive && this._channelId === channelId) {
logger.player(`[Player] Already in channel: ${channelId}`);
return;
}
@@ -603,6 +604,13 @@ class Player extends EventEmitter {
voiceConn.on("disconnect", () => {
if (this.leaving || this._destroyed) return;
logger.player(`[Player] Voice connection disconnected`);
this._voiceConn = null;
this.connection = null;
const cId = cleanId(this._channelId ?? this._home247Channel ?? "");
if (cId && (this._get247Mode() === "on" || this.queue?.getCurrent() || !(this.queue?.isEmpty?.() ?? true))) {
logger.player(`[Player] Voice disconnected with active session — scheduling reconnect to channel ${cId}`);
this.join(cId).catch(err => logger.warn(`[Player] Voice reconnect after disconnect failed: ${err?.message}`));
}
});
}