mirror of
https://github.com/EchoSixHIYA/WebSpeak-client-for-TeamSpeak.git
synced 2026-12-03 03:52:50 +08:00
feat(skin): preserve screen share user gesture
This commit is contained in:
1 parent
e20219b010
commit
b0b4a02a21
14 files changed
+209
-19
No files matched your search
@@ -81,6 +81,33 @@ test("generated UI supports broad safe markup, ARIA/data attributes, and inert c
|
||||
assert.equal(document.components[0].root.children?.[1].tag, "button");
|
||||
});
|
||||
|
||||
test("generated screen-share host widget requires permission and renders as an interactive host control", async () => {
|
||||
const source = generatedOutput("share-control", {
|
||||
tag: "section",
|
||||
children: [{ widget: "voice.screen-share-start", part: "start-share" }],
|
||||
});
|
||||
expectOutputError(source, "SKIN_EXTENSION_UI_PERMISSION_MISSING");
|
||||
|
||||
const permissions = ["voice.screenShare.control"] as const;
|
||||
const document = parseSkinExtensionUiOutput(source, { permissions });
|
||||
assert.equal(document.components[0].root.children?.[0].widget, "voice.screen-share-start");
|
||||
const html = await renderToString(createSSRApp(SkinPluginOutlet, {
|
||||
skinId: "community.test",
|
||||
skinVersion: "1.0.0",
|
||||
document: { schemaVersion: 3, components: [] },
|
||||
extensionOutput: source,
|
||||
extensionPermissions: permissions,
|
||||
page: "voice",
|
||||
data: {},
|
||||
assets: {},
|
||||
actions: {},
|
||||
widgets: { "voice.screen-share-start": () => "Start screen share" },
|
||||
}));
|
||||
assert.match(html, /data-ws-plugin-widget="voice\.screen-share-start"/);
|
||||
assert.match(html, /data-ws-part="skin\.voice\.share-control\.control-part-start-share"/);
|
||||
assert.match(html, /Start screen share/);
|
||||
});
|
||||
|
||||
test("generated UI schema 5 carries bounded state and named callbacks for a trusted host event loop", () => {
|
||||
const source = JSON.stringify({
|
||||
schemaVersion: 5,
|
||||
|
||||
@@ -16,6 +16,8 @@ export interface SkinExtensionWasmUiLoopRunHandle {
|
||||
export interface SkinExtensionWasmUiLoopOptions {
|
||||
/** Creates one bounded, disposable Wasm job for the supplied UI input. */
|
||||
createRun(input: SkinExtensionUiInput): SkinExtensionWasmUiLoopRunHandle;
|
||||
/** Supplies manifest permissions when generated output may embed a privileged host widget. */
|
||||
parseOutput?(output: string): SkinPluginDocument;
|
||||
onOutput?(output: string, document: SkinPluginDocument, input: SkinExtensionUiInput): void | Promise<void>;
|
||||
onError?(error: Error): void;
|
||||
}
|
||||
@@ -74,7 +76,7 @@ export function createSkinExtensionWasmUiLoopPrototype(options: SkinExtensionWas
|
||||
if (closed || activeRun !== run) return false;
|
||||
lastState = { ...input.state };
|
||||
if (result.uiOutput !== null) {
|
||||
const nextDocument = parseSkinExtensionUiOutput(result.uiOutput);
|
||||
const nextDocument = options.parseOutput?.(result.uiOutput) ?? parseSkinExtensionUiOutput(result.uiOutput);
|
||||
output = result.uiOutput;
|
||||
document = nextDocument;
|
||||
await options.onOutput?.(output, nextDocument, input);
|
||||
|
||||
@@ -35,6 +35,22 @@ const joinPlugin = parseSkinRuntimePluginDocument({
|
||||
}],
|
||||
}).plugins[0];
|
||||
|
||||
const screenSharePlugin = parseSkinRuntimePluginDocument({
|
||||
schemaVersion: 1,
|
||||
plugins: [{
|
||||
id: "voice-screen-share",
|
||||
name: "Voice screen share",
|
||||
version: "1.0.0",
|
||||
apiVersion: 1,
|
||||
runtime: "wasm",
|
||||
page: "voice",
|
||||
mode: "surface",
|
||||
entry: "plugins/voice-screen-share/index.wasm",
|
||||
assets: [],
|
||||
permissions: ["ui.surface.replace", "voice.screenShare.control"],
|
||||
}],
|
||||
}).plugins[0];
|
||||
|
||||
function output(page = "voice", count = 1): string {
|
||||
return JSON.stringify({
|
||||
schemaVersion: 5,
|
||||
@@ -64,6 +80,19 @@ function joinOutput(request = false, eventName: "dblclick" | "input" = "dblclick
|
||||
});
|
||||
}
|
||||
|
||||
function screenShareOutput(): string {
|
||||
return JSON.stringify({
|
||||
schemaVersion: 4,
|
||||
components: [{
|
||||
id: "voice-ui",
|
||||
name: "Voice UI",
|
||||
page: "voice",
|
||||
accessibleName: "Voice workspace",
|
||||
root: { tag: "main", children: [{ widget: "voice.screen-share-start" }] },
|
||||
}],
|
||||
});
|
||||
}
|
||||
|
||||
function sessionWithOutput(value: string, onError: (error: Error) => void = () => undefined) {
|
||||
return createSkinRuntimePluginSession({
|
||||
plugin,
|
||||
@@ -81,6 +110,27 @@ test("runtime plugin session accepts one generated root for its declared surface
|
||||
assert.equal(session.closed, true);
|
||||
});
|
||||
|
||||
test("runtime plugin session validates generated host widgets against manifest permissions", async () => {
|
||||
const allowed = createSkinRuntimePluginSession({
|
||||
plugin: screenSharePlugin,
|
||||
createRun: () => ({ result: Promise.resolve({ uiOutput: screenShareOutput() }), close: () => undefined }),
|
||||
});
|
||||
assert.equal(await allowed.start(), true);
|
||||
assert.equal(allowed.output, screenShareOutput());
|
||||
allowed.close();
|
||||
|
||||
const errors: Error[] = [];
|
||||
const denied = createSkinRuntimePluginSession({
|
||||
plugin,
|
||||
createRun: () => ({ result: Promise.resolve({ uiOutput: screenShareOutput() }), close: () => undefined }),
|
||||
onError: (error) => errors.push(error),
|
||||
});
|
||||
assert.equal(await denied.start(), false);
|
||||
assert.equal((errors[0] as { code?: string } | undefined)?.code, "SKIN_EXTENSION_UI_PERMISSION_MISSING");
|
||||
assert.equal(denied.output, null);
|
||||
denied.close();
|
||||
});
|
||||
|
||||
test("runtime plugin session rejects output targeting a different page", async () => {
|
||||
const errors: Error[] = [];
|
||||
const session = sessionWithOutput(output("home"), (error) => errors.push(error));
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
import type { SkinRuntimePlugin } from "../../../src/shared/skin-runtime-plugins.js";
|
||||
import { parseSkinExtensionUiActionRequest } from "../../../src/shared/skin-extension-ui.js";
|
||||
import { parseSkinExtensionUiActionRequest, parseSkinExtensionUiOutput } from "../../../src/shared/skin-extension-ui.js";
|
||||
import type { SkinExtensionUiInput, SkinExtensionUiEventInput } from "../../../src/shared/skin-extension-ui-input.js";
|
||||
import type { SkinPluginActionDefinition, SkinPluginDocument } from "../../../src/shared/skin-plugin.js";
|
||||
import {
|
||||
@@ -38,6 +38,7 @@ export function createSkinRuntimePluginSession(options: SkinRuntimePluginSession
|
||||
let output: string | null = null;
|
||||
const loop = createSkinExtensionWasmUiLoopPrototype({
|
||||
createRun: options.createRun,
|
||||
parseOutput: (source) => parseSkinExtensionUiOutput(source, { permissions: options.plugin.permissions }),
|
||||
onOutput: async (nextOutput, document, input) => {
|
||||
if (document.components.some((component) => component.page !== options.plugin.page)) {
|
||||
throw new SkinRuntimePluginSessionError("SKIN_RUNTIME_PLUGIN_PAGE_MISMATCH", "Generated UI must stay on the page declared by its plugin.");
|
||||
|
||||
Reference in new issue
Block a user