From b9fccb8757b870c09dc21fc2edf3e7ec475a4aa5 Mon Sep 17 00:00:00 2001 From: illusia <64828020+EchoSixHIYA@users.noreply.github.com> Date: Sat, 24 Oct 2026 18:16:01 +0800 Subject: [PATCH] feat(channels): render TeamSpeak spacers across skins --- docs/SKIN_DEVELOPMENT.md | 4 ++ src/server/directory-view.test.ts | 14 +++++ src/server/directory-view.ts | 1 + src/server/teamspeak-sdk.test.ts | 8 ++- src/server/teamspeak-sdk.ts | 2 + src/shared/channel-spacer.ts | 25 ++++++++ src/shared/server-messages.ts | 1 + src/shared/skin-layout.ts | 1 + src/shared/skin-plugin.ts | 2 +- .../skin-runtime-plugin-context.test.ts | 9 +++ src/shared/skin-runtime-plugin-context.ts | 7 ++- src/shared/voice-models.ts | 2 + .../web-client/ChannelMemberPanel.vue | 11 +++- .../components/web-client/ChannelSpacer.vue | 60 +++++++++++++++++++ .../web-client/VoiceChannelTreeItem.vue | 17 ++++-- web/src/composables/useWebClientChannels.ts | 3 +- web/src/services/skin-plugin-runtime.test.ts | 13 ++++ web/src/services/voice-channel-tree.test.ts | 28 +++++++++ web/src/views/DemoView.vue | 2 +- web/src/views/WebClient.vue | 6 ++ web/test/screen-share-ui.test.mjs | 41 ++++++++++++- 21 files changed, 240 insertions(+), 17 deletions(-) create mode 100644 src/shared/channel-spacer.ts create mode 100644 web/src/components/web-client/ChannelSpacer.vue diff --git a/docs/SKIN_DEVELOPMENT.md b/docs/SKIN_DEVELOPMENT.md index 981d292..00336f4 100644 --- a/docs/SKIN_DEVELOPMENT.md +++ b/docs/SKIN_DEVELOPMENT.md @@ -189,6 +189,10 @@ components.json 顶层接受 schemaVersion 1、2 或 3 和 components 数组。s 申请 `session.channels.read` 的 `session.channels` 列表还提供 `memberCount`、两位数显示用的 `memberCountLabel`、`maxClients` 和 `maxClientsLimited`。后两个字段仅在 TeamSpeak 返回有效上限数据时出现;`maxClientsLimited: false` 表示频道不限人数。它们与频道树一起属于公开只读数据,不会授予服务器写入能力。 +频道显示接口增补(0.2.8):同一权限下新增 `displayName`、`isSpacer`、`spacerAlignment` 与 `spacerStyle`,声明式 v3 和 Wasm v4 均可读取。`name` 始终保留服务器原名,`displayName` 仅对永久、顶层且名称以 `[spacer…]`、`[lspacer…]`、`[cspacer…]`、`[rspacer…]` 或 `[*spacer…]` 开头的频道移除前缀(大小写不敏感,省略或自定义标识均可)。分隔栏的 `spacerAlignment` 为 `left`、`center`、`right` 或 `repeat`;`spacerStyle` 为 `text`、`solid`、`dashed`、`dotted`、`dash-dot` 或 `dash-dot-dot`,五种线型对应 `___`、`---`、`...`、`-.-`、`-..`。普通频道的 `displayName` 等于 `name`、`isSpacer: false`、两个格式字段为空字符串。旧运行时可能不含新增字段;兼容包应回退到 `name`,不能只凭相同的 0.2.8 版本号推断字段存在。分隔栏仍为真实 TS 频道,不增加加入限制,不隐藏其中的成员或子频道;管理编辑继续使用原名。 + +宿主 `voice.channel-tree` 与 `voice.channel-panel` 自动使用上述显示规则;分隔栏隐藏普通频道图标和人数,不显示空成员提示。新增稳定部件 `voice.channel-spacer`,提供 `data-alignment` 与 `data-spacer-style` 属性;频道树行 `voice.channel-tree.row` 和成员面板标题 `voice.channel-group.heading` 在分隔栏上提供 `data-spacer="true"`。颜色和字体继承皮肤,文字及重复填充在可用宽度内裁剪,空文本保留分隔间距。皮肤无需新增权限或修改传输逻辑。 + ```json { "schemaVersion": 2, diff --git a/src/server/directory-view.test.ts b/src/server/directory-view.test.ts index 735b006..1399dcb 100644 --- a/src/server/directory-view.test.ts +++ b/src/server/directory-view.test.ts @@ -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"); diff --git a/src/server/directory-view.ts b/src/server/directory-view.ts index 0c87ff8..8e56bc9 100644 --- a/src/server/directory-view.ts +++ b/src/server/directory-view.ts @@ -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) => { diff --git a/src/server/teamspeak-sdk.test.ts b/src/server/teamspeak-sdk.test.ts index 9fc36f7..260173a 100644 --- a/src/server/teamspeak-sdk.test.ts +++ b/src/server/teamspeak-sdk.test.ts @@ -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"); diff --git a/src/server/teamspeak-sdk.ts b/src/server/teamspeak-sdk.ts index 4729a0e..47f58db 100644 --- a/src/server/teamspeak-sdk.ts +++ b/src/server/teamspeak-sdk.ts @@ -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 } diff --git a/src/shared/channel-spacer.ts b/src/shared/channel-spacer.ts new file mode 100644 index 0000000..5440bab --- /dev/null +++ b/src/shared/channel-spacer.ts @@ -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> = { + "___": "solid", "---": "dashed", "...": "dotted", "-.-": "dash-dot", "-..": "dash-dot-dot", +}; + +/** Spacers are a presentation convention for permanent, root-level TS channels. */ +export function getChannelSpacer(channel: Pick): 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): string { + return getChannelSpacer(channel)?.text ?? channel.name; +} diff --git a/src/shared/server-messages.ts b/src/shared/server-messages.ts index f7c05d9..57eeb5c 100644 --- a/src/shared/server-messages.ts +++ b/src/shared/server-messages.ts @@ -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)); } diff --git a/src/shared/skin-layout.ts b/src/shared/skin-layout.ts index 1d33c86..4505a0f 100644 --- a/src/shared/skin-layout.ts +++ b/src/shared/skin-layout.ts @@ -192,6 +192,7 @@ const PUBLIC_PART_IDS = new Set([ "voice.breadcrumbs", "voice.channel-group", "voice.channel-group.heading", + "voice.channel-spacer", "voice.channel-group.members", "voice.channel-tree.avatar", "voice.channel-tree.branch", diff --git a/src/shared/skin-plugin.ts b/src/shared/skin-plugin.ts index 85f4ab2..f5b8d98 100644 --- a/src/shared/skin-plugin.ts +++ b/src/shared/skin-plugin.ts @@ -276,7 +276,7 @@ const COLLECTION_PERMISSION: Record = { "screenShare.streams": "voice.screenShare.read", }; const COLLECTION_FIELDS: Record> = { - "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"]), diff --git a/src/shared/skin-runtime-plugin-context.test.ts b/src/shared/skin-runtime-plugin-context.test.ts index 5ce3114..8b935b7 100644 --- a/src/shared/skin-runtime-plugin-context.test.ts +++ b/src/shared/skin-runtime-plugin-context.test.ts @@ -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: { diff --git a/src/shared/skin-runtime-plugin-context.ts b/src/shared/skin-runtime-plugin-context.ts index 24f76c2..9ccaf1f 100644 --- a/src/shared/skin-runtime-plugin-context.ts +++ b/src/shared/skin-runtime-plugin-context.ts @@ -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> = Object.freeze({ id: 128, @@ -63,6 +63,9 @@ const TEXT_LIMITS: Readonly> = Object.freeze({ channelId: 128, parentId: 128, name: 160, + displayName: 160, + spacerAlignment: 8, + spacerStyle: 12, label: 160, channelName: 160, userName: 160, diff --git a/src/shared/voice-models.ts b/src/shared/voice-models.ts index 6eabe86..8b371bc 100644 --- a/src/shared/voice-models.ts +++ b/src/shared/voice-models.ts @@ -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[]; } diff --git a/web/src/components/web-client/ChannelMemberPanel.vue b/web/src/components/web-client/ChannelMemberPanel.vue index 3903f79..8e6b803 100644 --- a/web/src/components/web-client/ChannelMemberPanel.vue +++ b/web/src/components/web-client/ChannelMemberPanel.vue @@ -60,16 +60,19 @@
{{ t("noMembersInChannel") }}
@@ -188,6 +191,8 @@ + + diff --git a/web/src/components/web-client/VoiceChannelTreeItem.vue b/web/src/components/web-client/VoiceChannelTreeItem.vue index c30a35a..f39334b 100644 --- a/web/src/components/web-client/VoiceChannelTreeItem.vue +++ b/web/src/components/web-client/VoiceChannelTreeItem.vue @@ -16,7 +16,7 @@ type="button" class="ws-voice-channel-expander" data-ws-part="voice.channel-tree.expander" - :aria-label="`${expanded ? '收起' : '展开'} ${node.channel.name} / ${expanded ? 'Collapse' : 'Expand'} channel`" + :aria-label="`${expanded ? '收起' : '展开'} ${displayName} / ${expanded ? 'Collapse' : 'Expand'} channel`" :aria-expanded="expanded" @click.stop="emit('toggle', node.channel.id)" > @@ -24,8 +24,9 @@ type="button" class="ws-voice-channel-row" data-ws-part="voice.channel-tree.row" + :data-spacer="spacer ? 'true' : undefined" :data-drag-over="memberDragDrop && dragOverChannelId === node.channel.id ? 'true' : undefined" - :title="`双击或按 Enter 加入 ${node.channel.name} / Double-click or press Enter to join${node.channel.passwordProtected ? ' · 需要频道密码 / Channel password required' : ''}`" + :title="`双击或按 Enter 加入 ${displayName} / Double-click or press Enter to join${node.channel.passwordProtected ? ' · 需要频道密码 / Channel password required' : ''}`" :data-password-protected="node.channel.passwordProtected ? 'true' : undefined" @click="emit('select', node.channel.id)" @dblclick.stop.prevent="join" @@ -35,15 +36,17 @@ @drop="handleChannelDrop($event)" > - {{ node.channel.name }} - 双击加入 - + + {{ node.channel.name }} + 双击加入 + {{ memberCount }} @@ -230,6 +233,8 @@