mirror of
https://github.com/remix-bot/fluxer.git
synced 2026-11-24 06:01:44 -05:00
:)
This commit is contained in:
1 parent
0cc865950a
commit
ee460d03ff
3 files changed
+893
-125
No files matched your search
Generated
+834
-119
File diff suppressed because it is too large.
Load diff
+57
-5
@@ -352,6 +352,10 @@ export default class Player extends EventEmitter {
|
|||||||
// destroyed flag — prevents recovery/playback/worker spawn after destroy()
|
// destroyed flag — prevents recovery/playback/worker spawn after destroy()
|
||||||
_destroyed = false;
|
_destroyed = false;
|
||||||
|
|
||||||
|
// publishToRoom self-healing — scheduled retry timer and consecutive fail count
|
||||||
|
_publishRetryTimer = null;
|
||||||
|
_publishFailCount = 0;
|
||||||
|
|
||||||
// NodeLink config (kept for direct stream URL building; session managed by moonlink)
|
// NodeLink config (kept for direct stream URL building; session managed by moonlink)
|
||||||
_nl = {
|
_nl = {
|
||||||
host: "localhost",
|
host: "localhost",
|
||||||
@@ -672,7 +676,7 @@ export default class Player extends EventEmitter {
|
|||||||
// Promise.race with a timeout, and retry up to 3 times with exponential
|
// Promise.race with a timeout, and retry up to 3 times with exponential
|
||||||
// backoff. On final failure, we DON'T leave the channel — the player
|
// backoff. On final failure, we DON'T leave the channel — the player
|
||||||
// stays connected and can retry later (critical for 24/7 channels).
|
// stays connected and can retry later (critical for 24/7 channels).
|
||||||
const PUBLISH_TIMEOUT_MS = 15_000; // 15s timeout per attempt
|
const PUBLISH_TIMEOUT_MS = 8_000; // 8s timeout per attempt (was 15s)
|
||||||
const MAX_RETRIES = 3;
|
const MAX_RETRIES = 3;
|
||||||
const BASE_BACKOFF_MS = 2_000;
|
const BASE_BACKOFF_MS = 2_000;
|
||||||
|
|
||||||
@@ -696,6 +700,11 @@ export default class Player extends EventEmitter {
|
|||||||
]);
|
]);
|
||||||
|
|
||||||
logger.mediaplayer(`[Player] MediaPlayer published successfully on attempt ${attempt}`);
|
logger.mediaplayer(`[Player] MediaPlayer published successfully on attempt ${attempt}`);
|
||||||
|
this._publishFailCount = 0;
|
||||||
|
if (this._publishRetryTimer) {
|
||||||
|
clearTimeout(this._publishRetryTimer);
|
||||||
|
this._publishRetryTimer = null;
|
||||||
|
}
|
||||||
return true;
|
return true;
|
||||||
} catch (e) {
|
} catch (e) {
|
||||||
const msg = e?.message ?? String(e);
|
const msg = e?.message ?? String(e);
|
||||||
@@ -729,12 +738,50 @@ export default class Player extends EventEmitter {
|
|||||||
} else {
|
} else {
|
||||||
// On final failure, DON'T leave the channel. The voice
|
// On final failure, DON'T leave the channel. The voice
|
||||||
// connection is still alive — just the audio publishing failed.
|
// connection is still alive — just the audio publishing failed.
|
||||||
// Leaving the channel on play failure causes 24/7 drops. The
|
// Schedule a self-healing retry so 24/7 channels recover automatically
|
||||||
// player can retry publishing when the next track is played.
|
// instead of staying silent forever.
|
||||||
|
this._publishFailCount = (this._publishFailCount ?? 0) + 1;
|
||||||
|
const SELF_HEAL_DELAY_MS = Math.min(30_000 * this._publishFailCount, 120_000);
|
||||||
|
|
||||||
logger.error(
|
logger.error(
|
||||||
`[Player] All ${MAX_RETRIES} publishToRoom attempts failed — ` +
|
`[Player] All ${MAX_RETRIES} publishToRoom attempts failed (fail #${this._publishFailCount}) — ` +
|
||||||
`staying in channel (connection still alive). Playback will retry on next track.`
|
`scheduling self-heal retry in ${SELF_HEAL_DELAY_MS / 1000}s.`
|
||||||
);
|
);
|
||||||
|
|
||||||
|
// Clear any existing retry timer before scheduling a new one
|
||||||
|
if (this._publishRetryTimer) {
|
||||||
|
clearTimeout(this._publishRetryTimer);
|
||||||
|
this._publishRetryTimer = null;
|
||||||
|
}
|
||||||
|
|
||||||
|
this._publishRetryTimer = setTimeout(async () => {
|
||||||
|
this._publishRetryTimer = null;
|
||||||
|
if (this._destroyed || this.leaving) return;
|
||||||
|
const roomStillAlive = this.connection?.room?.isConnected ?? false;
|
||||||
|
if (!roomStillAlive) {
|
||||||
|
// Room died — emit autoleave so the 24/7 handler can respawn
|
||||||
|
logger.warn("[Player] Self-heal: room no longer connected — emitting autoleave.");
|
||||||
|
this.emit("autoleave");
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
logger.player(`[Player] Self-heal: retrying publishToRoom for channel ${this._channelId ?? "?"}`);
|
||||||
|
const ok = await this._ensureMediaPlayer().catch(() => false);
|
||||||
|
if (ok) {
|
||||||
|
this._publishFailCount = 0;
|
||||||
|
logger.player("[Player] Self-heal: publishToRoom succeeded — resuming playback.");
|
||||||
|
if (!this.queue.isEmpty() && !this.queue.getCurrent()) {
|
||||||
|
this.playNext();
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
logger.warn("[Player] Self-heal: publishToRoom still failing — will try full reconnect.");
|
||||||
|
// Final resort: destroy this player and let GatewayHandler's
|
||||||
|
// 24/7 protection respawn it via _spawnPlayer.
|
||||||
|
if (!this._destroyed && !this.leaving) {
|
||||||
|
this.emit("autoleave");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}, SELF_HEAL_DELAY_MS);
|
||||||
|
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -1422,6 +1469,11 @@ export default class Player extends EventEmitter {
|
|||||||
clearTimeout(this._recoveryTimer);
|
clearTimeout(this._recoveryTimer);
|
||||||
this._recoveryTimer = null;
|
this._recoveryTimer = null;
|
||||||
}
|
}
|
||||||
|
if (this._publishRetryTimer) {
|
||||||
|
clearTimeout(this._publishRetryTimer);
|
||||||
|
this._publishRetryTimer = null;
|
||||||
|
}
|
||||||
|
this._publishFailCount = 0;
|
||||||
this._recoveryPending = false;
|
this._recoveryPending = false;
|
||||||
this._isRecovering = false;
|
this._isRecovering = false;
|
||||||
this._recoveryAttempts = 0;
|
this._recoveryAttempts = 0;
|
||||||
|
|||||||
@@ -1,4 +1,5 @@
|
|||||||
import { https } from "follow-redirects";
|
import pkg from "follow-redirects";
|
||||||
|
const { https } = pkg;
|
||||||
|
|
||||||
class Tuna {
|
class Tuna {
|
||||||
apiKey = null;
|
apiKey = null;
|
||||||
|
|||||||
Reference in new issue
Block a user