mirror of
https://github.com/EchoSixHIYA/WebSpeak-client-for-TeamSpeak.git
synced 2026-12-03 03:52:50 +08:00
feat(channels): render TeamSpeak spacers across skins
This commit is contained in:
1 parent
4bff2133b6
commit
b9fccb8757
21 files changed
+240
-17
No files matched your search
@@ -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;
|
||||
}
|
||||
@@ -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));
|
||||
}
|
||||
|
||||
@@ -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",
|
||||
|
||||
@@ -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: {
|
||||
|
||||
@@ -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,
|
||||
|
||||
@@ -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[];
|
||||
}
|
||||
|
||||
|
||||
Reference in new issue
Block a user