mirror of
https://github.com/remix-bot/fluxer.git
synced 2026-11-24 06:01:44 -05:00
hotfix
This commit is contained in:
1 parent
0f40ee2ba8
commit
2c9a124d47
4 files changed
+200
-84
No files matched your search
+61
-21
@@ -1,12 +1,19 @@
|
||||
{
|
||||
"Comment": "Fluxer music bot configuration. IMPORTANT: Node.js >= 22.0.0 is required (moonlink.js v5 dependency). Run 'node --version' to verify.",
|
||||
"token": "your bot token",
|
||||
"fluxer.js": {
|
||||
"rest": {
|
||||
"Comment": "REST client options. 'timeout' is ms before a request to api.fluxer.app is aborted (default: 15000). Raise if you see DOMException AbortError in logs.",
|
||||
"timeout": 30000,
|
||||
"retries": 3
|
||||
}
|
||||
},
|
||||
"fluxer-api": {
|
||||
"Comment": "Configuration options for a fluxer REST client if self-hosting. See: https://docs.fluxer.app"
|
||||
},
|
||||
"prefix": "your desired prefix (such as %)",
|
||||
"presenceInterval": null,
|
||||
"presenceContents-Comment": "Each entry can be a plain string (e.g. 'Ping for Prefix') or an object. Objects support: text (required), emoji_name (unicode emoji or custom emoji name), emoji_id (snowflake ID for custom guild emojis only), activity ({ name, type, url? }). Activity types: 0=Playing, 1=Streaming, 2=Listening, 3=Watching, 5=Competing. For custom guild emojis, provide both emoji_name AND emoji_id. For unicode emojis, only emoji_name is needed.",
|
||||
"presenceContents": [
|
||||
{
|
||||
"text": "Ping for Prefix | Hosted by https://kyun.sh/",
|
||||
@@ -18,9 +25,13 @@
|
||||
"text": "Ping for Prefix",
|
||||
"emoji_name": "🎧",
|
||||
"activity": { "name": "music", "type": 2 }
|
||||
},
|
||||
{
|
||||
"text": "Ping for Prefix | By RedTech & NoLogicAlan",
|
||||
"emoji_name": "🎶",
|
||||
"activity": { "name": "RedTech & NoLogicAlan", "type": 2 }
|
||||
}
|
||||
],
|
||||
"presenceInterval": 30000,
|
||||
"spotify": {
|
||||
"clientId": "your spotify client id",
|
||||
"clientSecret": "your spotify client secret"
|
||||
@@ -29,12 +40,34 @@
|
||||
"host": "localhost",
|
||||
"port": 3000,
|
||||
"password": "youshallnotpass",
|
||||
"requestTimeout": 60000
|
||||
"requestTimeout": 60000,
|
||||
"Comment": "requestTimeout: ms before a NodeLink HTTP request is aborted. Default: 60000 (60s). Raise if you see 'NodeLink request timeout' errors."
|
||||
},
|
||||
"comment-radio": {
|
||||
"message": "If you have radio stations you'd like to connect, add them to the array below. Radio stations must be rendered like following:",
|
||||
"station": {
|
||||
"name": "zamrock",
|
||||
"detailedName": "ᘔᗩᗰᘔᗩᗰᖴOᖴᒪIᖴE",
|
||||
"thumbnail": "https://zamrock.net/wp-content/uploads/2024/06/Zamrock_rd_logo_0004-1.gif",
|
||||
"url": "url to stream from; this will be kept private",
|
||||
"description": "Genre: Zamrock, provided by [Zamrock.net](https://zamrock.net/)",
|
||||
"author": {
|
||||
"name": "Zamrock",
|
||||
"url": "https://zamrock.net"
|
||||
},
|
||||
"keyWords": ["radio", "zamrock", "psychedelic", "blues", "rock"]
|
||||
}
|
||||
},
|
||||
"radio": [],
|
||||
"cache": {
|
||||
"guilds": { "enabled": true, "max": 5000 },
|
||||
"members": { "enabled": true, "max": 10000 }
|
||||
"guilds": {
|
||||
"enabled": true,
|
||||
"max": 5000
|
||||
},
|
||||
"members": {
|
||||
"enabled": true,
|
||||
"max": 10000
|
||||
}
|
||||
},
|
||||
"helpCatalog": true,
|
||||
"helpPagination": true,
|
||||
@@ -48,7 +81,9 @@
|
||||
"webPort": 80,
|
||||
"dashboard": {
|
||||
"enabled": false,
|
||||
"redis": { "url": "redis://localhost:6379" }
|
||||
"redis": {
|
||||
"url": "redis://localhost:6379"
|
||||
}
|
||||
},
|
||||
"dashboardUrl": "The url the dashboard is accessible with.",
|
||||
"ssl": {
|
||||
@@ -57,40 +92,45 @@
|
||||
"useSSL": false,
|
||||
"httpPort": 80
|
||||
},
|
||||
"sessionSecret": "secret for the expressjs session middleware",
|
||||
"geniusToken": "Genius access token (optional, used for lyrics)",
|
||||
"sessionSecret": "secret for the expressjs session middleware; https://www.npmjs.com/package/express-session#user-content-secret",
|
||||
"geniusToken": "Genius access token (Used for lyrics); optional",
|
||||
"lastfm": {
|
||||
"Comment": "Last.fm integration: auto-scrobble songs, play loved/top/recent tracks. Register at https://www.last.fm/api/account/create",
|
||||
"apiKey": "your_lastfm_api_key",
|
||||
"apiSecret": "your_lastfm_api_secret",
|
||||
"scrobbleThreshold": 0.5,
|
||||
"scrobbleMinMs": 240000
|
||||
"scrobbleMinMs": 240000,
|
||||
"Comment2": "scrobbleThreshold: fraction of track duration before scrobbling (0.5 = 50%). scrobbleMinMs: minimum ms played before scrobble (default 4 min). Both must be met."
|
||||
},
|
||||
"owners": ["user id for owner-only commands"],
|
||||
"owners": ["user id for owner-only commands", "another user id"],
|
||||
"playerAFKTimeout": 60000,
|
||||
"Comment": "The above specifies the time in ms after which a player goes inactive; Optional.",
|
||||
"customStatsFooter": "Text shown in the footer of the %stats embed; optional.",
|
||||
"embedColor": "0xe9196c",
|
||||
"logging": {
|
||||
"Comment": "Control which log categories appear in the console. Set 'enabled' to false to silence everything except errors. Set any category to false to silence just that group.",
|
||||
"enabled": true,
|
||||
"player": true,
|
||||
"inactivity": false,
|
||||
"inactivity": true,
|
||||
"voiceState": true,
|
||||
"voice247": true,
|
||||
"voiceState": false,
|
||||
"mediaplayer": true,
|
||||
"mediaplayer": false,
|
||||
"commands": true,
|
||||
"guild": true,
|
||||
"recovery": false,
|
||||
"settings": false,
|
||||
"worker": false,
|
||||
"moonlink": false,
|
||||
"voice": false,
|
||||
"dashboard": false,
|
||||
"redis": false
|
||||
"settings": true,
|
||||
"worker": true,
|
||||
"moonlink": true,
|
||||
"dashboard": true,
|
||||
"redis": true
|
||||
},
|
||||
"timers": {
|
||||
"Comment": "All timing values in milliseconds (ms). 1000ms = 1 second, 60000ms = 1 minute.",
|
||||
"inactivityTimeout": 180000,
|
||||
"aloneCheckInterval": 30000,
|
||||
"aloneCheckInterval": 15000,
|
||||
"aloneCheckDebounce": 500,
|
||||
"rejoin247Delay": 2000,
|
||||
"leave247RejoinDelay": 3000,
|
||||
"rejoin247Delay": 3000,
|
||||
"leave247RejoinDelay": 5000,
|
||||
"playerUpdateInterval": 5000,
|
||||
"searchSessionTimeout": 30000,
|
||||
"playerSessionTimeout": 300000,
|
||||
|
||||
+99
-38
@@ -2,7 +2,7 @@ import { Events, GatewayOpcodes } from "@fluxerjs/core";
|
||||
import { getVoiceManager } from "@fluxerjs/voice";
|
||||
import { logger } from "./constants/Logger.mjs";
|
||||
import { ServerSettings } from "./Settings.mjs";
|
||||
import { get247ChannelMode } from "./constants/Helpers247.mjs";
|
||||
import { get247ChannelMode, remove247ChannelMode } from "./constants/Helpers247.mjs";
|
||||
import mysql from "mysql2";
|
||||
|
||||
/**
|
||||
@@ -23,7 +23,7 @@ export class GatewayHandler {
|
||||
const timers = remix.config.timers ?? {};
|
||||
this.T = {
|
||||
aloneCheckDebounce: timers.aloneCheckDebounce ?? 500,
|
||||
rejoin247Delay: timers.rejoin247Delay ?? 2_000,
|
||||
rejoin247Delay: timers.rejoin247Delay ?? 3_000,
|
||||
};
|
||||
|
||||
// ── Presence rotation config ─────────────────────────────────────────────
|
||||
@@ -57,7 +57,7 @@ export class GatewayHandler {
|
||||
/** @type {Map<string, {guild, timer}>} guildId → deferred cleanup data */
|
||||
this._deferredGuildDeletes = new Map();
|
||||
/** @type {number} How long to defer GuildDelete processing during startup (ms) */
|
||||
this._startupDeleteGraceMs = 10_000;
|
||||
this._startupDeleteGraceMs = 15_000;
|
||||
/** @type {boolean} Whether we're still in the startup grace period */
|
||||
this._inStartupGrace = true;
|
||||
}
|
||||
@@ -587,7 +587,10 @@ export class GatewayHandler {
|
||||
if (deferred) {
|
||||
clearTimeout(deferred.timer);
|
||||
this._deferredGuildDeletes.delete(guildId);
|
||||
// Silently cancel — no need to log every guild that comes back during startup
|
||||
logger.guild(
|
||||
`[GuildDelete] Cancelled deferred cleanup for server ${guildId} — ` +
|
||||
`guild came back (GuildCreate received during grace period).`
|
||||
);
|
||||
}
|
||||
|
||||
// Part 1: Voice state population
|
||||
@@ -716,12 +719,18 @@ export class GatewayHandler {
|
||||
// come back via GUILD_CREATE moments later. Defer cleanup during
|
||||
// the startup grace period; if GuildCreate arrives first, cancel.
|
||||
if (this._inStartupGrace) {
|
||||
// Silently buffer — log one summary after all deferrals are collected
|
||||
logger.guild(
|
||||
`[GuildDelete] Deferring cleanup for server ${guildId} ` +
|
||||
`(startup grace — will confirm after ${this._startupDeleteGraceMs / 1000}s).`
|
||||
);
|
||||
// Cancel any existing deferred timer for this guild
|
||||
const existing = this._deferredGuildDeletes.get(guildId);
|
||||
if (existing) clearTimeout(existing.timer);
|
||||
|
||||
const timer = setTimeout(() => {
|
||||
this._deferredGuildDeletes.delete(guildId);
|
||||
// Grace period expired without GuildCreate — this guild is really gone
|
||||
logger.guild(`[GuildDelete] Confirmed removal from server ${guildId} — cleaning up.`);
|
||||
this._processGuildDelete(guildId);
|
||||
}, this._startupDeleteGraceMs);
|
||||
|
||||
@@ -1121,26 +1130,25 @@ export class GatewayHandler {
|
||||
|
||||
// End the startup grace period after the configured delay.
|
||||
// Any deferred GuildDelete events that weren't cancelled by a GuildCreate
|
||||
// are processed in one batch here.
|
||||
// will be processed at this point.
|
||||
setTimeout(() => {
|
||||
this._inStartupGrace = false;
|
||||
const pending = this._deferredGuildDeletes;
|
||||
if (pending.size > 0) {
|
||||
const ids = [...pending.keys()];
|
||||
// Clear all individual deferred timers — we'll process them all at once
|
||||
for (const [, data] of pending) {
|
||||
clearTimeout(data.timer);
|
||||
}
|
||||
pending.clear();
|
||||
this._processGuildDelete(ids);
|
||||
const pending = this._deferredGuildDeletes.size;
|
||||
if (pending > 0) {
|
||||
logger.guild(
|
||||
`[GuildDelete] Startup grace period ended. ` +
|
||||
`${pending} deferred deletion(s) will be processed by their timers.`
|
||||
);
|
||||
} else {
|
||||
logger.guild(`[GuildDelete] Startup grace period ended. No deferred deletions.`);
|
||||
}
|
||||
}, this._startupDeleteGraceMs);
|
||||
|
||||
// ── Boot 24/7 auto-rejoin ────────────────────────────────────────────────
|
||||
// After a reboot/crash, automatically rejoin all voice channels that have
|
||||
// 24/7 mode enabled (stay_247 setting with mode "on" or "auto").
|
||||
// Minimal delay — Moonlink is already ready by onReady time.
|
||||
setTimeout(() => this.rejoin247Channels(), 2_000);
|
||||
// Delayed slightly to let the gateway settle and Moonlink initialise.
|
||||
setTimeout(() => this.rejoin247Channels(), 5_000);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -1208,37 +1216,97 @@ export class GatewayHandler {
|
||||
await remix._spawnPlayer(guildId, channelId);
|
||||
logger.voice247(`[BootRecovery] Successfully rejoined 24/7 channel ${channelId}`);
|
||||
} catch (e) {
|
||||
const is401 = e?.message?.includes("401") || e?.message?.includes("Unauthorized");
|
||||
if (is401) {
|
||||
logger.warn(
|
||||
`[BootRecovery] 401 error rejoining 24/7 channel ${channelId} (guild ${guildId}) — ` +
|
||||
`auto-removing 24/7 state for this channel`
|
||||
);
|
||||
this._remove247ForChannel(guildId, channelId);
|
||||
} else {
|
||||
logger.warn(`[BootRecovery] Failed to rejoin 24/7 channel ${channelId}: ${e.message}`);
|
||||
}
|
||||
}
|
||||
}, delay);
|
||||
}
|
||||
}
|
||||
|
||||
// ── 401 auto-cleanup for boot rejoin ──────────────────────────────────────
|
||||
|
||||
/**
|
||||
* Remove the 24/7 state for a channel when a 401 error occurs during
|
||||
* boot rejoin. This prevents the bot from repeatedly trying to rejoin
|
||||
* a channel that it no longer has access to (e.g. bot was removed from
|
||||
* the server, channel was deleted, or permissions were revoked).
|
||||
*
|
||||
* @param {string} guildId
|
||||
* @param {string} channelId
|
||||
*/
|
||||
_remove247ForChannel(guildId, channelId) {
|
||||
const { remix } = this;
|
||||
const settings = remix.settingsMgr;
|
||||
if (!settings?.guilds) return;
|
||||
|
||||
const serverSettings = settings.guilds.get(guildId);
|
||||
if (!serverSettings) return;
|
||||
|
||||
const cleanChannelId = String(channelId).replace(/\D/g, "");
|
||||
|
||||
// Get the current stay_247 channels
|
||||
const raw = serverSettings.get("stay_247");
|
||||
if (!raw || raw === "none") return;
|
||||
|
||||
const rawArr = Array.isArray(raw) ? raw : [raw];
|
||||
const currentSet = new Set(
|
||||
rawArr.map(id => String(id).replace(/\D/g, "")).filter(id => id.length >= 15)
|
||||
);
|
||||
|
||||
// Remove the channel from the set
|
||||
if (!currentSet.has(cleanChannelId)) return; // already removed
|
||||
currentSet.delete(cleanChannelId);
|
||||
|
||||
// Update stay_247 setting
|
||||
if (currentSet.size === 0) {
|
||||
serverSettings.set("stay_247", "none");
|
||||
} else {
|
||||
serverSettings.set("stay_247", [...currentSet]);
|
||||
}
|
||||
|
||||
// Remove the per-channel mode
|
||||
remove247ChannelMode(serverSettings, cleanChannelId, currentSet);
|
||||
|
||||
// Remove the playerMap entry if present
|
||||
const existingPlayer = remix.players.playerMap.get(cleanChannelId);
|
||||
if (existingPlayer) {
|
||||
remix.players.playerMap.delete(cleanChannelId);
|
||||
try { existingPlayer.leave().catch(() => {}); } catch (_) {}
|
||||
try { existingPlayer.destroy(); } catch (_) {}
|
||||
}
|
||||
|
||||
logger.voice247(
|
||||
`[BootRecovery] Auto-removed 24/7 for channel ${cleanChannelId} ` +
|
||||
`in guild ${guildId} due to 401 error`
|
||||
);
|
||||
}
|
||||
|
||||
// ── GuildDelete cleanup (extracted for deferred processing) ────────────────
|
||||
|
||||
/**
|
||||
* Perform the actual cleanup for guild(s) that the bot was removed from.
|
||||
* Accepts a single guildId (string) or an array of guildIds for batch
|
||||
* processing (used when the startup grace period expires with multiple
|
||||
* deferred deletes). Logs ONE summary line with all cleaned guild IDs.
|
||||
* @param {string|string[]} guildIds
|
||||
* Perform the actual cleanup for a guild that the bot was removed from.
|
||||
* Extracted from the GuildDelete handler so it can be called after the
|
||||
* startup grace period expires.
|
||||
* @param {string} guildId
|
||||
*/
|
||||
_processGuildDelete(guildIds) {
|
||||
const ids = Array.isArray(guildIds) ? guildIds : [guildIds];
|
||||
_processGuildDelete(guildId) {
|
||||
const { remix } = this;
|
||||
const cleanedIds = [];
|
||||
let totalDestroyedPlayers = 0;
|
||||
|
||||
for (const guildId of ids) {
|
||||
const cleanGuildId = String(guildId).replace(/\D/g, "");
|
||||
let destroyedPlayers = 0;
|
||||
|
||||
for (const [channelId, player] of remix.players.playerMap) {
|
||||
if (String(player._guildId ?? "").replace(/\D/g, "") === cleanGuildId) {
|
||||
remix.players.playerMap.delete(channelId);
|
||||
try { player.leave().catch(() => {}); } catch (_) {}
|
||||
try { player.destroy(); } catch (_) {}
|
||||
destroyedPlayers++;
|
||||
logger.guild(`[GuildDelete] Destroyed player for channel ${channelId}.`);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1256,13 +1324,6 @@ export class GatewayHandler {
|
||||
remix.settingsMgr.removeServer(guildId);
|
||||
remix._announcementChannelCache.delete(guildId);
|
||||
|
||||
cleanedIds.push(guildId);
|
||||
totalDestroyedPlayers += destroyedPlayers;
|
||||
}
|
||||
|
||||
if (cleanedIds.length > 0) {
|
||||
const extra = totalDestroyedPlayers > 0 ? ` (${totalDestroyedPlayers} player(s) destroyed)` : "";
|
||||
logger.guild(`[GuildDelete] Cleaned up ${cleanedIds.length} server(s): ${cleanedIds.join(", ")}${extra}`);
|
||||
}
|
||||
logger.guild(`[GuildDelete] Cleanup complete for server ${guildId}.`);
|
||||
}
|
||||
}
|
||||
+6
-8
@@ -1003,7 +1003,7 @@ export default class Player extends EventEmitter {
|
||||
if (this._destroyed) return;
|
||||
|
||||
if (this._isJoining) {
|
||||
logger.mediaplayer(`[Player] Busy joining. Ignoring: ${channelId}`);
|
||||
logger.player(`[Player] Busy joining. Ignoring: ${channelId}`);
|
||||
return;
|
||||
}
|
||||
if (this.connection && this._channelId === channelId) {
|
||||
@@ -1078,10 +1078,8 @@ export default class Player extends EventEmitter {
|
||||
try { this._revoice.deleteConnection(this._channelId); } catch (_) {}
|
||||
}
|
||||
|
||||
// Wait to give the Fluxer gateway time to process the voice state
|
||||
// leave before we join a new channel. FluxerRevoice adds its own
|
||||
// _globalJoinDelay before the actual join, so 500ms here is enough.
|
||||
await Utils.sleep(500);
|
||||
// FluxerRevoice.join() already adds a _globalJoinDelay (500ms) before
|
||||
// the actual join, so no additional sleep is needed here.
|
||||
this.connection = null;
|
||||
this._mediaPlayer = null;
|
||||
}
|
||||
@@ -1256,7 +1254,7 @@ export default class Player extends EventEmitter {
|
||||
const playerReady = await this._ensureMediaPlayer();
|
||||
if (!playerReady) {
|
||||
logger.mediaplayer("[Player] First MediaPlayer attempt failed, retrying after delay...");
|
||||
await Utils.sleep(1500);
|
||||
await Utils.sleep(500);
|
||||
if (this._destroyed || this.leaving) throw new Error("Player destroyed during MediaPlayer retry");
|
||||
const roomAlive = this.connection?.room?.isConnected ?? false;
|
||||
if (!roomAlive) {
|
||||
@@ -1280,7 +1278,7 @@ export default class Player extends EventEmitter {
|
||||
if (this.queue.isEmpty() && !this.queue.getCurrent()) {
|
||||
this._startInactivityTimer();
|
||||
}
|
||||
}, 3000);
|
||||
}, 1500);
|
||||
}
|
||||
|
||||
} catch (e) {
|
||||
@@ -1289,7 +1287,7 @@ export default class Player extends EventEmitter {
|
||||
|
||||
if (e.message?.includes("401") || e.message?.includes("Unauthorized")) {
|
||||
// Track 401 errors for logging purposes
|
||||
logger.warn(`[Player] Join failed with 401 Unauthorized for guild ${this._guildId ?? this._resolveGuildId() ?? 'unknown'}`);
|
||||
logger.warn(`[Player] Join failed with 401 Unauthorized for guild ${this._guildId}`);
|
||||
}
|
||||
|
||||
if (this.connection) {
|
||||
|
||||
@@ -27,14 +27,29 @@
|
||||
*/
|
||||
|
||||
import { EventEmitter } from "node:events";
|
||||
import { Room, RoomEvent, ConnectionState, setLogLevel } from "@livekit/rtc-node";
|
||||
import { Room, RoomEvent, ConnectionState } from "@livekit/rtc-node";
|
||||
import { joinVoiceChannel, getVoiceManager } from "@fluxerjs/voice";
|
||||
import { logger } from "./Logger.mjs";
|
||||
|
||||
// Suppress LiveKit SDK's verbose pino/JSON logs (lk-rtc, [voice LiveKitRtc]).
|
||||
// Only show warnings and errors from the SDK — the "Connect callback received"
|
||||
// JSON lines and "connected to room" messages are noise for production.
|
||||
try { setLogLevel("warn"); } catch (_) {}
|
||||
// ── Suppress verbose LiveKit SDK logging ──────────────────────────────────
|
||||
// @livekit/rtc-node removed the `setLogLevel` export in newer versions,
|
||||
// causing a SyntaxError crash when importing it. The SDK uses console.debug
|
||||
// for verbose trace-level logs. Monkey-patch console.debug to filter out
|
||||
// noisy LiveKit messages — no env vars needed.
|
||||
const _origConsoleDebug = console.debug;
|
||||
console.debug = function(...args) {
|
||||
const msg = typeof args[0] === 'string' ? args[0] : (args[0]?.toString?.() ?? '');
|
||||
if (typeof msg === 'string' && (
|
||||
msg.includes('[LiveKit') ||
|
||||
msg.includes('livekit') ||
|
||||
msg.includes('RTCKit') ||
|
||||
msg.includes('SignalClient') ||
|
||||
msg.includes('Room connect') ||
|
||||
msg.includes('ICE') ||
|
||||
msg.includes('DTLS')
|
||||
)) return;
|
||||
return _origConsoleDebug.apply(console, args);
|
||||
};
|
||||
|
||||
// ConnectionState enum values for reference:
|
||||
// ConnectionState.CONN_DISCONNECTED = 0
|
||||
@@ -475,7 +490,7 @@ export class FluxerRevoice extends EventEmitter {
|
||||
const elapsed = Date.now() - lastJoin;
|
||||
if (elapsed < this._guildMinJoinInterval) {
|
||||
const extraWait = this._guildMinJoinInterval - elapsed;
|
||||
logger.mediaplayer(
|
||||
logger.player(
|
||||
`[FluxerRevoice] Guild ${guildId} was joined ${elapsed}ms ago — ` +
|
||||
`waiting additional ${extraWait}ms to avoid 401 race`
|
||||
);
|
||||
@@ -492,7 +507,7 @@ export class FluxerRevoice extends EventEmitter {
|
||||
`aborting join for channel ${channelId} to avoid guaranteed failure. `
|
||||
);
|
||||
}
|
||||
logger.mediaplayer(
|
||||
logger.player(
|
||||
`[FluxerRevoice] Guild ${guildId} has 401 cooldown — ` +
|
||||
`waiting ${Math.round(cooldownRemaining / 1000)}s before attempting join`
|
||||
);
|
||||
@@ -517,16 +532,18 @@ export class FluxerRevoice extends EventEmitter {
|
||||
// up fully and rejoin instead of returning a dead connection that will
|
||||
// fail with "LiveKit disconnected (connectionState: 0)".
|
||||
if (existing && !existing._destroyed && existing.room && existing.room.isConnected) {
|
||||
logger.mediaplayer(`[FluxerRevoice] Already connected to ${channelId}, returning existing connection`);
|
||||
logger.player(`[FluxerRevoice] Already connected to ${channelId}, returning existing connection`);
|
||||
return existing;
|
||||
}
|
||||
logger.mediaplayer(
|
||||
`[FluxerRevoice] Stale connection for ${channelId} — cleaning up and rejoining`
|
||||
logger.player(
|
||||
`[FluxerRevoice] Stale connection for ${channelId} ` +
|
||||
`(isConnected: ${existing?.room?.isConnected ?? false}, ` +
|
||||
`destroyed: ${existing?._destroyed ?? true}) — cleaning up and rejoining`
|
||||
);
|
||||
await this._destroyStaleConnection(channelId, existing);
|
||||
}
|
||||
|
||||
logger.mediaplayer(`[FluxerRevoice] Joining channel ${channelId} via Fluxer gateway...`);
|
||||
logger.player(`[FluxerRevoice] Joining channel ${channelId} via Fluxer gateway...`);
|
||||
|
||||
// Fetch the channel object from the client cache (or REST)
|
||||
let channel = this.client.channels?.get?.(channelId);
|
||||
@@ -571,7 +588,7 @@ export class FluxerRevoice extends EventEmitter {
|
||||
throw new Error(`Fluxer voice join returned null for ${channelId}`);
|
||||
}
|
||||
|
||||
logger.mediaplayer(`[FluxerRevoice] Gateway join successful, extracting LiveKit room...`);
|
||||
logger.player(`[FluxerRevoice] Gateway join successful, extracting LiveKit room...`);
|
||||
|
||||
// The @fluxerjs/voice connection wraps a LiveKit Room.
|
||||
// Extract it so we can use it with revoice.js's MediaPlayer.
|
||||
@@ -580,7 +597,7 @@ export class FluxerRevoice extends EventEmitter {
|
||||
// Try to get the LiveKit Room from the native connection
|
||||
if (nativeConnection.room) {
|
||||
room = nativeConnection.room;
|
||||
logger.mediaplayer(`[FluxerRevoice] Got LiveKit room from native connection (isConnected: ${room.isConnected}, connectionState: ${stateLabel(room.connectionState)})`);
|
||||
logger.player(`[FluxerRevoice] Got LiveKit room from native connection (isConnected: ${room.isConnected}, connectionState: ${stateLabel(room.connectionState)})`);
|
||||
}
|
||||
|
||||
// (non-LiveKit) which we don't support for music playback.
|
||||
@@ -645,7 +662,7 @@ export class FluxerRevoice extends EventEmitter {
|
||||
throw new Error(`LiveKit room in disconnected state: ${stateLabel(finalCS)}`);
|
||||
}
|
||||
|
||||
logger.mediaplayer(`[FluxerRevoice] LiveKit room ready (isConnected: ${finalConnected}, connectionState: ${stateLabel(finalCS)})`);
|
||||
logger.player(`[FluxerRevoice] LiveKit room ready (isConnected: ${finalConnected}, connectionState: ${stateLabel(finalCS)})`);
|
||||
|
||||
// Record the successful join time for this guild so future joins
|
||||
// can enforce the minimum interval and avoid 401 races.
|
||||
@@ -672,7 +689,7 @@ export class FluxerRevoice extends EventEmitter {
|
||||
room.on(RoomEvent.Disconnected, (reason) => {
|
||||
const isIntentional = this._intentionalDisconnects.has(String(channelId));
|
||||
const reasonLabel = isIntentional ? "intentional" : (reason ?? "unexpected");
|
||||
logger.mediaplayer(`[FluxerRevoice] Room disconnected: ${reasonLabel}${isIntentional ? " (bot-initiated, recovery suppressed)" : ""}`);
|
||||
logger.player(`[FluxerRevoice] Room disconnected: ${reasonLabel}${isIntentional ? " (bot-initiated, recovery suppressed)" : ""}`);
|
||||
this._intentionalDisconnects.delete(String(channelId));
|
||||
connection._connected = false;
|
||||
connection._destroyed = true;
|
||||
@@ -697,11 +714,11 @@ export class FluxerRevoice extends EventEmitter {
|
||||
});
|
||||
|
||||
room.on(RoomEvent.Reconnecting, () => {
|
||||
logger.mediaplayer("[FluxerRevoice] Room reconnecting...");
|
||||
logger.player("[FluxerRevoice] Room reconnecting...");
|
||||
});
|
||||
|
||||
room.on(RoomEvent.Reconnected, () => {
|
||||
logger.mediaplayer("[FluxerRevoice] Room reconnected");
|
||||
logger.player("[FluxerRevoice] Room reconnected");
|
||||
connection._connected = true;
|
||||
});
|
||||
|
||||
|
||||
Reference in new issue
Block a user