mirror of
https://github.com/EchoSixHIYA/WebSpeak-client-for-TeamSpeak.git
synced 2026-12-03 03:52:50 +08:00
feat: complete runtime and KAAK skin updates
This commit is contained in:
1 parent
c994722016
commit
7fd1ea96fe
40 files changed
+3436
-1088
No files matched your search
+108
-30
@@ -146,8 +146,29 @@ test("server list skins may display only the host-provided TeamSpeak icon image"
|
||||
document.components[0].root.children![0].tag = "span";
|
||||
errorCode(() => parseSkinPluginDocument(document), "SKIN_PLUGIN_ATTRIBUTE_INVALID");
|
||||
});
|
||||
|
||||
test("host widget references stay allowlisted and cannot be used on the demo page", () => {
|
||||
|
||||
test("chat panel visibility is host-controlled and its toggle requires chat access", () => {
|
||||
const document = validDocument();
|
||||
document.schemaVersion = 3;
|
||||
document.components[0].permissions = ["chat.channel.read"];
|
||||
document.components[0].actions = {
|
||||
toggle: { type: "chat.togglePanel", args: {} },
|
||||
};
|
||||
document.components[0].root = {
|
||||
tag: "button",
|
||||
attributes: { "aria-expanded": "{{chat.status.panelOpen}}" },
|
||||
events: { click: "toggle" },
|
||||
children: [{ text: "{{chat.status.tabLabel}}" }],
|
||||
};
|
||||
const parsed = parseSkinPluginDocument(document).components[0];
|
||||
assert.equal(parsed.actions.toggle.type, "chat.togglePanel");
|
||||
assert.equal(parsed.root.attributes?.["aria-expanded"], "{{chat.status.panelOpen}}");
|
||||
|
||||
document.components[0].permissions = [];
|
||||
errorCode(() => parseSkinPluginDocument(document), "SKIN_PLUGIN_PERMISSION_MISSING");
|
||||
});
|
||||
|
||||
test("host widget references stay allowlisted and cannot be used on the demo page", () => {
|
||||
const unknownWidget = validDocument();
|
||||
unknownWidget.schemaVersion = 2;
|
||||
unknownWidget.components[0].root = { tag: "main", children: [{ widget: "filesystem.read" as never }] };
|
||||
@@ -197,17 +218,21 @@ test("home connection status widget requires the public session status permissio
|
||||
assert.deepEqual(skinPluginWidgetPermissions("home.connection-status"), ["session.status.read"]);
|
||||
});
|
||||
|
||||
test("MyTS login is a host button with no connection permission or skin action", () => {
|
||||
test("generic identity-provider entry is a host button with no connection permission or skin action", () => {
|
||||
const document = validDocument();
|
||||
document.schemaVersion = 3;
|
||||
document.components[0].page = "home";
|
||||
document.components[0].permissions = [];
|
||||
document.components[0].actions = {};
|
||||
document.components[0].root = { tag: "main", children: [{ widget: "home.myts-login" }] };
|
||||
document.components[0].root = {
|
||||
tag: "main",
|
||||
children: [{ widget: "home.identity-provider", options: { identityProviderId: "myts", identityProviderLabel: "myts" } }],
|
||||
};
|
||||
|
||||
const parsed = parseSkinPluginDocument(document);
|
||||
assert.equal(parsed.components[0].root.children?.[0].widget, "home.myts-login");
|
||||
assert.deepEqual(skinPluginWidgetPermissions("home.myts-login"), []);
|
||||
assert.equal(parsed.components[0].root.children?.[0].widget, "home.identity-provider");
|
||||
assert.deepEqual(parsed.components[0].root.children?.[0].options, { identityProviderId: "myts", identityProviderLabel: "myts" });
|
||||
assert.deepEqual(skinPluginWidgetPermissions("home.identity-provider"), []);
|
||||
assert.deepEqual(Object.keys(parsed.components[0].actions), []);
|
||||
});
|
||||
|
||||
@@ -241,13 +266,13 @@ test("schema v3 host audio controls require read and control permissions while v
|
||||
errorCode(() => parseSkinPluginDocument(document), "SKIN_PLUGIN_PERMISSION_MISSING");
|
||||
|
||||
document.components[0].permissions = ["audio.status.read", "audio.microphone.control", "audio.output.control"];
|
||||
document.components[0].root.children![0] = { widget: "voice.audio-controls", options: { layout: "room-panel" } };
|
||||
const roomPanel = parseSkinPluginDocument(document).components[0].root.children?.[0];
|
||||
assert.equal(roomPanel?.widget, "voice.audio-controls");
|
||||
assert.deepEqual(roomPanel?.options, { layout: "room-panel" });
|
||||
document.components[0].root.children![0] = { widget: "voice.audio-controls" };
|
||||
const genericAudioControls = parseSkinPluginDocument(document).components[0].root.children?.[0];
|
||||
assert.equal(genericAudioControls?.widget, "voice.audio-controls");
|
||||
assert.equal(genericAudioControls?.options, undefined);
|
||||
|
||||
const invalidLayout = structuredClone(document);
|
||||
invalidLayout.components[0].root.children![0] = { widget: "voice.audio-controls", options: { layout: "custom" } as never };
|
||||
invalidLayout.components[0].root.children![0] = { widget: "voice.audio-controls", options: { layout: "room-panel" } as never };
|
||||
errorCode(() => parseSkinPluginDocument(invalidLayout), "SKIN_PLUGIN_WIDGET_OPTIONS_INVALID");
|
||||
|
||||
const legacyDocument = structuredClone(document);
|
||||
@@ -269,6 +294,32 @@ test("schema v3 member cards require a separate permission to display cached pro
|
||||
assert.equal(parseSkinPluginDocument(document).components[0].root.children?.[0].widget, "voice.member-cards");
|
||||
});
|
||||
|
||||
test("generic home identity-provider widget validates provider metadata", () => {
|
||||
const document = validDocument();
|
||||
document.schemaVersion = 3;
|
||||
document.components[0].page = "home";
|
||||
document.components[0].permissions = [];
|
||||
document.components[0].actions = {};
|
||||
document.components[0].root = {
|
||||
tag: "main",
|
||||
children: [{ widget: "home.identity-provider", options: { identityProviderId: "myts", identityProviderLabel: "myts" } }],
|
||||
};
|
||||
const widget = parseSkinPluginDocument(document).components[0].root.children?.[0];
|
||||
assert.equal(widget?.widget, "home.identity-provider");
|
||||
assert.deepEqual(widget?.options, { identityProviderId: "myts", identityProviderLabel: "myts" });
|
||||
|
||||
const missing = structuredClone(document);
|
||||
missing.components[0].root.children![0] = { widget: "home.identity-provider" };
|
||||
errorCode(() => parseSkinPluginDocument(missing), "SKIN_PLUGIN_WIDGET_OPTIONS_INVALID");
|
||||
|
||||
const invalidProvider = structuredClone(document);
|
||||
invalidProvider.components[0].root.children![0] = {
|
||||
widget: "home.identity-provider",
|
||||
options: { identityProviderId: "myts/login", identityProviderLabel: "myts" } as never,
|
||||
};
|
||||
errorCode(() => parseSkinPluginDocument(invalidProvider), "SKIN_PLUGIN_WIDGET_OPTIONS_INVALID");
|
||||
});
|
||||
|
||||
test("schema v3 scopes local UI state only to approved public scalar context fields", () => {
|
||||
const document = validDocument();
|
||||
document.schemaVersion = 3;
|
||||
@@ -431,14 +482,22 @@ test("KAAK v3 example declares the connection home and complete voice workspace"
|
||||
assert.equal(home.page, "home");
|
||||
assert.equal(home.mode, "surface");
|
||||
assert.deepEqual(home.permissions, ["ui.surface.replace", "session.status.read"]);
|
||||
const homeSocialLinks = home.root.children?.at(-2);
|
||||
assert.equal(homeSocialLinks?.part, "home-social-links");
|
||||
assert.equal(homeSocialLinks?.widget, "home.social-links");
|
||||
assert.equal(home.root.children?.at(-1)?.part, "home-language", "social icons appear immediately to the left of the language switcher");
|
||||
const connectionCard = home.root.children?.[1].children?.[0].children?.[1];
|
||||
assert.equal(connectionCard?.part, "connection-card");
|
||||
assert.equal(connectionCard?.children?.[0].part, "card-heading");
|
||||
assert.equal(connectionCard?.children?.[0].children?.[0].part, "connection-title");
|
||||
assert.equal(connectionCard?.children?.[0].children?.[1].widget, "home.myts-login");
|
||||
assert.equal(connectionCard?.children?.[0].children?.[1].widget, "home.identity-provider");
|
||||
assert.deepEqual(connectionCard?.children?.[0].children?.[1].options, { identityProviderId: "myts", identityProviderLabel: "myts" });
|
||||
assert.equal(connectionCard?.children?.[2].widget, "home.connection-form");
|
||||
assert.equal(connectionCard?.children?.[4].widget, "home.connection-status");
|
||||
const heroMedia = home.root.children?.[0].children?.[2];
|
||||
const serverAnnouncement = home.root.children?.[0].children?.[2];
|
||||
assert.equal(serverAnnouncement?.part, "server-announcement");
|
||||
assert.equal(serverAnnouncement?.widget, "home.server-announcement");
|
||||
const heroMedia = home.root.children?.[0].children?.[3];
|
||||
assert.equal(heroMedia?.part, "hero-media");
|
||||
assert.equal(heroMedia?.children?.[0].tag, "svg");
|
||||
|
||||
@@ -451,14 +510,15 @@ test("KAAK v3 example declares the connection home and complete voice workspace"
|
||||
assert.ok(workspace.permissions.includes("session.channel.join"));
|
||||
assert.ok(workspace.permissions.includes("servers.quickList.read"));
|
||||
assert.ok(workspace.permissions.includes("servers.quickList.switch"));
|
||||
assert.ok(workspace.permissions.includes("chat.channel.send"));
|
||||
assert.ok(workspace.permissions.includes("chat.channel.read"));
|
||||
assert.ok(workspace.permissions.includes("chat.channel.send"));
|
||||
assert.ok(workspace.permissions.includes("audio.microphone.control"));
|
||||
assert.ok(workspace.permissions.includes("voice.screenShare.control"));
|
||||
assert.ok(workspace.permissions.includes("voice.screenShare.read"));
|
||||
assert.ok(workspace.permissions.includes("voice.screenShare.status.read"));
|
||||
assert.equal(workspace.actions["stop-screen-share"].type, "voice.stopScreenShare");
|
||||
assert.equal(workspace.actions["join-channel"], undefined, "channel joining is handled by the trusted tree widget");
|
||||
assert.equal(workspace.actions["send-message"].type, "chat.sendMessage");
|
||||
assert.equal(workspace.actions["toggle-chat-panel"].type, "chat.togglePanel");
|
||||
|
||||
const nodes: SkinPluginNode[] = [];
|
||||
const visit = (node: SkinPluginNode): void => {
|
||||
@@ -466,17 +526,23 @@ test("KAAK v3 example declares the connection home and complete voice workspace"
|
||||
node.children?.forEach(visit);
|
||||
};
|
||||
visit(workspace.root);
|
||||
assert.ok(nodes.some((node) => node.widget === "voice.audio-controls"));
|
||||
assert.ok(nodes.some((node) => node.widget === "voice.member-cards"));
|
||||
assert.ok(nodes.some((node) => node.widget === "voice.audio-controls" && node.options?.layout === "room-panel"));
|
||||
assert.ok(nodes.some((node) => node.part === "desktop-room-controls" && node.tag === "div"), "the desktop audio dock is composed in the skin document");
|
||||
assert.ok(nodes.some((node) => node.part === "desktop-room-noise-suppression" && node.events?.click === "toggle-noise-suppression"));
|
||||
assert.ok(nodes.some((node) => node.part === "desktop-room-accompaniment" && node.events?.click === "toggle-accompaniment"));
|
||||
assert.ok(nodes.some((node) => node.part === "mobile-room-controls" && node.tag === "div"), "the mobile room toolbar is composed in the skin document");
|
||||
assert.ok(nodes.some((node) => node.part === "mobile-room-microphone" && node.events?.click === "toggle-microphone"));
|
||||
assert.ok(nodes.some((node) => node.part === "mobile-room-speaker" && node.events?.click === "open-audio-settings"));
|
||||
assert.ok(nodes.some((node) => node.part === "mobile-room-exit" && node.events?.click === "disconnect"));
|
||||
assert.ok(nodes.some((node) => node.widget === "voice.server-header"), "the server header exposes trusted search and quick switching");
|
||||
assert.ok(nodes.some((node) => node.widget === "voice.channel-tree" && node.options?.layout === "server-sidebar"), "the KAAK channel tree opts into its isolated sidebar layout");
|
||||
assert.equal(nodes.find((node) => node.part === "record-placeholder"), undefined, "the KAAK voice dock does not expose a recording control");
|
||||
assert.ok(nodes.some((node) => node.widget === "voice.screen-share-start"), "the voice dock exposes WebSpeak screen sharing");
|
||||
assert.ok(nodes.some((node) => node.widget === "voice.screen-share-player"), "the voice stage keeps WebSpeak's screen-share player");
|
||||
assert.ok(nodes.some((node) => node.widget === "voice.chat-panel"), "KAAK uses the unified host chat panel for channel, server, and private messages");
|
||||
assert.equal(nodes.find((node) => node.part === "screen-share-stop")?.events?.click, "stop-screen-share");
|
||||
assert.ok(!nodes.some((node) => node.repeat?.path === "session.members"), "member imagery stays inside the trusted host widget");
|
||||
assert.ok(nodes.some((node) => node.tag === "input" && node.bindValue === "message"));
|
||||
assert.ok(!nodes.some((node) => node.tag === "input" && node.bindValue === "message"), "chat input state stays in the host-owned panel");
|
||||
});
|
||||
|
||||
test("skin plugin binds form controls only to declared local state", () => {
|
||||
@@ -625,14 +691,15 @@ test("component schema v3 exposes composable interaction patterns and permission
|
||||
const document = validDocument();
|
||||
document.schemaVersion = 3;
|
||||
document.components[0].permissions = [
|
||||
"audio.microphone.control", "audio.output.control", "audio.status.read", "voice.disconnect", "voice.presence.write",
|
||||
"audio.microphone.control", "audio.output.control", "audio.status.read", "audio.settings.open", "voice.disconnect", "voice.presence.write",
|
||||
"voice.whisper.control", "voice.whisper.status.read", "voice.screenShare.control", "voice.screenShare.read", "voice.screenShare.status.read",
|
||||
];
|
||||
document.components[0].state = { menuopen: false, volume: 0.5, awaymessage: "" };
|
||||
document.components[0].actions = {
|
||||
"toggle-menu": { type: "ui.toggleState", args: { key: "menuopen" } },
|
||||
microphone: { type: "voice.toggleMicrophone", args: {} },
|
||||
speaker: { type: "voice.toggleOutputMute", args: {} },
|
||||
document.components[0].state = { menuopen: false, chatopen: true, volume: 0.5, awaymessage: "" };
|
||||
document.components[0].actions = {
|
||||
"toggle-menu": { type: "ui.toggleState", args: { key: "menuopen", resetKey: "chatopen" } },
|
||||
microphone: { type: "voice.toggleMicrophone", args: {} },
|
||||
speaker: { type: "voice.toggleOutputMute", args: {} },
|
||||
settings: { type: "audio.openSettings", args: {} },
|
||||
volume: { type: "voice.setOutputVolume", args: { volume: "{{state.volume}}" } },
|
||||
disconnect: { type: "voice.disconnect", args: {} },
|
||||
away: { type: "voice.setAway", args: { away: true, message: "{{state.awaymessage}}" } },
|
||||
@@ -648,7 +715,8 @@ test("component schema v3 exposes composable interaction patterns and permission
|
||||
children: [
|
||||
{ tag: "button", events: { contextmenu: "toggle-menu", pointerenter: "toggle-menu" }, children: [{ text: "Menu" }] },
|
||||
{ tag: "button", events: { click: "microphone" }, children: [{ text: "Microphone" }] },
|
||||
{ tag: "button", events: { click: "speaker" }, children: [{ text: "Speaker" }] },
|
||||
{ tag: "button", events: { click: "speaker" }, children: [{ text: "Speaker" }] },
|
||||
{ tag: "button", events: { click: "settings" }, children: [{ text: "Audio settings" }] },
|
||||
{ tag: "button", events: { click: "volume" }, children: [{ text: "Volume" }] },
|
||||
{ tag: "button", events: { click: "disconnect" }, children: [{ text: "Disconnect" }] },
|
||||
{ tag: "button", events: { click: "away" }, children: [{ text: "Away" }] },
|
||||
@@ -664,16 +732,26 @@ test("component schema v3 exposes composable interaction patterns and permission
|
||||
const parsed = parseSkinPluginDocument(document);
|
||||
assert.equal(parsed.schemaVersion, 3);
|
||||
assert.equal(parsed.components[0].root.children?.[0].events?.contextmenu, "toggle-menu");
|
||||
assert.equal(parsed.components[0].actions["join-share"].type, "voice.joinScreenShare");
|
||||
assert.equal(parsed.components[0].root.children?.[9].repeat?.path, "screenShare.streams");
|
||||
assert.equal(parsed.components[0].actions["join-share"].type, "voice.joinScreenShare");
|
||||
assert.equal(parsed.components[0].actions.settings.type, "audio.openSettings");
|
||||
assert.equal(parsed.components[0].actions["toggle-menu"].args.resetKey, "chatopen");
|
||||
assert.equal(parsed.components[0].root.children?.[10].repeat?.path, "screenShare.streams");
|
||||
|
||||
const invalidResetKey = structuredClone(document);
|
||||
invalidResetKey.components[0].actions["toggle-menu"].args.resetKey = "missing";
|
||||
errorCode(() => parseSkinPluginDocument(invalidResetKey), "SKIN_PLUGIN_ACTION_INVALID");
|
||||
|
||||
const passiveVoiceControl = structuredClone(document);
|
||||
passiveVoiceControl.components[0].root.children![0].events = { pointerenter: "microphone" };
|
||||
errorCode(() => parseSkinPluginDocument(passiveVoiceControl), "SKIN_PLUGIN_EVENT_INVALID");
|
||||
|
||||
const missingPermission = structuredClone(document);
|
||||
missingPermission.components[0].permissions = missingPermission.components[0].permissions.filter((item) => item !== "audio.microphone.control");
|
||||
errorCode(() => parseSkinPluginDocument(missingPermission), "SKIN_PLUGIN_PERMISSION_MISSING");
|
||||
const missingPermission = structuredClone(document);
|
||||
missingPermission.components[0].permissions = missingPermission.components[0].permissions.filter((item) => item !== "audio.microphone.control");
|
||||
errorCode(() => parseSkinPluginDocument(missingPermission), "SKIN_PLUGIN_PERMISSION_MISSING");
|
||||
|
||||
const missingAudioSettingsPermission = structuredClone(document);
|
||||
missingAudioSettingsPermission.components[0].permissions = missingAudioSettingsPermission.components[0].permissions.filter((item) => item !== "audio.settings.open");
|
||||
errorCode(() => parseSkinPluginDocument(missingAudioSettingsPermission), "SKIN_PLUGIN_PERMISSION_MISSING");
|
||||
|
||||
const oldSchema = structuredClone(document);
|
||||
oldSchema.schemaVersion = 2;
|
||||
|
||||
+70
-33
@@ -25,9 +25,10 @@ export const SKIN_PLUGIN_PERMISSIONS = Object.freeze({
|
||||
"servers.quickList.read": Object.freeze({ policyVersion: 1, description: "Read favorite and recent server labels, public server icons, and opaque local identifiers, without server addresses or credentials." }),
|
||||
"servers.quickList.switch": Object.freeze({ policyVersion: 1, description: "Switch to a user-selected favorite or recent server through the host connection flow." }),
|
||||
"session.channel.join": Object.freeze({ policyVersion: 1, description: "Request joining a visible TeamSpeak channel through the host; the demo page only changes simulated state." }),
|
||||
"audio.status.read": Object.freeze({ policyVersion: 1, description: "Read the user's own microphone and speaker mute states." }),
|
||||
"audio.microphone.control": Object.freeze({ policyVersion: 1, description: "Toggle the user's own microphone through WebSpeak's audio pipeline." }),
|
||||
"audio.output.control": Object.freeze({ policyVersion: 1, description: "Toggle or adjust the user's local speaker output." }),
|
||||
"audio.status.read": Object.freeze({ policyVersion: 1, description: "Read the user's own microphone and speaker mute states." }),
|
||||
"audio.microphone.control": Object.freeze({ policyVersion: 1, description: "Toggle the user's own microphone through WebSpeak's audio pipeline." }),
|
||||
"audio.output.control": Object.freeze({ policyVersion: 1, description: "Toggle or adjust the user's local speaker output." }),
|
||||
"audio.settings.open": Object.freeze({ policyVersion: 1, description: "Open WebSpeak's trusted audio device and processing settings." }),
|
||||
"voice.presence.write": Object.freeze({ policyVersion: 1, description: "Set the user's own away status through the connected TeamSpeak session." }),
|
||||
"voice.whisper.control": Object.freeze({ policyVersion: 1, description: "Enable or disable the user's existing TeamSpeak whisper target selection." }),
|
||||
"voice.disconnect": Object.freeze({ policyVersion: 1, description: "Disconnect the user's current TeamSpeak voice session." }),
|
||||
@@ -43,7 +44,9 @@ export type SkinPluginComponentMode = "widget" | "surface";
|
||||
export const SKIN_PLUGIN_HOST_WIDGETS = Object.freeze([
|
||||
"home.connection-form",
|
||||
"home.connection-status",
|
||||
"home.myts-login",
|
||||
"home.server-announcement",
|
||||
"home.social-links",
|
||||
"home.identity-provider",
|
||||
"app.skin-switcher",
|
||||
"app.language-switcher",
|
||||
"voice.server-switcher",
|
||||
@@ -55,7 +58,7 @@ export const SKIN_PLUGIN_HOST_WIDGETS = Object.freeze([
|
||||
"voice.chat-panel",
|
||||
"voice.audio-controls",
|
||||
"voice.screen-share-player",
|
||||
"voice.screen-share-start",
|
||||
"voice.screen-share-start",
|
||||
"voice.whisper-controls",
|
||||
"voice.performance-panel",
|
||||
"voice.connection-controls",
|
||||
@@ -69,8 +72,12 @@ export interface SkinPluginWidgetOptions {
|
||||
memberActions?: boolean;
|
||||
/** Enable trusted host member drag-and-drop between channel-tree rows. */
|
||||
memberDragDrop?: boolean;
|
||||
/** Select a supported host presentation for audio controls or a channel tree. */
|
||||
layout?: "default" | "room-panel" | "server-sidebar";
|
||||
/** Select a supported host presentation for a channel tree. */
|
||||
layout?: "default" | "server-sidebar";
|
||||
/** Provider identity used by the generic, UI-only home sign-in entry. */
|
||||
identityProviderId?: string;
|
||||
/** Provider display name used by the generic, UI-only home sign-in entry. */
|
||||
identityProviderLabel?: string;
|
||||
}
|
||||
const widgetPermissions = (...permissions: SkinPluginPermission[]): readonly SkinPluginPermission[] => Object.freeze(permissions);
|
||||
export const SKIN_PLUGIN_HOST_WIDGET_PERMISSIONS: Partial<Record<SkinPluginHostWidget, readonly SkinPluginPermission[]>> = Object.freeze({
|
||||
@@ -108,10 +115,11 @@ export type SkinPluginEvent =
|
||||
| "click" | "dblclick" | "change" | "input" | "submit" | "keydown"
|
||||
| "keyup" | "contextmenu" | "focus" | "blur" | "pointerdown" | "pointerup"
|
||||
| "pointerenter" | "pointerleave" | "dragstart" | "dragover" | "drop";
|
||||
export type SkinPluginAction =
|
||||
| "ui.setState" | "ui.toggleState"
|
||||
| "voice.joinChannel" | "favorites.switch" | "quickServers.switch" | "chat.sendMessage"
|
||||
| "voice.toggleMicrophone" | "voice.toggleOutputMute" | "voice.setOutputVolume"
|
||||
export type SkinPluginAction =
|
||||
| "ui.setState" | "ui.toggleState"
|
||||
| "voice.joinChannel" | "favorites.switch" | "quickServers.switch" | "chat.sendMessage" | "chat.togglePanel"
|
||||
| "voice.toggleMicrophone" | "voice.toggleOutputMute" | "voice.setOutputVolume" | "audio.openSettings"
|
||||
| "audio.toggleNoiseSuppression" | "audio.toggleAccompaniment"
|
||||
| "voice.disconnect" | "voice.setAway" | "voice.setWhisperActive"
|
||||
| "voice.startScreenShare" | "voice.stopScreenShare" | "voice.joinScreenShare" | "voice.leaveScreenShare";
|
||||
|
||||
@@ -191,27 +199,31 @@ const V3_EVENTS = new Set<string>([
|
||||
"keyup", "contextmenu", "focus", "blur", "pointerdown", "pointerup", "pointerenter", "pointerleave", "dragstart", "dragover", "drop",
|
||||
]);
|
||||
const PASSIVE_EVENTS = new Set<string>(["focus", "blur", "pointerenter", "pointerleave", "dragstart", "dragover"]);
|
||||
const ACTIONS = new Set<string>([
|
||||
"ui.setState", "ui.toggleState", "voice.joinChannel", "favorites.switch", "quickServers.switch", "chat.sendMessage",
|
||||
"voice.toggleMicrophone", "voice.toggleOutputMute", "voice.setOutputVolume", "voice.disconnect", "voice.setAway", "voice.setWhisperActive",
|
||||
const ACTIONS = new Set<string>([
|
||||
"ui.setState", "ui.toggleState", "voice.joinChannel", "favorites.switch", "quickServers.switch", "chat.sendMessage", "chat.togglePanel",
|
||||
"voice.toggleMicrophone", "voice.toggleOutputMute", "voice.setOutputVolume", "audio.openSettings", "audio.toggleNoiseSuppression", "audio.toggleAccompaniment", "voice.disconnect", "voice.setAway", "voice.setWhisperActive",
|
||||
"voice.startScreenShare", "voice.stopScreenShare", "voice.joinScreenShare", "voice.leaveScreenShare",
|
||||
]);
|
||||
const V3_ACTIONS = new Set<string>([
|
||||
"ui.toggleState", "voice.toggleMicrophone", "voice.toggleOutputMute", "voice.setOutputVolume", "voice.disconnect", "voice.setAway",
|
||||
const V3_ACTIONS = new Set<string>([
|
||||
"ui.toggleState", "chat.togglePanel", "voice.toggleMicrophone", "voice.toggleOutputMute", "voice.setOutputVolume", "audio.openSettings", "audio.toggleNoiseSuppression", "audio.toggleAccompaniment", "voice.disconnect", "voice.setAway",
|
||||
"voice.setWhisperActive", "voice.startScreenShare", "voice.stopScreenShare", "voice.joinScreenShare", "voice.leaveScreenShare",
|
||||
]);
|
||||
const PERMISSIONS = new Set<string>(Object.keys(SKIN_PLUGIN_PERMISSIONS));
|
||||
const HOST_WIDGETS = new Set<string>(SKIN_PLUGIN_HOST_WIDGETS);
|
||||
const ACTION_ARGS: Record<SkinPluginAction, ReadonlySet<string>> = {
|
||||
"ui.setState": new Set(["key", "value"]),
|
||||
"ui.toggleState": new Set(["key"]),
|
||||
"ui.toggleState": new Set(["key", "resetKey"]),
|
||||
"voice.joinChannel": new Set(["channelId"]),
|
||||
"favorites.switch": new Set(["favoriteId"]),
|
||||
"quickServers.switch": new Set(["quickServerId"]),
|
||||
"chat.sendMessage": new Set(["text"]),
|
||||
"quickServers.switch": new Set(["quickServerId"]),
|
||||
"chat.sendMessage": new Set(["text"]),
|
||||
"chat.togglePanel": new Set([]),
|
||||
"voice.toggleMicrophone": new Set([]),
|
||||
"voice.toggleOutputMute": new Set([]),
|
||||
"voice.setOutputVolume": new Set(["volume"]),
|
||||
"voice.toggleOutputMute": new Set([]),
|
||||
"voice.setOutputVolume": new Set(["volume"]),
|
||||
"audio.openSettings": new Set([]),
|
||||
"audio.toggleNoiseSuppression": new Set([]),
|
||||
"audio.toggleAccompaniment": new Set([]),
|
||||
"voice.disconnect": new Set([]),
|
||||
"voice.setAway": new Set(["away", "message"]),
|
||||
"voice.setWhisperActive": new Set(["active"]),
|
||||
@@ -225,11 +237,15 @@ const ACTION_PERMISSION: Record<SkinPluginAction, SkinPluginPermission | null> =
|
||||
"ui.toggleState": null,
|
||||
"voice.joinChannel": "session.channel.join",
|
||||
"favorites.switch": "favorites.switch",
|
||||
"quickServers.switch": "servers.quickList.switch",
|
||||
"chat.sendMessage": "chat.channel.send",
|
||||
"quickServers.switch": "servers.quickList.switch",
|
||||
"chat.sendMessage": "chat.channel.send",
|
||||
"chat.togglePanel": "chat.channel.read",
|
||||
"voice.toggleMicrophone": "audio.microphone.control",
|
||||
"voice.toggleOutputMute": "audio.output.control",
|
||||
"voice.setOutputVolume": "audio.output.control",
|
||||
"voice.toggleOutputMute": "audio.output.control",
|
||||
"voice.setOutputVolume": "audio.output.control",
|
||||
"audio.openSettings": "audio.settings.open",
|
||||
"audio.toggleNoiseSuppression": "audio.microphone.control",
|
||||
"audio.toggleAccompaniment": "audio.output.control",
|
||||
"voice.disconnect": "voice.disconnect",
|
||||
"voice.setAway": "voice.presence.write",
|
||||
"voice.setWhisperActive": "voice.whisper.control",
|
||||
@@ -265,7 +281,8 @@ const COLLECTION_FIELD_PERMISSIONS: Record<string, Partial<Record<string, SkinPl
|
||||
};
|
||||
const SESSION_STATUS_FIELDS = new Set(["connected", "connecting", "connectionState", "serverLabel", "channelId", "channelName", "userName"]);
|
||||
const CONTEXT_FIELDS: Record<string, ReadonlySet<string>> = {
|
||||
"audio.status": new Set(["microphoneMuted", "outputMuted"]),
|
||||
"chat.status": new Set(["panelOpen", "tab", "tabLabel"]),
|
||||
"audio.status": new Set(["microphoneMuted", "outputMuted", "noiseSuppressionEnabled", "accompanimentActive"]),
|
||||
"screenShare.status": new Set(["active", "starting", "viewing"]),
|
||||
"whisper.status": new Set(["active", "targetCount"]),
|
||||
};
|
||||
@@ -273,8 +290,9 @@ const COMPONENT_STATE_SCOPE_PATHS = new Set([
|
||||
...Array.from(SESSION_STATUS_FIELDS, (field) => `session.status.${field}`),
|
||||
...Object.entries(CONTEXT_FIELDS).flatMap(([path, fields]) => Array.from(fields, (field) => `${path}.${field}`)),
|
||||
]);
|
||||
const CONTEXT_PERMISSIONS: Record<string, SkinPluginPermission> = {
|
||||
"audio.status": "audio.status.read",
|
||||
const CONTEXT_PERMISSIONS: Record<string, SkinPluginPermission> = {
|
||||
"chat.status": "chat.channel.read",
|
||||
"audio.status": "audio.status.read",
|
||||
"screenShare.status": "voice.screenShare.status.read",
|
||||
"whisper.status": "voice.whisper.status.read",
|
||||
};
|
||||
@@ -418,9 +436,12 @@ export function parseSkinPluginDocument(input: unknown): SkinPluginDocument {
|
||||
if (rawAction.type === "ui.setState" && (typeof args.key !== "string" || !/^[a-z][a-z0-9_-]{0,31}$/.test(args.key) || !stateKeys.has(args.key) || !("value" in args))) {
|
||||
fail("SKIN_PLUGIN_ACTION_INVALID", "ui.setState requires a local state key and value.");
|
||||
}
|
||||
if (rawAction.type === "ui.toggleState" && (typeof args.key !== "string" || !/^[a-z][a-z0-9_-]{0,31}$/.test(args.key) || !stateKeys.has(args.key) || typeof state[args.key] !== "boolean")) {
|
||||
fail("SKIN_PLUGIN_ACTION_INVALID", "ui.toggleState requires a declared boolean local state key.");
|
||||
}
|
||||
if (rawAction.type === "ui.toggleState" && (typeof args.key !== "string" || !/^[a-z][a-z0-9_-]{0,31}$/.test(args.key) || !stateKeys.has(args.key) || typeof state[args.key] !== "boolean")) {
|
||||
fail("SKIN_PLUGIN_ACTION_INVALID", "ui.toggleState requires a declared boolean local state key.");
|
||||
}
|
||||
if (rawAction.type === "ui.toggleState" && args.resetKey !== undefined && (typeof args.resetKey !== "string" || !/^[a-z][a-z0-9_-]{0,31}$/.test(args.resetKey) || args.resetKey === args.key || !stateKeys.has(args.resetKey) || typeof state[args.resetKey] !== "boolean")) {
|
||||
fail("SKIN_PLUGIN_ACTION_INVALID", "ui.toggleState resetKey must name a different declared boolean local state key.");
|
||||
}
|
||||
if (rawAction.type === "voice.joinChannel" && typeof args.channelId !== "string") fail("SKIN_PLUGIN_ACTION_INVALID", "voice.joinChannel requires a channelId binding.");
|
||||
if (rawAction.type === "favorites.switch" && typeof args.favoriteId !== "string") fail("SKIN_PLUGIN_ACTION_INVALID", "favorites.switch requires a favoriteId binding.");
|
||||
if (rawAction.type === "quickServers.switch" && typeof args.quickServerId !== "string") fail("SKIN_PLUGIN_ACTION_INVALID", "quickServers.switch requires a quickServerId binding.");
|
||||
@@ -458,6 +479,8 @@ export function parseSkinPluginDocument(input: unknown): SkinPluginDocument {
|
||||
? new Set(["screenShare"])
|
||||
: rawNode.widget === "voice.audio-controls"
|
||||
? new Set(["layout"])
|
||||
: rawNode.widget === "home.identity-provider"
|
||||
? new Set(["identityProviderId", "identityProviderLabel"])
|
||||
: new Set<string>();
|
||||
if (!isRecord(rawNode.options)
|
||||
|| Object.keys(rawNode.options).some((key) => !supportedOptions.has(key))
|
||||
@@ -466,8 +489,14 @@ export function parseSkinPluginDocument(input: unknown): SkinPluginDocument {
|
||||
|| (rawNode.options.memberDragDrop !== undefined && typeof rawNode.options.memberDragDrop !== "boolean")
|
||||
|| (rawNode.options.layout !== undefined
|
||||
&& rawNode.options.layout !== "default"
|
||||
&& rawNode.options.layout !== "room-panel"
|
||||
&& !(rawNode.widget === "voice.channel-tree" && rawNode.options.layout === "server-sidebar"))) {
|
||||
&& !(rawNode.widget === "voice.channel-tree" && rawNode.options.layout === "server-sidebar"))
|
||||
|| (rawNode.options.identityProviderId !== undefined
|
||||
&& (typeof rawNode.options.identityProviderId !== "string" || !/^[a-z0-9][a-z0-9._-]{0,63}$/.test(rawNode.options.identityProviderId)))
|
||||
|| (rawNode.options.identityProviderLabel !== undefined
|
||||
&& (typeof rawNode.options.identityProviderLabel !== "string"
|
||||
|| !rawNode.options.identityProviderLabel.trim()
|
||||
|| rawNode.options.identityProviderLabel.length > 64
|
||||
|| rawNode.options.identityProviderLabel !== rawNode.options.identityProviderLabel.trim()))) {
|
||||
fail("SKIN_PLUGIN_WIDGET_OPTIONS_INVALID", "This host widget uses unsupported options.");
|
||||
}
|
||||
options = {
|
||||
@@ -475,8 +504,16 @@ export function parseSkinPluginDocument(input: unknown): SkinPluginDocument {
|
||||
...(rawNode.options.memberActions !== undefined ? { memberActions: rawNode.options.memberActions } : {}),
|
||||
...(rawNode.options.memberDragDrop !== undefined ? { memberDragDrop: rawNode.options.memberDragDrop } : {}),
|
||||
...(rawNode.options.layout !== undefined ? { layout: rawNode.options.layout } : {}),
|
||||
...(rawNode.options.identityProviderId !== undefined ? { identityProviderId: rawNode.options.identityProviderId } : {}),
|
||||
...(rawNode.options.identityProviderLabel !== undefined ? { identityProviderLabel: rawNode.options.identityProviderLabel } : {}),
|
||||
};
|
||||
}
|
||||
if (rawNode.widget === "home.identity-provider"
|
||||
&& (!isRecord(rawNode.options)
|
||||
|| typeof rawNode.options.identityProviderId !== "string"
|
||||
|| typeof rawNode.options.identityProviderLabel !== "string")) {
|
||||
fail("SKIN_PLUGIN_WIDGET_OPTIONS_INVALID", "The identity-provider widget requires a provider ID and display label.");
|
||||
}
|
||||
const requiredPermission = inputSchemaVersion >= 3 || rawNode.widget === "voice.screen-share-start"
|
||||
? missingSkinPluginWidgetPermission(rawNode.widget as SkinPluginHostWidget, permissions, options)
|
||||
: undefined;
|
||||
|
||||
@@ -24,6 +24,32 @@ test("runtime context exposes only fields covered by declared read permissions",
|
||||
assert.equal(JSON.stringify(projected).includes("secret.example"), false);
|
||||
});
|
||||
|
||||
test("chat panel state is projected only to plugins with chat read permission", () => {
|
||||
const context = { chat: { status: { panelOpen: true, tab: "private", tabLabel: "私聊", recipient: "not exposed" } } };
|
||||
assert.deepEqual(JSON.parse(JSON.stringify(projectSkinRuntimePluginContext(["chat.channel.read"], context))), {
|
||||
chat: { status: { panelOpen: true, tab: "private", tabLabel: "私聊" } },
|
||||
});
|
||||
assert.deepEqual(JSON.parse(JSON.stringify(projectSkinRuntimePluginContext([], context))), {});
|
||||
});
|
||||
|
||||
test("audio processing and accompaniment states are projected only with audio status permission", () => {
|
||||
const context = {
|
||||
audio: {
|
||||
status: {
|
||||
microphoneMuted: false,
|
||||
outputMuted: true,
|
||||
noiseSuppressionEnabled: true,
|
||||
accompanimentActive: false,
|
||||
inputVolume: 0.75,
|
||||
},
|
||||
},
|
||||
};
|
||||
assert.deepEqual(JSON.parse(JSON.stringify(projectSkinRuntimePluginContext(["audio.status.read"], context))), {
|
||||
audio: { status: { microphoneMuted: false, outputMuted: true, noiseSuppressionEnabled: true, accompanimentActive: false } },
|
||||
});
|
||||
assert.deepEqual(JSON.parse(JSON.stringify(projectSkinRuntimePluginContext([], context))), {});
|
||||
});
|
||||
|
||||
test("runtime member screen-share status is separately permission-gated", () => {
|
||||
const context = {
|
||||
session: {
|
||||
|
||||
@@ -47,13 +47,14 @@ interface ContextProjection {
|
||||
}
|
||||
|
||||
const CONTEXTS: readonly ContextProjection[] = Object.freeze([
|
||||
{ path: ["chat", "status"], permission: "chat.channel.read", fields: new Set(["panelOpen", "tab", "tabLabel"]) },
|
||||
{ path: ["session", "status"], permission: "session.status.read", fields: new Set(["connected", "connecting", "connectionState", "channelId", "channelName", "userName", "serverLabel"]) },
|
||||
{ path: ["audio", "status"], permission: "audio.status.read", fields: new Set(["microphoneMuted", "outputMuted"]) },
|
||||
{ path: ["audio", "status"], permission: "audio.status.read", fields: new Set(["microphoneMuted", "outputMuted", "noiseSuppressionEnabled", "accompanimentActive"]) },
|
||||
{ path: ["whisper", "status"], permission: "voice.whisper.status.read", fields: new Set(["active", "targetCount"]) },
|
||||
{ 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", "active", "starting", "viewing", "maxClientsLimited"]);
|
||||
const BOOLEAN_FIELDS = new Set(["connected", "connecting", "current", "favorite", "speaking", "self", "screenSharing", "audio", "microphoneMuted", "outputMuted", "noiseSuppressionEnabled", "accompanimentActive", "active", "starting", "viewing", "maxClientsLimited", "panelOpen"]);
|
||||
const NUMBER_FIELDS = new Set(["depth", "memberCount", "targetCount", "ownerClientId", "viewerCount", "maxClients"]);
|
||||
const TEXT_LIMITS: Readonly<Record<string, number>> = Object.freeze({
|
||||
id: 128,
|
||||
@@ -72,6 +73,8 @@ const TEXT_LIMITS: Readonly<Record<string, number>> = Object.freeze({
|
||||
connectionState: 16,
|
||||
source: 48,
|
||||
kind: 48,
|
||||
tab: 16,
|
||||
tabLabel: 48,
|
||||
time: 48,
|
||||
memberCountLabel: 12,
|
||||
text: 1_024,
|
||||
|
||||
Reference in new issue
Block a user