mirror of
https://github.com/remix-bot/fluxer.git
synced 2026-11-24 06:01:44 -05:00
notsure
This commit is contained in:
1 parent
0e3087c7b5
commit
4f769f832f
2 files changed
+35
-1
No files matched your search
@@ -639,6 +639,8 @@ To add a new language, place a JSON file in `storage/locales/bot/` following the
|
|||||||
- [`NodeLink`](https://github.com/PerformanC/NodeLink) — Lavalink-compatible audio node
|
- [`NodeLink`](https://github.com/PerformanC/NodeLink) — Lavalink-compatible audio node
|
||||||
- [`prism-media`](https://github.com/discordjs/prism-media) — Opus encoding and stream demuxing
|
- [`prism-media`](https://github.com/discordjs/prism-media) — Opus encoding and stream demuxing
|
||||||
|
|
||||||
|
---
|
||||||
|
|
||||||
<p align="center">
|
<p align="center">
|
||||||
© 2026 Remix. Code licensed under the <a href="LICENSE">MIT License</a>.<br>
|
© 2026 Remix. Code licensed under the <a href="LICENSE">MIT License</a>.<br>
|
||||||
<em>The Remix name, logo, and branding are proprietary and may not be reused.</em>
|
<em>The Remix name, logo, and branding are proprietary and may not be reused.</em>
|
||||||
|
|||||||
@@ -17,6 +17,23 @@ const pendingUnpublishSids = new WeakMap();
|
|||||||
/** @type {number} @description Max time to wait for a stale-track unpublish to settle before publishing anyway (defensive — an unpublish should resolve almost instantly; this only guards against a hung/never-resolving LiveKit promise blocking playback indefinitely). */
|
/** @type {number} @description Max time to wait for a stale-track unpublish to settle before publishing anyway (defensive — an unpublish should resolve almost instantly; this only guards against a hung/never-resolving LiveKit promise blocking playback indefinitely). */
|
||||||
const UNPUBLISH_WAIT_TIMEOUT_MS = 1200;
|
const UNPUBLISH_WAIT_TIMEOUT_MS = 1200;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Trackstream circuit breaker (shared by all bridges — they all talk to the
|
||||||
|
* same NodeLink). When /v4/trackstream keeps timing out and loadstream is
|
||||||
|
* enabled, every track used to burn ~15s (timeout) + ~13s (loadtracks retry)
|
||||||
|
* before reaching the route that actually works. After TS_BREAKER_THRESHOLD
|
||||||
|
* consecutive failures we skip trackstream for TS_BREAKER_COOLDOWN_MS, then
|
||||||
|
* probe it once again.
|
||||||
|
*/
|
||||||
|
const TS_BREAKER_THRESHOLD = 2;
|
||||||
|
const TS_BREAKER_COOLDOWN_MS = 5 * 60_000;
|
||||||
|
const _tsBreaker = { failures: 0, openUntil: 0 };
|
||||||
|
const tsBreakerOpen = () => _tsBreaker.failures >= TS_BREAKER_THRESHOLD && Date.now() < _tsBreaker.openUntil;
|
||||||
|
const tsBreakerFail = () => { _tsBreaker.failures++; if (_tsBreaker.failures >= TS_BREAKER_THRESHOLD) _tsBreaker.openUntil = Date.now() + TS_BREAKER_COOLDOWN_MS; };
|
||||||
|
const tsBreakerOk = () => { _tsBreaker.failures = 0; _tsBreaker.openUntil = 0; };
|
||||||
|
/** Timeouts/connection errors mean the node is slow — a fresh encoded track will not help. */
|
||||||
|
const isSlowNodeError = (e) => /timeout|ECONNRESET|ECONNREFUSED|EAI_AGAIN/i.test(String(e?.message || e));
|
||||||
|
|
||||||
/** @extends {EventEmitter} */
|
/** @extends {EventEmitter} */
|
||||||
export class FluxerAudioBridge extends EventEmitter {
|
export class FluxerAudioBridge extends EventEmitter {
|
||||||
_conn = null;
|
_conn = null;
|
||||||
@@ -110,7 +127,9 @@ export class FluxerAudioBridge extends EventEmitter {
|
|||||||
const trackstreamGate = loadstreamEnabled
|
const trackstreamGate = loadstreamEnabled
|
||||||
? (seekMs === 0 && !filterPayload) // loadstream owns seek/filter cases when enabled
|
? (seekMs === 0 && !filterPayload) // loadstream owns seek/filter cases when enabled
|
||||||
: true;
|
: true;
|
||||||
if (trackstreamGate && trackInfo.encoded && this._lavalink) {
|
const skipTrackstream = loadstreamEnabled && tsBreakerOpen();
|
||||||
|
if (skipTrackstream) logger.player("[AudioBridge] Trackstream circuit open (recent timeouts) — going straight to loadstream.");
|
||||||
|
if (trackstreamGate && !skipTrackstream && trackInfo.encoded && this._lavalink) {
|
||||||
const result = await this._playViaTrackstream(conn, trackInfo, { seekMs, durationMs, generation });
|
const result = await this._playViaTrackstream(conn, trackInfo, { seekMs, durationMs, generation });
|
||||||
if (result !== null) return result;
|
if (result !== null) return result;
|
||||||
// Trackstream could not serve this track (returned null for a LIVE play).
|
// Trackstream could not serve this track (returned null for a LIVE play).
|
||||||
@@ -377,6 +396,11 @@ export class FluxerAudioBridge extends EventEmitter {
|
|||||||
if (stale()) return "stopped";
|
if (stale()) return "stopped";
|
||||||
// The encoded payload may be stale (expired googlevideo URL → HTTP 403)
|
// The encoded payload may be stale (expired googlevideo URL → HTTP 403)
|
||||||
// — resolve a fresh one once and retry before giving up.
|
// — resolve a fresh one once and retry before giving up.
|
||||||
|
if (isSlowNodeError(e)) {
|
||||||
|
tsBreakerFail();
|
||||||
|
logger.warn("[AudioBridge] Trackstream failed (" + e.message + ") — node is slow, skipping fresh-encoded retry.");
|
||||||
|
return null;
|
||||||
|
}
|
||||||
logger.warn("[AudioBridge] Trackstream failed (" + e.message + ") — trying one fresh-encoded retry...");
|
logger.warn("[AudioBridge] Trackstream failed (" + e.message + ") — trying one fresh-encoded retry...");
|
||||||
const freshEncoded = trackInfo.url && trackInfo.url.startsWith("http")
|
const freshEncoded = trackInfo.url && trackInfo.url.startsWith("http")
|
||||||
? await this._resolveUrlViaLavalink(trackInfo.url, trackInfo.guildId).catch(() => null)
|
? await this._resolveUrlViaLavalink(trackInfo.url, trackInfo.guildId).catch(() => null)
|
||||||
@@ -396,6 +420,13 @@ export class FluxerAudioBridge extends EventEmitter {
|
|||||||
|
|
||||||
if (stale()) return "stopped";
|
if (stale()) return "stopped";
|
||||||
|
|
||||||
|
if (/mpegts|m3u8|hls/i.test(String(direct.format || "")) || /\.m3u8(\?|$)/i.test(direct.url)) {
|
||||||
|
// HLS/MPEG-TS can never be positioned/passed through in-process, and a
|
||||||
|
// fresh loadtracks resolve returns the same HLS — skip the ~13s detour.
|
||||||
|
logger.player("[AudioBridge] trackstream returned HLS (" + (direct.format || "m3u8") + ") — not playable in-process.");
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
if (!/webm|opus/i.test(String(direct.format || ""))) {
|
if (!/webm|opus/i.test(String(direct.format || ""))) {
|
||||||
logger.player("[AudioBridge] trackstream format not opus/webm (" + (direct.format || "?") + "), refreshing encoded track once...");
|
logger.player("[AudioBridge] trackstream format not opus/webm (" + (direct.format || "?") + "), refreshing encoded track once...");
|
||||||
const freshEncoded = trackInfo.url && trackInfo.url.startsWith("http")
|
const freshEncoded = trackInfo.url && trackInfo.url.startsWith("http")
|
||||||
@@ -435,6 +466,7 @@ export class FluxerAudioBridge extends EventEmitter {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// WebM/Opus direct URL — play with zero re-encode.
|
// WebM/Opus direct URL — play with zero re-encode.
|
||||||
|
tsBreakerOk();
|
||||||
this._usedTrackstream = true;
|
this._usedTrackstream = true;
|
||||||
logger.player("[AudioBridge] Passthrough webm/opus via trackstream" +
|
logger.player("[AudioBridge] Passthrough webm/opus via trackstream" +
|
||||||
(seekMs > 0 ? " [positioned seek " + seekMs + "ms]" : " (zero-copy)") + ": " +
|
(seekMs > 0 ? " [positioned seek " + seekMs + "ms]" : " (zero-copy)") + ": " +
|
||||||
|
|||||||
Reference in new issue
Block a user