diff --git a/index.mjs b/index.mjs index 3e5a5c8..a547d86 100644 --- a/index.mjs +++ b/index.mjs @@ -577,9 +577,39 @@ export class Remix { icon: guild.icon ? `https://cdn.fluxer.app/icons/${guild.id}/${guild.icon}.webp` : null, + description: guild.description ?? null, + ownerId: guild.ownerId ?? null, voiceChannels: guild.channels .filter(c => c.isVoiceBased?.() ?? false) - .map(c => ({ name: c.name, id: c.id, icon: null })), + .map(c => { + // Build voice participants list for this channel + const voiceParticipants = []; + if (guild.voice_states) { + const vs = Array.isArray(guild.voice_states) ? guild.voice_states : + typeof guild.voice_states.values === "function" ? [...guild.voice_states.values()] : Object.values(guild.voice_states); + for (const state of vs) { + const scId = String(state?.channelId ?? state?.channel_id ?? "").replace(/\D/g, ""); + const chId = String(c.id ?? "").replace(/\D/g, ""); + if (scId === chId) { + const member = guild.members?.get?.(state?.userId ?? state?.user_id); + if (member?.user && !member.user.bot) { + voiceParticipants.push(Dashboard.convertUser(member.user)); + } + } + } + } + return { + name: c.name, + displayName: c.name, + id: c.id, + icon: null, + description: c.topic ?? null, + isVoice: true, + mature: c.nsfw ?? false, + serverId: guild.id, + voiceParticipants, + }; + }), }); } diff --git a/src/PlayerManager.mjs b/src/PlayerManager.mjs index 74de716..7f61d69 100644 --- a/src/PlayerManager.mjs +++ b/src/PlayerManager.mjs @@ -186,13 +186,9 @@ export class PlayerManager { if (stateChannelId !== channelId) continue; const member = guild.members?.get?.(state.userId ?? state.user_id); if (!member?.user || member.user?.bot) continue; - // Send per-player channel "join"/"leave" event with the full user - // object — matching Stoat format where data = Dashboard.convertUser(user). - // The backend Player.setupEvents does: - // join: this.users.push(data) — works with objects - // leave: findIndex(u => u === data.id) — needs data.id - const convertedUser = Dashboard.convertUser(member.user); - emit(eventType, convertedUser); + // Send per-player channel "join"/"leave" event with just the user ID + // (matching Stoat format where data = userId string) + emit(eventType, member.user.id); // Also send global user update this.dashboard.userUpdate({ type: eventType, @@ -213,14 +209,9 @@ export class PlayerManager { player.on("startplay", (song) => { // Send the serialised video to the per-player channel emit("startplay", Dashboard.convertVideo(song ?? player.queue?.current)); - // The backend Player expects "streamStartPlay" with a timestamp so it - // can compute elapsed time for the dashboard progress bar. - // Player.mjs sets startedPlaying = Date.now() just before emitting - // "startplay", so we use the same value (or fall back to Date.now()). - const startedAt = player.startedPlaying instanceof Date - ? player.startedPlaying.getTime() - : Number(player.startedPlaying) || Date.now(); - emit("streamStartPlay", startedAt); + // Emit streamStartPlay with current timestamp so the backend can + // calculate elapsed time accurately (matches Stoat behaviour) + emit("streamStartPlay", Date.now()); // Also broadcast on global channel for full state update this.dashboard.playerUpdate({ type: "startplay" }, player); }); diff --git a/src/dashboard/Dashboard.mjs b/src/dashboard/Dashboard.mjs index f1ff7c5..61d6525 100644 --- a/src/dashboard/Dashboard.mjs +++ b/src/dashboard/Dashboard.mjs @@ -184,30 +184,23 @@ export class Dashboard { return { message: "Adding to queue" }; } + case "testConnection": { + return { success: true }; + } + case "leave": { - if (!user) return { error: "Invalid user" }; - const channelId = params.data.channel; - if (!channelId) return { error: "Missing channel ID" }; - const player = this._getPlayerById(channelId); + const player = this._getPlayerById(params.data.channel); if (!player) return { error: "Player not found" }; - const authErr = this._authorizePlayerControl(user, player); + const authErr = await this._authorizeUserInGuild(user, player._guildId); if (authErr) return { error: authErr }; try { await player.leave(); - player.destroy(); - const activeChannelId = player._channelId ?? channelId; - this.remix.players.playerMap.delete(activeChannelId); return { message: "Left channel" }; } catch (e) { - logger.dashboard("[Dashboard] Leave error:", e.message); - return { error: "Failed to leave channel: " + e.message }; + return { error: "Failed to leave: " + e.message }; } } - case "testConnection": { - return { success: true }; - } - default: return { error: "Unknown function: " + (params.func ?? "(none)") }; }