mirror of
https://github.com/EchoSixHIYA/WebSpeak-client-for-TeamSpeak.git
synced 2026-12-03 12:02:50 +08:00
feat(skins): add persistent voice workspace API and align KAAK
This commit is contained in:
1 parent
0af3236c30
commit
452e6f09ca
24 files changed
+451
-21
No files matched your search
@@ -0,0 +1,43 @@
|
||||
<template>
|
||||
<section
|
||||
v-if="!connected"
|
||||
class="voice-connection-status"
|
||||
data-ws-part="voice.connection-status"
|
||||
:data-ws-state="connecting ? 'connecting' : error ? 'failed' : 'disconnected'"
|
||||
>
|
||||
<p role="status" aria-live="polite" data-ws-part="voice.connection-status.message">
|
||||
{{ connecting ? t('connecting') : error || t('voiceHealthDisconnected') }}
|
||||
</p>
|
||||
<label data-ws-part="voice.connection-status.nickname">
|
||||
<span>{{ t('nickname') }}</span>
|
||||
<input
|
||||
:value="nickname"
|
||||
:disabled="connecting"
|
||||
maxlength="30"
|
||||
autocomplete="nickname"
|
||||
data-ws-part="voice.connection-status.nickname.input"
|
||||
@input="$emit('update:nickname', ($event.target as HTMLInputElement).value)"
|
||||
/>
|
||||
</label>
|
||||
<button
|
||||
type="button"
|
||||
:disabled="!canConnect || connecting"
|
||||
data-ws-part="voice.connection-status.reconnect"
|
||||
@click="$emit('connect')"
|
||||
><Icon v-if="connecting" name="refresh" :size="16" />{{ t('reconnectNow') }}</button>
|
||||
</section>
|
||||
</template>
|
||||
|
||||
<script setup lang="ts">
|
||||
import Icon from "../Icon.vue";
|
||||
|
||||
defineProps<{
|
||||
connected: boolean;
|
||||
connecting: boolean;
|
||||
nickname: string;
|
||||
error: string;
|
||||
canConnect: boolean;
|
||||
t: (key: string) => string;
|
||||
}>();
|
||||
defineEmits<{ connect: []; 'update:nickname': [value: string] }>();
|
||||
</script>
|
||||
@@ -0,0 +1,51 @@
|
||||
import { computed, onScopeDispose, ref, watch, type Ref } from "vue";
|
||||
import { saveLocalPreferences, type LocalPreferences, type RecentServer } from "../services/local-persistence.js";
|
||||
|
||||
export interface VoiceWorkspaceSnapshot {
|
||||
preferences: LocalPreferences;
|
||||
recent: readonly RecentServer[];
|
||||
}
|
||||
/** The selected package opts in; persistence and lifecycle remain host-owned. */
|
||||
export function useVoiceWorkspace(options: {
|
||||
enabled: Readonly<Ref<boolean>>;
|
||||
connected: Readonly<Ref<boolean>>;
|
||||
save?: typeof saveLocalPreferences;
|
||||
}) {
|
||||
const hasConnected = ref(false);
|
||||
const active = computed(() => options.enabled.value && hasConnected.value);
|
||||
let epoch = 0;
|
||||
let disposed = false;
|
||||
let pendingSave: AbortController | undefined;
|
||||
function remember() {
|
||||
if (disposed) return;
|
||||
hasConnected.value = true;
|
||||
pendingSave?.abort();
|
||||
pendingSave = new AbortController();
|
||||
void (options.save ?? saveLocalPreferences)({ schemaVersion: 1, hasConnected: true }, pendingSave.signal).catch(() => undefined);
|
||||
}
|
||||
watch(options.connected, connected => { if (connected) remember(); }, { flush: "sync", immediate: true });
|
||||
async function restore(
|
||||
load: () => Promise<VoiceWorkspaceSnapshot>,
|
||||
apply?: (snapshot: VoiceWorkspaceSnapshot) => void,
|
||||
): Promise<VoiceWorkspaceSnapshot | undefined> {
|
||||
const owner = epoch;
|
||||
try {
|
||||
const snapshot = await load();
|
||||
if (disposed || owner !== epoch) return;
|
||||
if (snapshot.preferences.hasConnected === true || snapshot.recent.length > 0) {
|
||||
hasConnected.value = true;
|
||||
if (snapshot.preferences.hasConnected !== true) remember();
|
||||
}
|
||||
apply?.(snapshot);
|
||||
return snapshot;
|
||||
} catch { return undefined; }
|
||||
}
|
||||
function reset() {
|
||||
epoch++;
|
||||
pendingSave?.abort();
|
||||
pendingSave = undefined;
|
||||
hasConnected.value = false;
|
||||
}
|
||||
onScopeDispose(() => { disposed = true; reset(); });
|
||||
return { active, hasConnected, restore, reset };
|
||||
}
|
||||
@@ -1423,6 +1423,7 @@ webClientTranslations.ru = {
|
||||
favoriteSwitching: "Переключение на {{server}}…",
|
||||
favoriteConnectionFailed: "Не удалось подключиться к {{server}}",
|
||||
quickConnectFailed: "Не удалось подключиться. Проверьте адрес сервера и имя.",
|
||||
reconnectNow: "Подключиться снова",
|
||||
removeFavorite: "Удалить из избранного",
|
||||
cancel: "Отмена",
|
||||
close: "Закрыть",
|
||||
@@ -1649,6 +1650,7 @@ webClientTranslations.ja = {
|
||||
networkPerformanceHint: "ブラウザから WebSpeak を経由して TeamSpeak まで継続測定",
|
||||
voiceStatus: "音声状態",
|
||||
voiceStatusHint: "実音声フレームを表示。WebRTC ではブラウザー統計、互換モードではフレーム数を計測。テスト音は送信しません",
|
||||
reconnectNow: "今すぐ再接続",
|
||||
voiceHealthDisconnected: "音声セッション未接続",
|
||||
voiceHealthSampling: "メディア情報を取得中",
|
||||
voiceHealthConnecting: "音声経路を接続中",
|
||||
|
||||
@@ -154,6 +154,8 @@ export interface LocalPreferences {
|
||||
outputVolume?: number;
|
||||
notificationVolume?: number;
|
||||
lastNickname?: string;
|
||||
/** Successful voice connection history, independent of the selected skin. */
|
||||
hasConnected?: boolean;
|
||||
inputDeviceId?: string;
|
||||
volumesByUid?: Record<string, number>;
|
||||
}
|
||||
|
||||
@@ -46,11 +46,11 @@ export const BUILTIN_SKIN_CATALOG: SkinCatalogEntry[] = [
|
||||
{
|
||||
id: BUILTIN_KAAK_SKIN_ID,
|
||||
name: "KAAK",
|
||||
version: "3.1.122",
|
||||
version: "3.1.125",
|
||||
author: "WebSpeak Project",
|
||||
license: "AGPL-3.0-only",
|
||||
description: "A KOOK-inspired WebSpeak skin with a split-screen connection home, searchable server header, TeamSpeak banner, nested channel members, unified chat with local history, and a compact audio dock.",
|
||||
minAppVersion: "0.2.7",
|
||||
minAppVersion: "0.2.8",
|
||||
installedAt: 0,
|
||||
builtIn: true,
|
||||
},
|
||||
|
||||
@@ -486,7 +486,9 @@ 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.122");
|
||||
assert.equal(skin.version, "3.1.125");
|
||||
assert.deepEqual(skin.workspace, { apiVersion: 1, mode: "persistent" });
|
||||
assert.equal(skin.minAppVersion, "0.2.8");
|
||||
assert.equal(BUILTIN_SKIN_CATALOG.find((entry) => entry.id === skin.id)?.version, skin.version);
|
||||
assert.equal(skin.schemaVersion, 3);
|
||||
const baseMessages = skin.contentData?.locales["zh-CN"]?.messages ?? {};
|
||||
@@ -499,6 +501,8 @@ test("the distributable KAAK package provides full home and voice surfaces", asy
|
||||
}
|
||||
const home = skin.pluginData?.components.find((component) => component.page === "home");
|
||||
const voice = skin.pluginData?.components.find((component) => component.page === "voice");
|
||||
assert.ok(voice?.permissions.includes("voice.connect"));
|
||||
assert.match(JSON.stringify(voice?.root), /"widget":"voice.connection-status"/);
|
||||
assert.deepEqual(skin.pluginData?.components.map((component) => [component.id, component.mode]), [
|
||||
["kaak-home", "surface"],
|
||||
["kaak-workspace", "surface"],
|
||||
|
||||
@@ -1,3 +1,4 @@
|
||||
import { parseSkinWorkspacePolicy, type SkinWorkspacePolicy } from "../../../src/shared/skin-workspace.js";
|
||||
import { unzipSync } from "fflate";
|
||||
import { compileSkinCss as compileSharedSkinCss, rewriteSkinCssAssets, SkinCssValidationError } from "../../../src/shared/skin-css.js";
|
||||
|
||||
@@ -38,6 +39,7 @@ export interface SkinManifest {
|
||||
content?: string;
|
||||
components?: string;
|
||||
plugins?: string;
|
||||
workspace?: SkinWorkspacePolicy;
|
||||
minAppVersion: string;
|
||||
preview?: string;
|
||||
}
|
||||
@@ -405,7 +407,7 @@ function parseManifest(bytes: Uint8Array): SkinManifest {
|
||||
if (schemaVersion !== 1 && schemaVersion !== 2 && schemaVersion !== 3 && schemaVersion !== 4) throw new SkinPackError("This skin package version is not supported.", "SKIN_SCHEMA_VERSION");
|
||||
if (schemaVersion >= 2) {
|
||||
const fields = new Set(["schemaVersion", "packageType", "id", "name", "version", "author", "license", "description", "entry", "layout", "permissions", "content", "minAppVersion", "preview"]);
|
||||
if (schemaVersion >= 3) { fields.delete("permissions"); fields.add("components"); }
|
||||
if (schemaVersion >= 3) { fields.delete("permissions"); fields.add("components"); fields.add("workspace"); }
|
||||
if (schemaVersion === 4) fields.add("plugins");
|
||||
const unknown = Object.keys(raw).find((key) => !fields.has(key));
|
||||
if (unknown) throw new SkinPackError(`Version 2 skin manifest contains an unsupported field: ${unknown}.`, "SKIN_MANIFEST_INVALID");
|
||||
@@ -428,6 +430,9 @@ function parseManifest(bytes: Uint8Array): SkinManifest {
|
||||
if (schemaVersion === 1 && (raw.layout !== undefined || raw.packageType !== undefined || raw.permissions !== undefined || raw.components !== undefined || raw.plugins !== undefined)) {
|
||||
throw new SkinPackError("Version 1 skin packages cannot declare layout or plugin fields.", "SKIN_SCHEMA_VERSION");
|
||||
}
|
||||
let workspace: SkinWorkspacePolicy | undefined;
|
||||
try { workspace = parseSkinWorkspacePolicy(raw.workspace, schemaVersion); }
|
||||
catch (error) { throw new SkinPackError(error instanceof Error ? error.message : "Invalid workspace policy.", "SKIN_MANIFEST_INVALID"); }
|
||||
const id = stringField("id", 80)!;
|
||||
if (!/^[a-z0-9](?:[a-z0-9.-]*[a-z0-9])?$/.test(id) || id.startsWith("builtin.")) throw new SkinPackError("Skin IDs must be unique lowercase IDs and cannot use the reserved builtin. prefix.", "SKIN_ID_INVALID");
|
||||
const entry = stringField("entry", 120)!;
|
||||
@@ -461,6 +466,7 @@ function parseManifest(bytes: Uint8Array): SkinManifest {
|
||||
components,
|
||||
plugins,
|
||||
minAppVersion,
|
||||
...(workspace ? { workspace } : {}),
|
||||
preview,
|
||||
};
|
||||
}
|
||||
|
||||
@@ -8338,3 +8338,13 @@
|
||||
padding: 8px;
|
||||
}
|
||||
}
|
||||
|
||||
/* Public voice.connection-status widget; package CSS controls its placement. */
|
||||
:deep(.voice-connection-status) { display: flex; align-items: center; flex-wrap: wrap; gap: 12px; min-width: 0; padding: 14px; border: 1px solid var(--border,#dfe8e5); border-radius: 12px; background: var(--surface,#fff); color: var(--text,#20302c); }
|
||||
:deep(.voice-connection-status p) { flex: 1 1 180px; margin: 0; overflow-wrap: anywhere; font-size: 13px; }
|
||||
:deep(.voice-connection-status label) { display: grid; gap: 4px; width: 150px; max-width: 100%; font-size: 11px; }
|
||||
:deep(.voice-connection-status input) { min-width: 0; width: 100%; padding: 8px 10px; border: 1px solid var(--border,#dfe8e5); border-radius: 7px; background: var(--surface,#fff); color: inherit; font: inherit; font-size: 13px; }
|
||||
:deep(.voice-connection-status button) { display: inline-flex; align-items: center; gap: 7px; min-height: 44px; padding: 9px 14px; border: 0; border-radius: 8px; background: var(--accent,#087d74); color: #fff; cursor: pointer; }
|
||||
:deep(.voice-connection-status button:disabled) { opacity: .5; cursor: not-allowed; }
|
||||
:deep(.voice-connection-status input:focus-visible), :deep(.voice-connection-status button:focus-visible) { outline: 3px solid var(--accent,#087d74); outline-offset: 2px; }
|
||||
.workspace-connection-status { position: fixed; z-index: 40; top: 12px; left: 50%; transform: translateX(-50%); width: min(640px,calc(100% - 28px)); }
|
||||
@@ -54,6 +54,18 @@
|
||||
@surface-change="skinRuntimePluginSurfaceActive = $event"
|
||||
@restore-skin="switchToBuiltIn"
|
||||
/>
|
||||
<VoiceConnectionStatus
|
||||
v-if="voiceWorkspace.active.value && !skinPluginSurfaceActive && !skinRuntimePluginSurfaceActive && !favoriteServerDialogOpen && !serverPasswordDialog.open"
|
||||
class="workspace-connection-status"
|
||||
:connected="voiceState.connected"
|
||||
:connecting="voiceConnectionBusy"
|
||||
:nickname="nickname"
|
||||
:error="voiceConnectionError"
|
||||
:can-connect="canRequestVoiceConnection"
|
||||
:t="t"
|
||||
@update:nickname="nickname = $event"
|
||||
@connect="requestVoiceConnection"
|
||||
/>
|
||||
<!-- Connection / welcome screen -->
|
||||
<section
|
||||
v-if="!showVoiceShell && !skinPluginSurfaceActive && !skinRuntimePluginSurfaceActive"
|
||||
@@ -951,6 +963,8 @@
|
||||
import { observeMobileViewport } from "../services/mobile-viewport.js";
|
||||
import { computed, h, onMounted, onUnmounted, reactive, ref, shallowRef, watch } from "vue";
|
||||
import Icon from "../components/Icon.vue";
|
||||
import VoiceConnectionStatus from "../components/web-client/VoiceConnectionStatus.vue";
|
||||
import { useVoiceWorkspace } from "../composables/useVoiceWorkspace.js";
|
||||
import SkinPluginOutlet from "../components/SkinPluginOutlet.js";
|
||||
import SkinPluginEditor from "../components/SkinPluginEditor.vue";
|
||||
import SkinRuntimePluginHost from "../components/SkinRuntimePluginHost.js";
|
||||
@@ -1165,6 +1179,7 @@ const {
|
||||
} = useWebClientIdentity({ identityMaterial, rememberIdentity, t, showToast });
|
||||
const {
|
||||
quickServers,
|
||||
recentServers,
|
||||
isFavorite,
|
||||
loadSavedServers,
|
||||
recordCurrentServer,
|
||||
@@ -1423,7 +1438,20 @@ const {
|
||||
t,
|
||||
});
|
||||
|
||||
const voiceWorkspace = useVoiceWorkspace({
|
||||
enabled: computed(() => activeSkin.value?.workspace?.apiVersion === 1 && activeSkin.value.workspace.mode === "persistent"),
|
||||
connected: computed(() => voiceState.connected),
|
||||
});
|
||||
const voiceConnectionBusy = computed(() => voiceState.connecting || voiceState.reconnecting || favoriteSwitchPending.value);
|
||||
const voiceConnectionError = computed(() => voiceState.error ? localizedMessage(voiceState.error) : favoriteSwitchError.value);
|
||||
const canRequestVoiceConnection = computed(() => canJoin.value && !serverConfigLoading.value && identityReady.value
|
||||
&& !voiceState.connected && !voiceConnectionBusy.value);
|
||||
function requestVoiceConnection(): void {
|
||||
if (!canRequestVoiceConnection.value || favoriteServerDialogOpen.value || serverPasswordDialog.open) return;
|
||||
beginFavoriteConnection();
|
||||
}
|
||||
const showVoiceShell = computed(() => Boolean(
|
||||
voiceWorkspace.active.value ||
|
||||
voiceState.connected || voiceState.reconnecting || voiceState.reconnectFailed
|
||||
|| favoriteSwitchPending.value || favoriteSwitchFailed.value,
|
||||
));
|
||||
@@ -1455,6 +1483,7 @@ const quickServersForDisplay = computed(() => quickServers.value.map((server) =>
|
||||
}));
|
||||
|
||||
function connectQuickServer(server: QuickServer): void {
|
||||
if (serverConfigLoading.value || !identityReady.value) return;
|
||||
if ((voiceState.connecting || voiceState.connected) && isQuickServerTarget(server)) return;
|
||||
if (accessMode.value !== "open") {
|
||||
showToast(t("serverSwitchRestricted"));
|
||||
@@ -1483,8 +1512,11 @@ function beginFavoriteConnection(): void {
|
||||
favoriteSwitchPending.value = true;
|
||||
favoriteSwitchFailed.value = false;
|
||||
favoriteSwitchError.value = "";
|
||||
if (!canJoin.value) {
|
||||
failFavoriteConnection(t("quickConnectFailed"));
|
||||
return;
|
||||
}
|
||||
doConnect();
|
||||
if (!voiceState.connecting && !voiceState.connected) failFavoriteConnection(t("quickConnectFailed"));
|
||||
}
|
||||
|
||||
function failFavoriteConnection(message: string): void {
|
||||
@@ -1514,12 +1546,12 @@ function openFavoriteServerDialog(): void {
|
||||
showToast(t("serverFeatureAdminDisabled"));
|
||||
return;
|
||||
}
|
||||
if (!showVoiceShell.value || voiceState.connecting || favoriteDialogBusy.value) return;
|
||||
if (!showVoiceShell.value || serverConfigLoading.value || !identityReady.value || voiceState.connecting || favoriteDialogBusy.value) return;
|
||||
favoriteServerDialogOpen.value = true;
|
||||
}
|
||||
|
||||
async function submitFavoriteServerDraft(draft: FavoriteServerDraft): Promise<void> {
|
||||
if (favoriteDialogBusy.value || voiceState.connecting || accessMode.value !== "open") return;
|
||||
if (favoriteDialogBusy.value || serverConfigLoading.value || !identityReady.value || voiceState.connecting || accessMode.value !== "open") return;
|
||||
const port = draft.port || DEFAULT_TEAM_SPEAK_PORT;
|
||||
if (!draft.address || !draft.nickname || !isValidTeamSpeakPort(port)) {
|
||||
showToast(t("quickConnectFailed"));
|
||||
@@ -1732,7 +1764,8 @@ const skinPluginActions = {
|
||||
if (!Number.isFinite(volume)) return;
|
||||
setOutputVolume(Math.max(0, Math.min(1, volume)));
|
||||
},
|
||||
"voice.disconnect": () => { if (voiceState.connected || voiceState.connecting) doDisconnect(); },
|
||||
"voice.connect": () => requestVoiceConnection(),
|
||||
"voice.disconnect": () => { if (voiceState.connected || voiceState.connecting || favoriteSwitchPending.value) leaveVoiceWorkspace(); },
|
||||
"voice.setAway": (args: Record<string, string | number | boolean>) => {
|
||||
if (!voiceState.connected || typeof args.away !== "boolean") return;
|
||||
const message = typeof args.message === "string" ? args.message.slice(0, 200) : "";
|
||||
@@ -1998,6 +2031,16 @@ const skinPluginWidgets = {
|
||||
showScreenShare: options?.screenShare !== false,
|
||||
t,
|
||||
}),
|
||||
"voice.connection-status": () => favoriteServerDialogOpen.value || serverPasswordDialog.open ? null : h(VoiceConnectionStatus, {
|
||||
connected: voiceState.connected,
|
||||
connecting: voiceConnectionBusy.value,
|
||||
nickname: nickname.value,
|
||||
"onUpdate:nickname": (value: string) => { if (!voiceConnectionBusy.value) nickname.value = value; },
|
||||
error: voiceConnectionError.value,
|
||||
canConnect: canRequestVoiceConnection.value,
|
||||
t,
|
||||
onConnect: requestVoiceConnection,
|
||||
}),
|
||||
"voice.connection-controls": () => h("div", { class: "ws-plugin-connection-controls", role: "toolbar", "aria-label": t("desktopAudioControls") }, [
|
||||
h("button", { type: "button", "aria-label": t("copyInvite"), title: t("copyInvite"), onClick: doShare }, [h(Icon, { name: "share", size: 18 })]),
|
||||
...(accessMode.value === "open" ? [h("button", {
|
||||
@@ -2102,10 +2145,20 @@ onMounted(() => {
|
||||
// The selected skin is applied to this public root, never to the admin DOM.
|
||||
applyTheme(themeMode.value);
|
||||
browserError.value = checkSupport() ?? "";
|
||||
void loadPublicConfig();
|
||||
void initializeSkin();
|
||||
void loadLocalPreferences().then((preferences) => {
|
||||
void voiceWorkspace.restore(async () => {
|
||||
const [, , , preferences] = await Promise.all([loadPublicConfig(), initializeSkin(), loadSavedServers(), loadLocalPreferences()]);
|
||||
return { preferences, recent: [...recentServers.value] };
|
||||
}, (snapshot) => {
|
||||
const { preferences, recent } = snapshot;
|
||||
if (!localStorage.getItem("webspeak:language") && (preferences.language === "zh" || preferences.language === "en" || preferences.language === "de" || preferences.language === "ru" || preferences.language === "ja")) language.value = preferences.language;
|
||||
if (!nickname.value.trim()) nickname.value = preferences.lastNickname || recent[0]?.nickname || "";
|
||||
const hasInvite = ["invite", "server", "target", "tsHost", "tsPort", "channel"].some(key => query.has(key));
|
||||
if (voiceWorkspace.active.value && !hasInvite && accessMode.value === "open"
|
||||
&& !voiceState.connected && !voiceState.connecting && !favoriteSwitchPending.value
|
||||
&& !favoriteServerDialogOpen.value && !serverPasswordDialog.open) {
|
||||
const latest = recent[0];
|
||||
if (latest) selectLocalServer(latest.address, latest.nickname, latest.lastChannelHint?.name);
|
||||
}
|
||||
});
|
||||
void restoreIdentity(async () => {
|
||||
const stored = await loadStoredIdentity();
|
||||
@@ -2113,7 +2166,6 @@ onMounted(() => {
|
||||
}).finally(() => {
|
||||
identityReady.value = true;
|
||||
});
|
||||
void loadSavedServers();
|
||||
deviceChangeHandler = () => { void refreshAudioDevices().catch(() => undefined); };
|
||||
navigator.mediaDevices?.addEventListener("devicechange", deviceChangeHandler);
|
||||
viewportMediaQuery = window.matchMedia("(max-width: 740px)");
|
||||
@@ -2161,6 +2213,7 @@ async function clearBrowserData(): Promise<void> {
|
||||
if (!window.confirm(t("clearLocalDataConfirm"))) return;
|
||||
resetIdentityOperations();
|
||||
publicSkin.cancel();
|
||||
voiceWorkspace.reset();
|
||||
await clearStoredLocalData();
|
||||
for (const key of ["webspeak:nickname", "webspeak:language", "webspeak:theme", "webspeak:active-skin", "webspeak:skin-choice", "webspeak:input-device", "webspeak:output-device", "webspeak:remember-identity"]) localStorage.removeItem(key);
|
||||
await publicSkin.reset();
|
||||
|
||||
Reference in new issue
Block a user