mirror of
https://github.com/EchoSixHIYA/WebSpeak-client-for-TeamSpeak.git
synced 2026-12-02 19:42:51 +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
@@ -11,6 +11,7 @@ import {
|
||||
type SkinPluginDocument,
|
||||
type SkinPluginHostWidget,
|
||||
type SkinPluginNode,
|
||||
type SkinPluginPermission,
|
||||
} from "../../../src/shared/skin-plugin.js";
|
||||
import { parseSkinExtensionUiOutput } from "../../../src/shared/skin-extension-ui.js";
|
||||
import { parseSkinExtensionUiInput } from "../../../src/shared/skin-extension-ui-input.js";
|
||||
@@ -35,6 +36,7 @@ export default defineComponent({
|
||||
document: { type: Object as PropType<SkinPluginDocument>, required: true },
|
||||
extensionOutput: { type: String as PropType<string | null>, default: null },
|
||||
extensionMode: { type: String as PropType<SkinPluginComponentMode | undefined>, default: undefined },
|
||||
extensionPermissions: { type: Array as PropType<readonly SkinPluginPermission[]>, default: () => [] },
|
||||
componentNamespace: { type: String, default: "" },
|
||||
manageSurfaceRecovery: { type: Boolean, default: true },
|
||||
page: { type: String as PropType<"home" | "voice" | "demo">, required: true },
|
||||
@@ -57,11 +59,21 @@ export default defineComponent({
|
||||
const objectUrls = new Map<string, string>();
|
||||
const validatedDocument = computed(() => {
|
||||
let document: SkinPluginDocument;
|
||||
try { document = parseSkinPluginDocument(props.document); }
|
||||
const emptyRuntimeBase = Boolean(props.extensionOutput)
|
||||
&& props.document.schemaVersion === 3
|
||||
&& Array.isArray(props.document.components)
|
||||
&& props.document.components.length === 0;
|
||||
try {
|
||||
// Runtime plugins use an empty v3 base document so their validated generated output
|
||||
// can flow through the same approval, layout, and rendering path as packaged components.
|
||||
document = emptyRuntimeBase
|
||||
? { schemaVersion: 3, components: [] }
|
||||
: parseSkinPluginDocument(props.document);
|
||||
}
|
||||
catch { return { schemaVersion: 2 as const, components: [] }; }
|
||||
if (!props.extensionOutput || document.schemaVersion !== 3) return document;
|
||||
try {
|
||||
const parsedExtensionDocument = parseSkinExtensionUiOutput(props.extensionOutput);
|
||||
const parsedExtensionDocument = parseSkinExtensionUiOutput(props.extensionOutput, { permissions: props.extensionPermissions });
|
||||
const extensionDocument = props.extensionMode
|
||||
? { ...parsedExtensionDocument, components: parsedExtensionDocument.components.map((component) => ({ ...component, mode: props.extensionMode })) }
|
||||
: parsedExtensionDocument;
|
||||
@@ -192,6 +204,7 @@ export default defineComponent({
|
||||
|
||||
function layoutPart(component: SkinPluginComponent, node: SkinPluginNode, nodePath: string): string {
|
||||
const interactive = ["a", "button", "input", "select", "summary", "textarea"].includes(node.tag ?? "")
|
||||
|| node.widget === "voice.screen-share-start"
|
||||
|| node.attributes?.role === "button"
|
||||
|| ["click", "dblclick", "contextmenu", "keydown", "keyup", "pointerdown", "pointerup", "drop"]
|
||||
.some((eventName) => Boolean(node.events?.[eventName as keyof typeof node.events]));
|
||||
|
||||
@@ -3,7 +3,7 @@ import type { SkinExtensionSessionStatus } from "../../../src/shared/skin-extens
|
||||
import { computeSkinRuntimePluginDigest, createSkinRuntimePluginApproval, isSkinRuntimePluginApproved, type SkinRuntimePluginApproval } from "../../../src/shared/skin-runtime-plugin-approval.js";
|
||||
import type { SkinRuntimePlugin, SkinRuntimePluginDocument, SkinRuntimePluginPage } from "../../../src/shared/skin-runtime-plugins.js";
|
||||
import { parseSkinExtensionUiInput, type SkinExtensionUiInput } from "../../../src/shared/skin-extension-ui-input.js";
|
||||
import { SKIN_PLUGIN_ACTION_PERMISSIONS, skinPluginActionPermission, type SkinPluginAction, type SkinPluginDocument } from "../../../src/shared/skin-plugin.js";
|
||||
import { SKIN_PLUGIN_ACTION_PERMISSIONS, skinPluginActionPermission, type SkinPluginAction, type SkinPluginDocument, type SkinPluginHostWidget } from "../../../src/shared/skin-plugin.js";
|
||||
import { SKIN_RUNTIME_PLUGIN_DATA_PERMISSIONS } from "../../../src/shared/skin-runtime-plugin-context.js";
|
||||
import SkinPluginOutlet from "./SkinPluginOutlet.js";
|
||||
import { approveSkinRuntimePlugin, getSkinRuntimePluginApproval, revokeSkinRuntimePluginApprovals } from "../services/skin-runtime-plugin-approval.js";
|
||||
@@ -91,6 +91,7 @@ export default defineComponent({
|
||||
page: { type: String as PropType<SkinRuntimePluginPage>, required: true },
|
||||
context: { type: Object as PropType<Record<string, unknown>>, default: () => ({}) },
|
||||
actions: { type: Object as PropType<Partial<Record<SkinPluginAction, HostActionHandler>>>, default: () => ({}) },
|
||||
widgets: { type: Object as PropType<Partial<Record<SkinPluginHostWidget, () => VNodeChild>>>, default: () => ({}) },
|
||||
readSessionStatus: { type: Function as PropType<(signal: AbortSignal) => SkinExtensionSessionStatus | Promise<SkinExtensionSessionStatus>>, required: true },
|
||||
},
|
||||
emits: {
|
||||
@@ -351,6 +352,8 @@ export default defineComponent({
|
||||
data: {},
|
||||
assets: pluginAssets,
|
||||
actions: {},
|
||||
extensionPermissions: plugin.permissions,
|
||||
widgets: props.widgets,
|
||||
onExtensionEvent: (event: unknown) => dispatch(plugin.id, event),
|
||||
onSurfaceChange: (active: boolean) => surfaceChanged(plugin.id, active),
|
||||
onRestoreSkin: () => emit("restore-skin"),
|
||||
|
||||
@@ -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.");
|
||||
|
||||
@@ -46,6 +46,25 @@
|
||||
min-height: 0;
|
||||
}
|
||||
|
||||
.ws-plugin-host-widget[data-ws-plugin-widget="voice.screen-share-start"] { min-height: 44px; }
|
||||
.skin-runtime-screen-share-start {
|
||||
display: inline-flex;
|
||||
min-width: 44px;
|
||||
min-height: 44px;
|
||||
align-items: center;
|
||||
justify-content: center;
|
||||
gap: 8px;
|
||||
padding: 0 12px;
|
||||
border: 1px solid currentColor;
|
||||
border-radius: 10px;
|
||||
color: inherit;
|
||||
background: transparent;
|
||||
font: inherit;
|
||||
cursor: pointer;
|
||||
}
|
||||
.skin-runtime-screen-share-start:disabled { cursor: not-allowed; opacity: .55; }
|
||||
.skin-runtime-screen-share-start:focus-visible { outline: 3px solid #fbbf24; outline-offset: 3px; }
|
||||
|
||||
.ws-plugin-surface-recovery,
|
||||
.ws-plugin-surface-reset {
|
||||
position: fixed;
|
||||
|
||||
@@ -35,6 +35,7 @@
|
||||
:page="showVoiceShell ? 'voice' : 'home'"
|
||||
:context="skinPluginContext"
|
||||
:actions="skinPluginActions"
|
||||
:widgets="skinPluginWidgets"
|
||||
:read-session-status="readSkinRuntimeSessionStatus"
|
||||
@surface-change="skinRuntimePluginSurfaceActive = $event"
|
||||
@restore-skin="switchToBuiltIn"
|
||||
@@ -1618,6 +1619,15 @@ const skinPluginActions = {
|
||||
};
|
||||
|
||||
const skinPluginWidgets = {
|
||||
"voice.screen-share-start": () => h("button", {
|
||||
type: "button",
|
||||
class: "skin-runtime-screen-share-start",
|
||||
disabled: !voiceState.connected || screenShareActive.value || screenShareStarting.value,
|
||||
"aria-label": t("startScreenShare"),
|
||||
onClick: () => {
|
||||
if (voiceState.connected && !screenShareActive.value && !screenShareStarting.value) void startScreenShare();
|
||||
},
|
||||
}, [h(Icon, { name: "share", size: 16 }), h("span", null, t("startScreenShare"))]),
|
||||
"home.connection-form": () => h(JoinForm, {
|
||||
autofocusNickname: !isMobileViewport.value,
|
||||
serverHost: serverHost.value,
|
||||
|
||||
Reference in new issue
Block a user