feat(channels): render TeamSpeak spacers across skins

This commit is contained in:
illusia committed 2026-10-24 18:16:01 +08:00
1 parent 4bff2133b6
commit b9fccb8757
21 files changed
+240 -17

No files matched your search

+14
View File
@@ -9,6 +9,20 @@ const directory = (): TSDirectorySnapshot => ({
clients: [{ id: 2, channelID: 1n, nickname: "Member", uid: "uid-2", type: 0, serverGroups: [], away: true, inputMuted: true }],
});
test("permanent channel flags survive the gateway wire, without guessing omitted flags", () => {
const source = directory();
source.channels[0] = { ...source.channels[0], name: "[cspacer0]Section", isPermanent: true };
source.channels[1] = { ...source.channels[1], isPermanent: false };
const channels = mapChannelTree(source);
const message = parseServerMessage(JSON.parse(JSON.stringify({ type: "channelList", channels })));
assert.ok(message?.type === "channelList");
assert.equal(message.channels[0].name, "[cspacer0]Section");
assert.equal(message.channels[0].isPermanent, true);
assert.equal(message.channels[1].isPermanent, false);
assert.equal(Object.hasOwn(mapChannelTree(directory())[0], "isPermanent"), false);
assert.equal(parseServerMessage({ type: "channelList", channels: [{ ...channels[0], isPermanent: "true" }] }), null);
});
test("self restoration uses the connected channel before a snapshot or requested channel", () => {
const source = directory();
const result = normalizeDirectorySnapshot(source, 2, 18446744073709551615n, "Self", "Lobby");
+1
View File
@@ -12,6 +12,7 @@ export function mapChannelTree(snapshot: TSDirectorySnapshot, avatarCache = new
? { maxClients: channel.maxClients, maxClientsLimited: channel.maxClientsLimited }
: {}),
...(typeof channel.passwordProtected === "boolean" ? { passwordProtected: channel.passwordProtected } : {}),
...(typeof channel.isPermanent === "boolean" ? { isPermanent: channel.isPermanent } : {}),
members: snapshot.clients
.filter((client) => client.channelID === channel.id)
.map((client) => {
+5 -3
View File
@@ -10,7 +10,7 @@ const identity = generateIdentitySync(8);
const uid = "AAAAAAAAAAAAAAAAAAAAAAAAAAA=";
function channel(id = 1): Channel {
return { id: asChannelID(BigInt(id)), parentID: asChannelID(0n), order: asChannelID(0n), name: "Lobby",
description: "", hasPassword: true, maxClients: 12, isMaxClientsUnlimited: false } as Channel;
description: "", hasPassword: true, isPermanent: true, maxClients: 12, isMaxClientsUnlimited: false } as Channel;
}
function member(id = 1): ClientEntry {
return { id: asClientID(id), nickname: `Member ${id}`, uid: asUID(uid), channelID: asChannelID(1n), type: 0,
@@ -43,7 +43,7 @@ function fixture() {
test("ordinary-client directories and avatar metadata use the live view without list permissions", async () => {
const { sdk, native } = fixture();
assert.deepEqual(await sdk.listDirectoryChannels(), [{ id: 1n, parentID: 0n, order: 0n, name: "Lobby", description: "",
passwordProtected: true, maxClients: 12, maxClientsLimited: true }]);
passwordProtected: true, isPermanent: true, maxClients: 12, maxClientsLimited: true }]);
assert.deepEqual(await sdk.listDirectoryClients(), [{ id: 1, nickname: "Member 1", uid, channelID: 1n, type: 0,
serverGroups: [], away: true, awayMessage: "Away", inputMuted: true, outputMuted: false, channelCommander: true }]);
assert.deepEqual(await sdk.getClientAvatarMetadata(1), { uid, cacheKey: "avatar-hash", path: `/${avatarFileName(uid)}` });
@@ -62,11 +62,13 @@ test("live-view snapshots include channel edits and remove clients that went out
assert.equal(snapshots.length, 1, "an unchanged revision does not duplicate the directory");
assert.equal(snapshots[0]?.complete, true);
native.view.clients.clear();
native.view.channels.set(asChannelID(1n), { ...channel(), name: "Renamed", hasPassword: false, maxClients: 20 });
native.view.channels.set(asChannelID(1n), { ...channel(), name: "Renamed", hasPassword: false, isPermanent: false, maxClients: 20 });
native.view.revision++;
native.emit("viewChanged");
assert.equal(snapshots.at(-1)?.channels[0]?.name, "Renamed");
assert.equal(snapshots.at(-1)?.channels[0]?.passwordProtected, false);
assert.equal(snapshots[0]?.channels[0]?.isPermanent, true);
assert.equal(snapshots.at(-1)?.channels[0]?.isPermanent, false);
assert.equal(snapshots.at(-1)?.channels[0]?.maxClients, 20);
assert.deepEqual(snapshots.at(-1)?.clients, []);
assert.equal(snapshots[0]?.clients.length, 1, "earlier snapshots stay independent");
+2
View File
@@ -48,6 +48,7 @@ export interface DirectoryChannelInfo {
name: string;
description: string;
passwordProtected?: boolean;
isPermanent?: boolean;
maxClients?: number;
maxClientsLimited?: boolean;
}
@@ -315,6 +316,7 @@ function toDirectoryChannel(channel: Channel): DirectoryChannelInfo {
name: channel.name,
description: channel.description,
passwordProtected: channel.hasPassword,
...(typeof channel.isPermanent === "boolean" ? { isPermanent: channel.isPermanent } : {}),
...(Number.isInteger(channel.maxClients) && channel.maxClients >= 0 && channel.maxClients <= 65_535
&& typeof channel.isMaxClientsUnlimited === "boolean"
? { maxClients: channel.maxClients, maxClientsLimited: !channel.isMaxClientsUnlimited }
+25
View File
@@ -0,0 +1,25 @@
import type { ChannelInfo } from "./voice-models.js";
export interface ChannelSpacer {
text: string;
alignment: "left" | "center" | "right" | "repeat";
style: "text" | "solid" | "dashed" | "dotted" | "dash-dot" | "dash-dot-dot";
}
const LINE_STYLES: Readonly<Record<string, ChannelSpacer["style"]>> = {
"___": "solid", "---": "dashed", "...": "dotted", "-.-": "dash-dot", "-..": "dash-dot-dot",
};
/** Spacers are a presentation convention for permanent, root-level TS channels. */
export function getChannelSpacer(channel: Pick<ChannelInfo, "name" | "parentID" | "isPermanent">): ChannelSpacer | null {
if (channel.parentID !== "0" || channel.isPermanent !== true) return null;
const match = /^\[([clr*]?)spacer[^\]\r\n]*\]([\s\S]*)$/i.exec(channel.name);
if (!match) return null;
const text = match[2];
const alignment = ({ c: "center", r: "right", "*": "repeat" } as const)[match[1].toLowerCase() as "c" | "r" | "*"] ?? "left";
return { text, alignment, style: Object.hasOwn(LINE_STYLES, text) ? LINE_STYLES[text] : "text" };
}
export function channelDisplayName(channel: Pick<ChannelInfo, "name" | "parentID" | "isPermanent">): string {
return getChannelSpacer(channel)?.text ?? channel.name;
}
+1
View File
@@ -73,6 +73,7 @@ function channel(value: unknown): value is ChannelInfo {
&& optional(value.maxClients, maximum => finite(maximum) && Number.isInteger(maximum) && maximum >= 0 && maximum <= 65_535)
&& optional(value.maxClientsLimited, boolean)
&& optional(value.passwordProtected, boolean)
&& optional(value.isPermanent, boolean)
&& (value.maxClients === undefined) === (value.maxClientsLimited === undefined)
&& optional(value.members, members => arrayOf(members, member));
}
+1
View File
@@ -192,6 +192,7 @@ const PUBLIC_PART_IDS = new Set<string>([
"voice.breadcrumbs",
"voice.channel-group",
"voice.channel-group.heading",
"voice.channel-spacer",
"voice.channel-group.members",
"voice.channel-tree.avatar",
"voice.channel-tree.branch",
+1 -1
View File
@@ -276,7 +276,7 @@ const COLLECTION_PERMISSION: Record<string, SkinPluginPermission> = {
"screenShare.streams": "voice.screenShare.read",
};
const COLLECTION_FIELDS: Record<string, ReadonlySet<string>> = {
"session.channels": new Set(["id", "name", "parentId", "depth", "memberCount", "memberCountLabel", "maxClients", "maxClientsLimited", "current"]),
"session.channels": new Set(["id", "name", "displayName", "isSpacer", "spacerAlignment", "spacerStyle", "parentId", "depth", "memberCount", "memberCountLabel", "maxClients", "maxClientsLimited", "current"]),
"session.members": new Set(["id", "name", "avatarInitial", "channelId", "status", "speaking", "self", "screenSharing", "screenShareStreamId"]),
"favorites.items": new Set(["id", "label", "current", "kind"]),
"servers.quickList": new Set(["id", "label", "monogram", "icon", "tone", "current", "switchRestricted", "switchTitle", "kind", "favorite"]),
@@ -5,6 +5,15 @@ import {
SKIN_RUNTIME_PLUGIN_CONTEXT_LIMIT_BYTES,
} from "./skin-runtime-plugin-context.js";
test("channel spacer metadata is available to custom skins only with channel read permission", () => {
const item = { id: "4", name: "[cspacer0]Section", displayName: "Section", isSpacer: true, spacerAlignment: "center", spacerStyle: "text", secret: "hidden" };
const context = { session: { channels: [item] } };
assert.deepEqual(JSON.parse(JSON.stringify(projectSkinRuntimePluginContext([], context))), {});
assert.deepEqual(JSON.parse(JSON.stringify(projectSkinRuntimePluginContext(["session.channels.read"], context))), {
session: { channels: [{ id: "4", name: item.name, displayName: "Section", isSpacer: true, spacerAlignment: "center", spacerStyle: "text" }] },
});
});
test("runtime context exposes only fields covered by declared read permissions", () => {
const projected = projectSkinRuntimePluginContext(["session.channels.read"], {
session: {
+5 -2
View File
@@ -26,7 +26,7 @@ interface CollectionProjection {
}
const COLLECTIONS: readonly CollectionProjection[] = Object.freeze([
{ path: ["session", "channels"], permission: "session.channels.read", fields: new Set(["id", "name", "parentId", "depth", "memberCount", "memberCountLabel", "maxClients", "maxClientsLimited", "current"]), maxItems: 128 },
{ path: ["session", "channels"], permission: "session.channels.read", fields: new Set(["id", "name", "displayName", "isSpacer", "spacerAlignment", "spacerStyle", "parentId", "depth", "memberCount", "memberCountLabel", "maxClients", "maxClientsLimited", "current"]), maxItems: 128 },
{
path: ["session", "members"],
permission: "session.members.read",
@@ -54,7 +54,7 @@ const CONTEXTS: readonly ContextProjection[] = Object.freeze([
{ path: ["screenShare", "status"], permission: "voice.screenShare.status.read", fields: new Set(["active", "starting", "viewing"]) },
]);
const BOOLEAN_FIELDS = new Set(["connected", "connecting", "current", "favorite", "speaking", "self", "screenSharing", "audio", "microphoneMuted", "outputMuted", "noiseSuppressionEnabled", "accompanimentActive", "active", "starting", "viewing", "maxClientsLimited", "panelOpen"]);
const BOOLEAN_FIELDS = new Set(["connected", "connecting", "current", "favorite", "speaking", "self", "screenSharing", "audio", "microphoneMuted", "outputMuted", "noiseSuppressionEnabled", "accompanimentActive", "active", "starting", "viewing", "maxClientsLimited", "panelOpen", "isSpacer"]);
const NUMBER_FIELDS = new Set(["depth", "memberCount", "targetCount", "ownerClientId", "viewerCount", "maxClients"]);
const TEXT_LIMITS: Readonly<Record<string, number>> = Object.freeze({
id: 128,
@@ -63,6 +63,9 @@ const TEXT_LIMITS: Readonly<Record<string, number>> = Object.freeze({
channelId: 128,
parentId: 128,
name: 160,
displayName: 160,
spacerAlignment: 8,
spacerStyle: 12,
label: 160,
channelName: 160,
userName: 160,
+2
View File
@@ -25,6 +25,8 @@ export interface ChannelInfo {
maxClientsLimited?: boolean;
/** TeamSpeak's public channel flag; absent when the connected server omits it. */
passwordProtected?: boolean;
/** Required to recognize TeamSpeak's permanent, root-level spacer channels. */
isPermanent?: boolean;
members?: ChannelMember[];
}