feat(kaak): add trusted server switcher and channel tree

This commit is contained in:
illusia committed 2026-10-11 18:37:13 +08:00
1 parent 17fb27b89a
commit b13bdf1eb2
24 files changed
+733 -514

No files matched your search

+2 -1
View File
@@ -66,7 +66,8 @@
<path v-else-if="name === 'share'" d="M4 12v7a2 2 0 0 0 2 2h12a2 2 0 0 0 2-2v-7M16 6l-4-4-4 4m4-4v13" />
<path v-else-if="name === 'copy'" d="M8 8V5a2 2 0 0 1 2-2h8a2 2 0 0 1 2 2v8a2 2 0 0 1-2 2h-3M6 8h7a2 2 0 0 1 2 2v8a2 2 0 0 1-2 2H6a2 2 0 0 1-2-2v-8a2 2 0 0 1 2-2Z" />
<path v-else-if="name === 'close'" d="m6 6 12 12M18 6 6 18" />
<path v-else-if="name === 'more'" d="M5 12h.01M12 12h.01M19 12h.01" stroke-width="3" />
<path v-else-if="name === 'more'" d="M5 12h.01M12 12h.01M19 12h.01" stroke-width="3" />
<path v-else-if="name === 'menu'" d="M4 6h16M4 12h16M4 18h16" />
<path v-else-if="name === 'refresh'" d="M20 11a8 8 0 0 0-14-4L4 9m0-4v4h4M4 13a8 8 0 0 0 14 4l2-2m0 4v-4h-4" />
<path v-else-if="name === 'lock'" d="M6 10h12v10H6zM8 10V7a4 4 0 0 1 8 0v3" />
<path v-else-if="name === 'users'" d="M16 21v-2a4 4 0 0 0-4-4H7a4 4 0 0 0-4 4v2m6-10a4 4 0 1 0 0-8 4 4 0 0 0 0 8Zm6-7a4 4 0 0 1 0 7m2 5h1a4 4 0 0 1 4 4v1" />
@@ -0,0 +1,88 @@
<template>
<ul
v-if="tree.length"
class="ws-voice-channel-tree"
data-ws-part="voice.channel-tree.list"
role="tree"
aria-label="语音频道 / Voice channels"
>
<VoiceChannelTreeItem
v-for="node in tree"
:key="node.channel.id"
:node="node"
:depth="0"
:current-channel-id="currentChannelId"
:selected-channel-id="selectedChannelId"
:expanded-ids="expandedIds"
:avatar-style="avatarStyle"
:avatar-initial="avatarInitial"
:is-speaking="isSpeaking"
:t="t"
@toggle="toggleExpanded"
@select="selectedChannelId = $event"
@join="joinChannel"
/>
</ul>
<div
v-else
class="ws-voice-channel-tree-empty"
data-ws-part="voice.channel-tree.empty"
role="status"
>无可用语音频道 / No voice channels</div>
</template>
<script setup lang="ts">
import { computed, ref, watch, type CSSProperties } from "vue";
import type { ChannelMember } from "../../composables/useVoiceWebSocket.js";
import type { TreeChannel } from "../../composables/useWebClientChannels.js";
import { buildVoiceChannelTree } from "../../services/voice-channel-tree.js";
import VoiceChannelTreeItem from "./VoiceChannelTreeItem.vue";
const props = defineProps<{
channels: readonly TreeChannel[];
currentChannelId?: string;
avatarStyle: (name: string, isSelf?: boolean, avatar?: string) => CSSProperties;
avatarInitial: (name: string) => string;
isSpeaking: (member: ChannelMember) => boolean;
t: (key: string) => string;
}>();
const tree = computed(() => buildVoiceChannelTree(props.channels));
const selectedChannelId = ref(props.currentChannelId ?? "");
const expandedIds = ref(new Set<string>());
watch(() => props.currentChannelId, (channelId) => {
if (channelId) selectedChannelId.value = channelId;
}, { immediate: true });
watch(tree, (nodes) => {
const availableIds = new Set<string>();
const expanded = new Set(expandedIds.value);
const pending = [...nodes];
while (pending.length) {
const node = pending.pop()!;
availableIds.add(node.channel.id);
if (node.children.length || node.channel.members.length) expanded.add(node.channel.id);
pending.push(...node.children);
}
for (const id of expanded) if (!availableIds.has(id)) expanded.delete(id);
expandedIds.value = expanded;
}, { immediate: true });
function toggleExpanded(channelId: string): void {
const next = new Set(expandedIds.value);
if (next.has(channelId)) next.delete(channelId);
else next.add(channelId);
expandedIds.value = next;
}
function joinChannel(channel: TreeChannel): void {
if (channel.id === props.currentChannelId) return;
selectedChannelId.value = channel.id;
emit("join", channel);
}
const emit = defineEmits<{
join: [channel: TreeChannel];
}>();
</script>
@@ -0,0 +1,143 @@
<template>
<li
class="ws-voice-channel-node"
data-ws-part="voice.channel-tree.node"
role="treeitem"
:aria-level="depth + 1"
:aria-expanded="hasContents ? expanded : undefined"
:aria-selected="selected"
:aria-current="current ? 'location' : undefined"
:data-current="current ? 'true' : 'false'"
:data-selected="selected ? 'true' : 'false'"
>
<div class="ws-voice-channel-line" data-ws-part="voice.channel-tree.line">
<button
v-if="hasContents"
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-expanded="expanded"
@click.stop="emit('toggle', node.channel.id)"
><Icon :name="expanded ? 'chevron-down' : 'chevron-right'" :size="13" /></button>
<span v-else class="ws-voice-channel-expander-placeholder" aria-hidden="true"></span>
<button
type="button"
class="ws-voice-channel-row"
data-ws-part="voice.channel-tree.row"
:title="`双击或按 Enter 加入 ${node.channel.name} / Double-click or press Enter to join`"
@click="emit('select', node.channel.id)"
@dblclick.stop.prevent="join"
@keydown.enter.prevent.stop="join"
>
<Icon class="ws-voice-channel-type" data-ws-part="voice.channel-tree.icon" name="volume" :size="14" />
<span class="ws-voice-channel-name" data-ws-part="voice.channel-tree.name">{{ node.channel.name }}</span>
<span v-if="selected && !current" class="ws-voice-channel-join-hint" data-ws-part="voice.channel-tree.join-hint">双击加入</span>
<span class="ws-voice-channel-count" data-ws-part="voice.channel-tree.count">
{{ memberCount }}<template v-if="node.channel.maxClientsLimited && typeof node.channel.maxClients === 'number'">/{{ node.channel.maxClients }}</template>
</span>
</button>
</div>
<div
v-if="hasContents"
class="ws-voice-channel-branch"
data-ws-part="voice.channel-tree.branch"
:data-expanded="expanded ? 'true' : 'false'"
>
<ul class="ws-voice-channel-branch-content" role="group">
<li
v-for="member in node.channel.members"
:key="member.id"
class="ws-voice-channel-member"
data-ws-part="voice.channel-tree.member"
role="treeitem"
:aria-level="depth + 2"
:aria-label="`${member.nickname}${member.isSelf ? `, ${t('you')}` : ''}${member.inputMuted ? `, ${t('inputMuted')}` : ''}${member.away ? ', away' : ''}`"
:data-speaking="isSpeaking(member) ? 'true' : 'false'"
:data-away="member.away ? 'true' : 'false'"
>
<span
class="ws-voice-channel-member-avatar"
data-ws-part="voice.channel-tree.avatar"
:class="{ 'is-speaking': isSpeaking(member) }"
:style="avatarStyle(member.nickname, member.isSelf, member.avatar)"
aria-hidden="true"
>{{ member.avatar ? '' : avatarInitial(member.nickname) }}</span>
<span class="ws-voice-channel-member-name" data-ws-part="voice.channel-tree.member-name">
{{ member.isSelf ? t('you') : member.nickname }}
</span>
<Icon
v-if="member.inputMuted"
class="ws-voice-channel-member-muted"
data-ws-part="voice.channel-tree.member-muted"
name="mic-off"
:size="12"
:title="t('inputMuted')"
/>
<span
v-else-if="isSpeaking(member)"
class="ws-voice-channel-member-speaking"
data-ws-part="voice.channel-tree.member-speaking"
aria-hidden="true"
></span>
<span v-if="member.away" class="ws-voice-channel-member-away" data-ws-part="voice.channel-tree.member-away" aria-hidden="true">·</span>
</li>
<VoiceChannelTreeItem
v-for="child in node.children"
:key="child.channel.id"
:node="child"
:depth="depth + 1"
:current-channel-id="currentChannelId"
:selected-channel-id="selectedChannelId"
:expanded-ids="expandedIds"
:avatar-style="avatarStyle"
:avatar-initial="avatarInitial"
:is-speaking="isSpeaking"
:t="t"
@toggle="emit('toggle', $event)"
@select="emit('select', $event)"
@join="emit('join', $event)"
/>
</ul>
</div>
</li>
</template>
<script setup lang="ts">
import { computed, type CSSProperties } from "vue";
import Icon from "../Icon.vue";
import type { ChannelMember } from "../../composables/useVoiceWebSocket.js";
import type { TreeChannel } from "../../composables/useWebClientChannels.js";
import type { VoiceChannelTreeNode } from "../../services/voice-channel-tree.js";
defineOptions({ name: "VoiceChannelTreeItem" });
const props = defineProps<{
node: VoiceChannelTreeNode<TreeChannel>;
depth: number;
currentChannelId?: string;
selectedChannelId: string;
expandedIds: ReadonlySet<string>;
avatarStyle: (name: string, isSelf?: boolean, avatar?: string) => CSSProperties;
avatarInitial: (name: string) => string;
isSpeaking: (member: ChannelMember) => boolean;
t: (key: string) => string;
}>();
const emit = defineEmits<{
toggle: [channelId: string];
select: [channelId: string];
join: [channel: TreeChannel];
}>();
const expanded = computed(() => props.expandedIds.has(props.node.channel.id));
const hasContents = computed(() => props.node.children.length > 0 || props.node.channel.members.length > 0);
const current = computed(() => props.node.channel.id === props.currentChannelId);
const selected = computed(() => props.node.channel.id === props.selectedChannelId);
const memberCount = computed(() => String(props.node.channel.members.length).padStart(2, "0"));
function join(): void {
if (props.node.channel.id !== props.currentChannelId) emit("join", props.node.channel);
}
</script>
@@ -0,0 +1,84 @@
<template>
<div
ref="rootElement"
class="ws-voice-server-switcher"
data-ws-part="voice.server-switcher"
@keydown.esc.prevent.stop="closeMenu"
>
<button
ref="triggerElement"
type="button"
class="ws-voice-server-switcher-trigger"
data-ws-part="voice.server-switcher.trigger"
aria-label="切换服务器 / Switch server"
title="切换服务器 / Switch server"
:aria-expanded="open"
aria-haspopup="true"
@click="open = !open"
><Icon name="menu" :size="17" /></button>
<div
v-if="open"
class="ws-voice-server-switcher-menu"
data-ws-part="voice.server-switcher.menu"
role="group"
aria-label="快速切换服务器 / Quick server switch"
>
<button
v-for="server in servers"
:key="server.id"
type="button"
class="ws-voice-server-switcher-item"
data-ws-part="voice.server-switcher.item"
:class="{ 'is-current': server.current }"
:aria-current="server.current ? 'true' : undefined"
:disabled="server.current"
@click="switchServer(server)"
>
<span class="ws-voice-server-switcher-icon" data-ws-part="voice.server-switcher.icon" :data-tone="server.tone">
<img v-if="server.icon" :src="server.icon" alt="" />
<span v-else>{{ server.monogram }}</span>
</span>
<span class="ws-voice-server-switcher-label" data-ws-part="voice.server-switcher.label">{{ server.label }}</span>
<Icon v-if="server.current" class="ws-voice-server-switcher-current" data-ws-part="voice.server-switcher.current" name="check" :size="14" />
</button>
<p v-if="!otherServerCount" class="ws-voice-server-switcher-empty" data-ws-part="voice.server-switcher.empty">
暂无其他收藏或最近连接的服务器。<br />Save or connect to another server to switch here.
</p>
</div>
</div>
</template>
<script setup lang="ts">
import { computed, onBeforeUnmount, onMounted, ref } from "vue";
import type { SkinPluginQuickServer } from "../../services/skin-plugin-context.js";
import Icon from "../Icon.vue";
const props = defineProps<{
servers: readonly SkinPluginQuickServer[];
onSwitchServer: (quickServerId: string) => void;
}>();
const open = ref(false);
const rootElement = ref<HTMLElement | null>(null);
const triggerElement = ref<HTMLButtonElement | null>(null);
const otherServerCount = computed(() => props.servers.filter((server) => !server.current).length);
function switchServer(server: SkinPluginQuickServer): void {
if (server.current) return;
props.onSwitchServer(server.id);
closeMenu();
}
function closeMenu(): void {
if (!open.value) return;
open.value = false;
triggerElement.value?.focus();
}
function onDocumentPointerDown(event: PointerEvent): void {
if (event.target instanceof Node && !rootElement.value?.contains(event.target)) closeMenu();
}
onMounted(() => document.addEventListener("pointerdown", onDocumentPointerDown));
onBeforeUnmount(() => document.removeEventListener("pointerdown", onDocumentPointerDown));
</script>
+2 -2
View File
@@ -46,10 +46,10 @@ export const BUILTIN_SKIN_CATALOG: SkinCatalogEntry[] = [
{
id: BUILTIN_KAAK_SKIN_ID,
name: "KAAK",
version: "3.1.64",
version: "3.1.65",
author: "WebSpeak Project",
license: "AGPL-3.0-only",
description: "A KOOK-inspired voice-room workspace with collapsible voice groups, channel chat, TeamSpeak profile cards, accessible host-owned member controls, and WebSpeak screen sharing.",
description: "A KOOK-inspired voice-room workspace with a live server header, quick server switching, a nested channel tree with member avatars, attached channel chat, and WebSpeak voice controls.",
minAppVersion: "0.2.7-preview",
installedAt: 0,
builtIn: true,
+22 -20
View File
@@ -464,7 +464,7 @@ test("the distributable KAAK package provides full home and voice surfaces", asy
const file = new File([archive], "kaak-voice.wskin", { type: "application/octet-stream" });
const skin = await importSkinPack(file);
assert.equal(skin.id, "community.kaak-voice");
assert.equal(skin.version, "3.1.64");
assert.equal(skin.version, "3.1.65");
assert.equal(BUILTIN_SKIN_CATALOG.find((entry) => entry.id === skin.id)?.version, skin.version);
assert.equal(skin.schemaVersion, 3);
const home = skin.pluginData?.components.find((component) => component.page === "home");
@@ -476,7 +476,8 @@ test("the distributable KAAK package provides full home and voice surfaces", asy
assert.ok(home?.permissions.includes("ui.surface.replace"));
assert.equal(voice?.stateScope, "session.status.channelId");
assert.ok(voice?.permissions.includes("ui.surface.replace"));
assert.ok(voice?.permissions.includes("servers.quickList.switch"));
assert.ok(voice?.permissions.includes("servers.quickList.read"));
assert.ok(voice?.permissions.includes("servers.quickList.switch"));
assert.ok(voice?.permissions.includes("session.channels.read"));
assert.ok(voice?.permissions.includes("session.members.read"));
assert.ok(voice?.permissions.includes("session.memberAvatars.read"));
@@ -496,11 +497,14 @@ test("the distributable KAAK package provides full home and voice surfaces", asy
}
return undefined;
}
const channelRow = findPart(voice?.root, "channel-row");
assert.equal(channelRow?.events?.click, "select-channel");
assert.equal(channelRow?.events?.dblclick, "join-channel");
assert.deepEqual(findPart(channelRow, "channel-join-hint")?.when, { path: "state.selectedchannel", equals: "{{channel.id}}" });
assert.equal(findPart(channelRow, "channel-join-hint")?.children?.[0]?.text, "双击加入");
assert.equal(findPart(voice?.root, "server-name")?.children?.[0]?.text, "{{session.status.serverLabel}}");
assert.equal(findPart(voice?.root, "server-switcher")?.widget, "voice.server-switcher");
assert.deepEqual(findPart(voice?.root, "server-connection-dot")?.when, { path: "session.status.connectionState", equals: "connected" });
assert.equal(findPart(voice?.root, "server-subtitle")?.children?.[0]?.text, "已连接 · {{session.status.userName}}");
assert.equal(findPart(voice?.root, "voice-channel-tree")?.widget, "voice.channel-tree");
assert.equal(findPart(voice?.root, "channel-row"), undefined, "channels render in the trusted nested tree widget");
assert.equal(voice?.actions["select-channel"], undefined);
assert.equal(voice?.actions["join-channel"], undefined);
assert.equal(findPart(voice?.root, "text-channel-group-toggle"), undefined);
assert.equal(findPart(voice?.root, "text-channel-list"), undefined);
const voiceGroupToggle = findPart(voice?.root, "voice-channel-group-toggle");
@@ -530,12 +534,8 @@ test("the distributable KAAK package provides full home and voice surfaces", asy
assert.equal(findPart(voiceStageHeading, "voice-stage-member-count")?.children?.[0]?.text, "{{stagechannel.memberCountLabel}}");
assert.deepEqual(findPart(voiceStageHeading, "voice-stage-capacity")?.when, { path: "stagechannel.maxClientsLimited", equals: true });
assert.equal(findPart(voiceStageHeading, "voice-stage-capacity")?.children?.[0]?.text, "/{{stagechannel.maxClients}}");
assert.equal(findPart(voice?.root, "channel-count")?.children?.[0]?.text, "{{channel.memberCountLabel}}");
assert.deepEqual(findPart(voice?.root, "channel-capacity")?.when, { path: "channel.maxClientsLimited", equals: true });
assert.equal(findPart(voice?.root, "channel-capacity")?.children?.[0]?.text, "/{{channel.maxClients}}");
assert.deepEqual(findPart(voice?.root, "channel-voice-members")?.when, { path: "channel.members", empty: false });
assert.equal(findPart(voice?.root, "channel-voice-member")?.repeat?.path, "channel.members");
assert.equal(findPart(voice?.root, "channel-member-avatar")?.children?.[0]?.text, "{{voicemember.avatarInitial}}");
assert.equal(findPart(voice?.root, "channel-count"), undefined, "real member counts come from the host-owned channel tree");
assert.equal(findPart(voice?.root, "channel-voice-member"), undefined, "avatar resources stay inside trusted host UI");
assert.equal(findPart(voice?.root, "voice-stage")?.attributes?.["aria-label"], "语音房间 / Voice room");
assert.equal(findPart(voice?.root, "member-cards")?.widget, "voice.member-cards");
assert.deepEqual(findPart(voice?.root, "member-cards")?.options, { screenShare: true, memberActions: true });
@@ -554,9 +554,12 @@ test("the distributable KAAK package provides full home and voice surfaces", asy
assert.equal(findPart(voice?.root, "screen-share-stop")?.events?.click, "stop-screen-share");
assert.equal(findPart(voice?.root, "audio-controls")?.widget, "voice.audio-controls");
assert.deepEqual(findPart(voice?.root, "audio-controls")?.options, { layout: "room-panel" });
assert.ok(skin.css.includes('[data-ws-plugin-part="kaak-workspace.channel-row"]'));
assert.match(skin.css, /channel-row"\]\[aria-current="true"\][\s\S]*?channel-join-hint[\s\S]*?display: none;/);
assert.match(skin.css, /@keyframes ws-community-kaak-voice-kaak-channel-join-hint/);
assert.ok(skin.css.includes('[data-ws-plugin-part="kaak-workspace.server-summary"]'));
assert.ok(skin.css.includes(".ws-voice-server-switcher-menu"));
assert.ok(skin.css.includes('[data-ws-plugin-part="kaak-workspace"] .ws-voice-channel-row'));
assert.match(skin.css, /ws-voice-channel-node\[data-current="true"\][\s\S]*?box-shadow: inset 2px 0 var\(--skin-kaak-accent\);/);
assert.match(skin.css, /ws-voice-channel-branch\[data-expanded="false"\][\s\S]*?grid-template-rows: 0fr;/);
assert.match(skin.css, /ws-voice-channel-member-avatar[\s\S]*?border-radius: 50%;/);
assert.match(skin.css, /--skin-kaak-font:[\s\S]*?PingFang SC/);
assert.match(skin.css, /--skin-kaak-accent: #6cbf00;/);
assert.match(skin.css, /voice-dock"\] \{[\s\S]*?width: min\(264px, 100%\);[\s\S]*?border-radius: 17px;/);
@@ -651,11 +654,10 @@ test("the distributable KAAK package provides full home and voice surfaces", asy
assert.match(skin.css, /voice-avatar-wrap::after \{[\s\S]*?content: "";[\s\S]*?border: 2px solid #6cbf0088;/);
assert.match(skin.css, /voice-card\[data-ws-speaking="true"\] \.voice-avatar-wrap::after \{ display: block; animation: ws-community-kaak-voice-kaak-member-speaking-ring 1\.08s/);
assert.match(skin.css, /voice-card\[data-ws-speaking="true"\]::after \{ display: block; animation: ws-community-kaak-voice-kaak-member-speaking-wave \.72s ease-in-out infinite alternate/);
assert.match(skin.css, /server-name"\]\s*\{[\s\S]*?font-size: 16px;[\s\S]*?font-weight: 700;[\s\S]*?line-height: 24px;/);
assert.match(skin.css, /server-name"\]\s*\{[\s\S]*?font-size: 16px;[\s\S]*?font-weight: 700;[\s\S]*?line-height: 22px;/);
assert.match(skin.css, /voice-channel-group-toggle"\]\s*\{[\s\S]*?font-size: 12px;[\s\S]*?font-weight: 700;[\s\S]*?letter-spacing: normal;/);
assert.match(skin.css, /channel-name"\]\s*\{[\s\S]*?font-size: 14px;[\s\S]*?font-weight: 700;[\s\S]*?line-height: 24px;/);
assert.match(skin.css, /channel-count"\]\s*\{[\s\S]*?color: rgba\(230, 234, 240, \.4\);[\s\S]*?font-size: 12px;[\s\S]*?font-weight: 400;/);
assert.match(skin.css, /channel-capacity"\]\s*\{[\s\S]*?color: rgba\(230, 234, 240, \.4\);[\s\S]*?font-size: 12px;[\s\S]*?font-weight: 400;/);
assert.match(skin.css, /ws-voice-channel-name\s*\{[^}]*font-size: 14px;[^}]*font-weight: 700;[^}]*line-height: 24px;/);
assert.match(skin.css, /ws-voice-channel-count\s*\{[^}]*color: rgba\(230, 234, 240, \.4\);[^}]*font-size: 12px;[^}]*font-weight: 400;/);
assert.match(skin.css, /\.ws-voice-member-move \{ transition: transform \.28s/);
assert.match(skin.css, /\.ws-voice-member-enter-from,[\s\S]*?\.ws-voice-member-leave-to \{ opacity: 0; transform: translateY\(10px\) scale\(\.975\); \}/);
assert.match(skin.css, /data-ws-part="voice\.member\.mic-status"[\s\S]*?color: #c8c9ce;[\s\S]*?background: #111216d9;/);
+11 -2
View File
@@ -22,11 +22,20 @@ function safeLabelTone(label: string): number {
return (hash >>> 0) % 7;
}
const CONNECTION_TARGET_PATTERN = /(?:\b(?:\d{1,3}\.){3}\d{1,3}(?::\d{1,5})?\b|\[[0-9a-f:]+\](?::\d{1,5})?|\b(?:[a-z0-9](?:[a-z0-9-]{0,61}[a-z0-9])?\.)+[a-z]{2,63}(?::\d{1,5})?\b|\b(?:[0-9a-f]{0,4}:){2,}[0-9a-f:]{1,}\b)/i;
function containsConnectionTarget(label: string, address: string): boolean {
const candidates = new Set([address.trim()]);
try { candidates.add(splitTeamSpeakTarget(address).address.trim()); } catch { /* Persisted targets are validated on write. */ }
const normalizedLabel = label.toLocaleLowerCase();
return [...candidates].some((candidate) => candidate.length >= 3 && normalizedLabel.includes(candidate.toLocaleLowerCase()));
return CONNECTION_TARGET_PATTERN.test(normalizedLabel)
|| [...candidates].some((candidate) => candidate.length >= 3 && normalizedLabel.includes(candidate.toLocaleLowerCase()));
}
/** Returns a displayable TeamSpeak server name without exposing connection targets. */
export function safeSkinServerDisplayName(name: string, address: string): string {
const bounded = name.trim().replace(/\u0000/g, "").slice(0, 160);
return bounded && !containsConnectionTarget(bounded, address) ? bounded : "";
}
/** Projects local favorite/recent entries without exposing their connection targets. */
@@ -48,7 +57,7 @@ export function createSkinPluginQuickServerProjection(createId: () => string = r
}
targetByOpaqueId.set(opaqueId, server);
const label = server.label.trim();
const serverName = server.serverName?.trim() ?? "";
const serverName = safeSkinServerDisplayName(server.serverName ?? "", server.address);
const safeLabel = !label || containsConnectionTarget(label, server.address)
? serverName && !containsConnectionTarget(serverName, server.address)
? serverName
@@ -101,3 +101,18 @@ test("skin quick-server projection uses the TeamSpeak name and public icon while
assert.equal(server.icon, icon);
assert.equal(JSON.stringify(server).includes("shanghai.example"), false);
});
test("skin quick-server projection does not expose a network target used as the TeamSpeak name", () => {
const projection = createSkinPluginQuickServerProjection(() => "opaque-target-name");
const [server] = projection.project([{
id: "current.example:9987",
address: "current.example:9987",
label: "current.example:9987",
serverName: "server.example.invalid:9987",
isFavorite: true,
}], () => true);
assert.equal(server.label, "Favorite 1");
assert.equal(server.monogram, "F");
assert.equal(JSON.stringify(server).includes("server.example.invalid"), false);
});
+37
View File
@@ -0,0 +1,37 @@
export interface VoiceChannelTreeSource {
id: string;
depth: number;
}
export interface VoiceChannelTreeNode<T extends VoiceChannelTreeSource = VoiceChannelTreeSource> {
channel: T;
depth: number;
children: VoiceChannelTreeNode<T>[];
}
const MAX_NESTED_CHANNEL_DEPTH = 12;
/** Rebuilds a nested view from the host's safe, preorder TeamSpeak channel list. */
export function buildVoiceChannelTree<T extends VoiceChannelTreeSource>(
channels: readonly T[],
): VoiceChannelTreeNode<T>[] {
const roots: VoiceChannelTreeNode<T>[] = [];
const parentStack: VoiceChannelTreeNode<T>[] = [];
const seen = new Set<string>();
for (const channel of channels) {
if (!channel.id || seen.has(channel.id)) continue;
seen.add(channel.id);
const requestedDepth = Number.isFinite(channel.depth) ? Math.max(0, Math.floor(channel.depth)) : 0;
const depth = Math.min(requestedDepth, MAX_NESTED_CHANNEL_DEPTH, parentStack.length);
const node: VoiceChannelTreeNode<T> = { channel, depth, children: [] };
if (depth === 0) roots.push(node);
else parentStack[depth - 1].children.push(node);
parentStack.length = depth;
parentStack.push(node);
}
return roots;
}
+54 -24
View File
@@ -977,8 +977,10 @@ import SkinPluginOutlet from "../components/SkinPluginOutlet.js";
import SkinPluginEditor from "../components/SkinPluginEditor.vue";
import SkinRuntimePluginHost from "../components/SkinRuntimePluginHost.js";
import SkinLoadRecoveryNotice from "../components/SkinLoadRecoveryNotice.vue";
import VoiceMemberCards from "../components/web-client/VoiceMemberCards.vue";
import VoicePerformancePanel from "../components/web-client/VoicePerformancePanel.vue";
import VoiceMemberCards from "../components/web-client/VoiceMemberCards.vue";
import VoicePerformancePanel from "../components/web-client/VoicePerformancePanel.vue";
import VoiceChannelTree from "../components/web-client/VoiceChannelTree.vue";
import VoiceServerSwitcher from "../components/web-client/VoiceServerSwitcher.vue";
import ScreenShareSettingsDialog from "../components/web-client/ScreenShareSettingsDialog.vue";
import ScreenSharePlayer from "../components/web-client/ScreenSharePlayer.vue";
import AudioDock from "../components/web-client/AudioDock.vue";
@@ -1018,7 +1020,7 @@ import { BUILTIN_DARK_SKIN, BUILTIN_LIGHT_SKIN } from "../services/skin-runtime.
import { applyTheme, getStoredTheme, type ThemeMode } from "../services/theme.js";
import { createScreenWakeLockController, getScreenWakeLockApi, type ScreenWakeLockController, type ScreenWakeLockSnapshot } from "../services/screen-wake-lock.js";
import { createMobileAwayController, type MobileAwayController } from "../services/mobile-away.js";
import { createSkinPluginQuickServerProjection } from "../services/skin-plugin-context.js";
import { createSkinPluginQuickServerProjection, safeSkinServerDisplayName } from "../services/skin-plugin-context.js";
import { loadSkinPluginAuthoringDocument } from "../services/skin-plugin-authoring.js";
import type { SkinPluginDocument, SkinPluginWidgetOptions } from "../../../src/shared/skin-plugin.js";
import { combineTeamSpeakTarget, DEFAULT_TEAM_SPEAK_PORT, isValidTeamSpeakPort, splitTeamSpeakTarget } from "../services/teamspeak-target.js";
@@ -1542,8 +1544,16 @@ async function submitFavoriteServerDraft(draft: FavoriteServerDraft): Promise<vo
const visiblePokes = computed(() => pokeNotifications.slice(-3));
const skinPluginQuickServers = createSkinPluginQuickServerProjection();
const skinPluginQuickServers = createSkinPluginQuickServerProjection();
const skinPluginQuickList = computed(() => skinPluginQuickServers.project(quickServersForDisplay.value, isQuickServerTarget));
const currentServerDisplayName = computed(() => {
const target = currentServerTarget();
const liveName = safeSkinServerDisplayName(voiceServerInfo.value?.name ?? "", target);
if (liveName) return liveName;
const savedCurrent = quickServers.value.find(isQuickServerTarget);
const savedName = savedCurrent ? safeSkinServerDisplayName(savedCurrent.serverName ?? "", savedCurrent.address) : "";
return savedName || skinPluginQuickList.value.find((server) => server.current)?.label || "TeamSpeak";
});
const skinPluginFavorites = computed(() => skinPluginQuickList.value
.filter((server) => server.favorite)
.map(({ favorite: _favorite, ...server }) => server));
@@ -1559,12 +1569,14 @@ const skinPluginMembers = computed(() => memberChannels.value.flatMap((item) =>
const skinPluginContext = computed(() => ({
session: {
status: {
connected: voiceState.connected,
connecting: voiceState.connecting,
channelId: currentChannel.value?.id ?? "",
channelName: currentChannelName.value,
userName: nickname.value,
status: {
connected: voiceState.connected,
connecting: voiceState.connecting,
connectionState: voiceState.connected ? "connected" : voiceState.connecting || voiceState.reconnecting ? "connecting" : "disconnected",
channelId: currentChannel.value?.id ?? "",
channelName: currentChannelName.value,
userName: nickname.value,
serverLabel: currentServerDisplayName.value,
},
channels: channelTree.value.map((item) => {
const members = skinPluginMembers.value.filter((member) => member.channelId === item.id);
@@ -1626,13 +1638,19 @@ const skinPluginContext = computed(() => ({
},
}));
const readSkinRuntimeSessionStatus = (_signal: AbortSignal) => ({
connected: voiceState.connected,
channelName: voiceState.connected ? currentChannelName.value : null,
memberCount: skinPluginMembers.value.length,
});
const skinPluginActions = {
const readSkinRuntimeSessionStatus = (_signal: AbortSignal) => ({
connected: voiceState.connected,
channelName: voiceState.connected ? currentChannelName.value : null,
memberCount: skinPluginMembers.value.length,
});
function switchQuickServerByOpaqueId(quickServerId: string): void {
if (accessMode.value !== "open") return;
const target = skinPluginQuickServers.resolve(quickServerId);
if (target && quickServers.value.some((server) => server.id === target.id)) connectQuickServer(target);
}
const skinPluginActions = {
"voice.joinChannel": (args: Record<string, string | number | boolean>) => {
if (!voiceState.connected || typeof args.channelId !== "string") return;
const target = channelTree.value.find((item) => item.id === args.channelId);
@@ -1643,10 +1661,9 @@ const skinPluginActions = {
const target = skinPluginQuickServers.resolve(args.favoriteId);
if (target?.isFavorite && quickServers.value.some((server) => server.id === target.id && server.isFavorite)) connectQuickServer(target);
},
"quickServers.switch": (args: Record<string, string | number | boolean>) => {
if (accessMode.value !== "open" || typeof args.quickServerId !== "string") return;
const target = skinPluginQuickServers.resolve(args.quickServerId);
if (target && quickServers.value.some((server) => server.id === target.id)) connectQuickServer(target);
"quickServers.switch": (args: Record<string, string | number | boolean>) => {
if (typeof args.quickServerId !== "string") return;
switchQuickServerByOpaqueId(args.quickServerId);
},
"chat.sendMessage": (args: Record<string, string | number | boolean>) => {
if (!voiceState.connected || typeof args.text !== "string" || !currentChannel.value?.id) return;
@@ -1742,7 +1759,7 @@ const skinPluginWidgets = {
menuLabel: t("languageMenu"),
onChange: persistLanguage,
}),
"voice.channel-panel": () => h(ChannelMemberPanel, {
"voice.channel-panel": () => h(ChannelMemberPanel, {
query: memberQuery.value,
"onUpdate:query": (value: string) => { memberQuery.value = value; },
model: memberControls,
@@ -1756,8 +1773,21 @@ const skinPluginWidgets = {
rangeStyle,
t,
onSelectChannel: selectChannel,
onVolumeInput: onVolInput,
}),
onVolumeInput: onVolInput,
}),
"voice.server-switcher": () => h(VoiceServerSwitcher, {
servers: skinPluginQuickList.value,
onSwitchServer: switchQuickServerByOpaqueId,
}),
"voice.channel-tree": () => h(VoiceChannelTree, {
channels: channelTree.value,
currentChannelId: currentChannel.value?.id,
avatarStyle,
avatarInitial,
isSpeaking,
t,
onJoin: selectChannel,
}),
"voice.member-cards": (options?: SkinPluginWidgetOptions) => h(VoiceMemberCards, {
currentMembers: currentMembers.value,
isMobileViewport: isMobileViewport.value,