mirror of
https://github.com/remix-bot/fluxer.git
synced 2026-11-24 06:01:44 -05:00
dashboard tests
This commit is contained in:
1 parent
9366bbe95a
commit
37c29ca6cd
3 files changed
+44
-30
No files matched your search
@@ -577,9 +577,39 @@ export class Remix {
|
|||||||
icon: guild.icon
|
icon: guild.icon
|
||||||
? `https://cdn.fluxer.app/icons/${guild.id}/${guild.icon}.webp`
|
? `https://cdn.fluxer.app/icons/${guild.id}/${guild.icon}.webp`
|
||||||
: null,
|
: null,
|
||||||
|
description: guild.description ?? null,
|
||||||
|
ownerId: guild.ownerId ?? null,
|
||||||
voiceChannels: guild.channels
|
voiceChannels: guild.channels
|
||||||
.filter(c => c.isVoiceBased?.() ?? false)
|
.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,
|
||||||
|
};
|
||||||
|
}),
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
+6
-15
@@ -186,13 +186,9 @@ export class PlayerManager {
|
|||||||
if (stateChannelId !== channelId) continue;
|
if (stateChannelId !== channelId) continue;
|
||||||
const member = guild.members?.get?.(state.userId ?? state.user_id);
|
const member = guild.members?.get?.(state.userId ?? state.user_id);
|
||||||
if (!member?.user || member.user?.bot) continue;
|
if (!member?.user || member.user?.bot) continue;
|
||||||
// Send per-player channel "join"/"leave" event with the full user
|
// Send per-player channel "join"/"leave" event with just the user ID
|
||||||
// object — matching Stoat format where data = Dashboard.convertUser(user).
|
// (matching Stoat format where data = userId string)
|
||||||
// The backend Player.setupEvents does:
|
emit(eventType, member.user.id);
|
||||||
// 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
|
// Also send global user update
|
||||||
this.dashboard.userUpdate({
|
this.dashboard.userUpdate({
|
||||||
type: eventType,
|
type: eventType,
|
||||||
@@ -213,14 +209,9 @@ export class PlayerManager {
|
|||||||
player.on("startplay", (song) => {
|
player.on("startplay", (song) => {
|
||||||
// Send the serialised video to the per-player channel
|
// Send the serialised video to the per-player channel
|
||||||
emit("startplay", Dashboard.convertVideo(song ?? player.queue?.current));
|
emit("startplay", Dashboard.convertVideo(song ?? player.queue?.current));
|
||||||
// The backend Player expects "streamStartPlay" with a timestamp so it
|
// Emit streamStartPlay with current timestamp so the backend can
|
||||||
// can compute elapsed time for the dashboard progress bar.
|
// calculate elapsed time accurately (matches Stoat behaviour)
|
||||||
// Player.mjs sets startedPlaying = Date.now() just before emitting
|
emit("streamStartPlay", Date.now());
|
||||||
// "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
|
// Also broadcast on global channel for full state update
|
||||||
this.dashboard.playerUpdate({ type: "startplay" }, player);
|
this.dashboard.playerUpdate({ type: "startplay" }, player);
|
||||||
});
|
});
|
||||||
|
|||||||
@@ -184,30 +184,23 @@ export class Dashboard {
|
|||||||
return { message: "Adding to queue" };
|
return { message: "Adding to queue" };
|
||||||
}
|
}
|
||||||
|
|
||||||
|
case "testConnection": {
|
||||||
|
return { success: true };
|
||||||
|
}
|
||||||
|
|
||||||
case "leave": {
|
case "leave": {
|
||||||
if (!user) return { error: "Invalid user" };
|
const player = this._getPlayerById(params.data.channel);
|
||||||
const channelId = params.data.channel;
|
|
||||||
if (!channelId) return { error: "Missing channel ID" };
|
|
||||||
const player = this._getPlayerById(channelId);
|
|
||||||
if (!player) return { error: "Player not found" };
|
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 };
|
if (authErr) return { error: authErr };
|
||||||
try {
|
try {
|
||||||
await player.leave();
|
await player.leave();
|
||||||
player.destroy();
|
|
||||||
const activeChannelId = player._channelId ?? channelId;
|
|
||||||
this.remix.players.playerMap.delete(activeChannelId);
|
|
||||||
return { message: "Left channel" };
|
return { message: "Left channel" };
|
||||||
} catch (e) {
|
} catch (e) {
|
||||||
logger.dashboard("[Dashboard] Leave error:", e.message);
|
return { error: "Failed to leave: " + e.message };
|
||||||
return { error: "Failed to leave channel: " + e.message };
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
case "testConnection": {
|
|
||||||
return { success: true };
|
|
||||||
}
|
|
||||||
|
|
||||||
default:
|
default:
|
||||||
return { error: "Unknown function: " + (params.func ?? "(none)") };
|
return { error: "Unknown function: " + (params.func ?? "(none)") };
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in new issue
Block a user