mirror of
https://github.com/remix-bot/fluxer.git
synced 2026-11-23 21:52:45 -05:00
better log for LiveKit
This commit is contained in:
1 parent
ee0e353f0d
commit
0f40ee2ba8
3 files changed
+70
-51
No files matched your search
@@ -27,10 +27,15 @@
|
||||
*/
|
||||
|
||||
import { EventEmitter } from "node:events";
|
||||
import { Room, RoomEvent, ConnectionState } from "@livekit/rtc-node";
|
||||
import { Room, RoomEvent, ConnectionState, setLogLevel } 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 (_) {}
|
||||
|
||||
// ConnectionState enum values for reference:
|
||||
// ConnectionState.CONN_DISCONNECTED = 0
|
||||
// ConnectionState.CONN_CONNECTED = 1
|
||||
@@ -470,7 +475,7 @@ export class FluxerRevoice extends EventEmitter {
|
||||
const elapsed = Date.now() - lastJoin;
|
||||
if (elapsed < this._guildMinJoinInterval) {
|
||||
const extraWait = this._guildMinJoinInterval - elapsed;
|
||||
logger.player(
|
||||
logger.mediaplayer(
|
||||
`[FluxerRevoice] Guild ${guildId} was joined ${elapsed}ms ago — ` +
|
||||
`waiting additional ${extraWait}ms to avoid 401 race`
|
||||
);
|
||||
@@ -487,7 +492,7 @@ export class FluxerRevoice extends EventEmitter {
|
||||
`aborting join for channel ${channelId} to avoid guaranteed failure. `
|
||||
);
|
||||
}
|
||||
logger.player(
|
||||
logger.mediaplayer(
|
||||
`[FluxerRevoice] Guild ${guildId} has 401 cooldown — ` +
|
||||
`waiting ${Math.round(cooldownRemaining / 1000)}s before attempting join`
|
||||
);
|
||||
@@ -512,18 +517,16 @@ 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.player(`[FluxerRevoice] Already connected to ${channelId}, returning existing connection`);
|
||||
logger.mediaplayer(`[FluxerRevoice] Already connected to ${channelId}, returning existing connection`);
|
||||
return existing;
|
||||
}
|
||||
logger.player(
|
||||
`[FluxerRevoice] Stale connection for ${channelId} ` +
|
||||
`(isConnected: ${existing?.room?.isConnected ?? false}, ` +
|
||||
`destroyed: ${existing?._destroyed ?? true}) — cleaning up and rejoining`
|
||||
logger.mediaplayer(
|
||||
`[FluxerRevoice] Stale connection for ${channelId} — cleaning up and rejoining`
|
||||
);
|
||||
await this._destroyStaleConnection(channelId, existing);
|
||||
}
|
||||
|
||||
logger.player(`[FluxerRevoice] Joining channel ${channelId} via Fluxer gateway...`);
|
||||
logger.mediaplayer(`[FluxerRevoice] Joining channel ${channelId} via Fluxer gateway...`);
|
||||
|
||||
// Fetch the channel object from the client cache (or REST)
|
||||
let channel = this.client.channels?.get?.(channelId);
|
||||
@@ -568,7 +571,7 @@ export class FluxerRevoice extends EventEmitter {
|
||||
throw new Error(`Fluxer voice join returned null for ${channelId}`);
|
||||
}
|
||||
|
||||
logger.player(`[FluxerRevoice] Gateway join successful, extracting LiveKit room...`);
|
||||
logger.mediaplayer(`[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.
|
||||
@@ -577,7 +580,7 @@ export class FluxerRevoice extends EventEmitter {
|
||||
// Try to get the LiveKit Room from the native connection
|
||||
if (nativeConnection.room) {
|
||||
room = nativeConnection.room;
|
||||
logger.player(`[FluxerRevoice] Got LiveKit room from native connection (isConnected: ${room.isConnected}, connectionState: ${stateLabel(room.connectionState)})`);
|
||||
logger.mediaplayer(`[FluxerRevoice] Got LiveKit room from native connection (isConnected: ${room.isConnected}, connectionState: ${stateLabel(room.connectionState)})`);
|
||||
}
|
||||
|
||||
// (non-LiveKit) which we don't support for music playback.
|
||||
@@ -642,7 +645,7 @@ export class FluxerRevoice extends EventEmitter {
|
||||
throw new Error(`LiveKit room in disconnected state: ${stateLabel(finalCS)}`);
|
||||
}
|
||||
|
||||
logger.player(`[FluxerRevoice] LiveKit room ready (isConnected: ${finalConnected}, connectionState: ${stateLabel(finalCS)})`);
|
||||
logger.mediaplayer(`[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.
|
||||
@@ -669,7 +672,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.player(`[FluxerRevoice] Room disconnected: ${reasonLabel}${isIntentional ? " (bot-initiated, recovery suppressed)" : ""}`);
|
||||
logger.mediaplayer(`[FluxerRevoice] Room disconnected: ${reasonLabel}${isIntentional ? " (bot-initiated, recovery suppressed)" : ""}`);
|
||||
this._intentionalDisconnects.delete(String(channelId));
|
||||
connection._connected = false;
|
||||
connection._destroyed = true;
|
||||
@@ -694,11 +697,11 @@ export class FluxerRevoice extends EventEmitter {
|
||||
});
|
||||
|
||||
room.on(RoomEvent.Reconnecting, () => {
|
||||
logger.player("[FluxerRevoice] Room reconnecting...");
|
||||
logger.mediaplayer("[FluxerRevoice] Room reconnecting...");
|
||||
});
|
||||
|
||||
room.on(RoomEvent.Reconnected, () => {
|
||||
logger.player("[FluxerRevoice] Room reconnected");
|
||||
logger.mediaplayer("[FluxerRevoice] Room reconnected");
|
||||
connection._connected = true;
|
||||
});
|
||||
|
||||
|
||||
Reference in new issue
Block a user