From 9366bbe95af3e6c6406b7db14f82f36cd1af1761 Mon Sep 17 00:00:00 2001 From: NoLogicAlan Date: Thu, 7 May 2026 23:24:45 +0300 Subject: [PATCH] test --- src/PlayerManager.mjs | 18 +++++++++++++++--- src/dashboard/Dashboard.mjs | 20 ++++++++++++++++++++ 2 files changed, 35 insertions(+), 3 deletions(-) diff --git a/src/PlayerManager.mjs b/src/PlayerManager.mjs index 7cfc261..74de716 100644 --- a/src/PlayerManager.mjs +++ b/src/PlayerManager.mjs @@ -186,9 +186,13 @@ 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 just the user ID - // (matching Stoat format where data = userId string) - emit(eventType, member.user.id); + // 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); // Also send global user update this.dashboard.userUpdate({ type: eventType, @@ -209,6 +213,14 @@ 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); // 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 a2ee77c..f1ff7c5 100644 --- a/src/dashboard/Dashboard.mjs +++ b/src/dashboard/Dashboard.mjs @@ -184,6 +184,26 @@ export class Dashboard { return { message: "Adding to queue" }; } + 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); + if (!player) return { error: "Player not found" }; + const authErr = this._authorizePlayerControl(user, player); + 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 }; + } + } + case "testConnection": { return { success: true }; }