fix(skins): expose screen-share status to custom members

This commit is contained in:
illusia committed 2026-10-11 23:06:06 +08:00
1 parent 7fe8719812
commit 8b5db8af1f
20 files changed
+295 -41

No files matched your search

+32
View File
@@ -238,6 +238,38 @@ test("schema v3 scopes local UI state only to approved public scalar context fie
errorCode(() => parseSkinPluginDocument(legacy), "SKIN_PLUGIN_SCHEMA_UNSUPPORTED");
});
test("custom member screen-share fields require read permission and can bind a watch action", () => {
const document = validDocument();
document.schemaVersion = 3;
document.components[0].actions = {
watch: { type: "voice.joinScreenShare", args: { streamId: "{{member.screenShareStreamId}}" } },
};
document.components[0].permissions = ["session.members.read", "voice.screenShare.read", "voice.screenShare.control"];
document.components[0].root = {
tag: "ul",
children: [{
tag: "li",
repeat: { path: "session.members", as: "member" },
children: [{
tag: "button",
when: { path: "member.screenSharing", equals: true },
events: { click: "watch" },
}],
}],
};
const parsed = parseSkinPluginDocument(document);
assert.equal(parsed.components[0].root.children?.[0].children?.[0].when?.path, "member.screenSharing");
assert.equal(parsed.components[0].actions.watch.args.streamId, "{{member.screenShareStreamId}}");
const missingRead = structuredClone(document);
missingRead.components[0].permissions = missingRead.components[0].permissions.filter((permission) => permission !== "voice.screenShare.read");
errorCode(() => parseSkinPluginDocument(missingRead), "SKIN_PLUGIN_PERMISSION_MISSING");
const missingControl = structuredClone(document);
missingControl.components[0].permissions = missingControl.components[0].permissions.filter((permission) => permission !== "voice.screenShare.control");
errorCode(() => parseSkinPluginDocument(missingControl), "SKIN_PLUGIN_PERMISSION_MISSING");
});
test("schema v3 trusted widgets can omit screen-share UI and request only the permissions they use", () => {
const document = validDocument();
document.schemaVersion = 3;
+18 -10
View File
@@ -246,14 +246,20 @@ const COLLECTION_PERMISSION: Record<string, SkinPluginPermission> = {
"chat.messages": "chat.channel.read",
"screenShare.streams": "voice.screenShare.read",
};
const COLLECTION_FIELDS: Record<string, ReadonlySet<string>> = {
"session.channels": new Set(["id", "name", "parentId", "depth", "memberCount", "memberCountLabel", "maxClients", "maxClientsLimited", "current"]),
"session.members": new Set(["id", "name", "avatarInitial", "channelId", "status", "speaking", "self"]),
const COLLECTION_FIELDS: Record<string, ReadonlySet<string>> = {
"session.channels": new Set(["id", "name", "parentId", "depth", "memberCount", "memberCountLabel", "maxClients", "maxClientsLimited", "current"]),
"session.members": new Set(["id", "name", "avatarInitial", "channelId", "status", "speaking", "self", "screenSharing", "screenShareStreamId"]),
"favorites.items": new Set(["id", "label", "current", "kind"]),
"servers.quickList": new Set(["id", "label", "monogram", "icon", "tone", "current", "kind", "favorite"]),
"chat.messages": new Set(["id", "author", "text", "time", "kind", "channelId"]),
"screenShare.streams": new Set(["streamId", "source", "ownerClientId", "ownerNickname", "name", "audio", "viewerCount"]),
};
"screenShare.streams": new Set(["streamId", "source", "ownerClientId", "ownerNickname", "name", "audio", "viewerCount"]),
};
const COLLECTION_FIELD_PERMISSIONS: Record<string, Partial<Record<string, SkinPluginPermission>>> = {
"session.members": {
screenSharing: "voice.screenShare.read",
screenShareStreamId: "voice.screenShare.read",
},
};
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"]),
@@ -299,11 +305,13 @@ function bindingPermissions(value: string, aliases: ReadonlyMap<string, string>,
if (path.length !== 2 || !stateKeys.has(path[1])) fail("SKIN_PLUGIN_BINDING_INVALID", "A state binding must reference a declared local state key.");
continue;
}
const aliasCollection = aliases.get(path[0]);
if (aliasCollection) {
if (path.length !== 2 || !COLLECTION_FIELDS[aliasCollection]?.has(path[1])) fail("SKIN_PLUGIN_BINDING_INVALID", "A repeated item binding references an unsupported public field.");
continue;
}
const aliasCollection = aliases.get(path[0]);
if (aliasCollection) {
if (path.length !== 2 || !COLLECTION_FIELDS[aliasCollection]?.has(path[1])) fail("SKIN_PLUGIN_BINDING_INVALID", "A repeated item binding references an unsupported public field.");
const fieldPermission = COLLECTION_FIELD_PERMISSIONS[aliasCollection]?.[path[1]];
if (fieldPermission) found.add(fieldPermission);
continue;
}
if (path[0] === "session" && path.length === 3 && path[1] === "status" && SESSION_STATUS_FIELDS.has(path[2])) {
found.add("session.status.read");
continue;
@@ -24,6 +24,36 @@ test("runtime context exposes only fields covered by declared read permissions",
assert.equal(JSON.stringify(projected).includes("secret.example"), false);
});
test("runtime member screen-share status is separately permission-gated", () => {
const context = {
session: {
members: [{
id: "42",
name: "Sharing member",
channelId: "channel-1",
status: "online",
speaking: false,
self: false,
screenSharing: true,
screenShareStreamId: "share-opaque-id",
}],
},
};
const memberOnly = projectSkinRuntimePluginContext(["session.members.read"], context);
assert.deepEqual(JSON.parse(JSON.stringify(memberOnly)), {
session: { members: [{ id: "42", name: "Sharing member", channelId: "channel-1", status: "online", speaking: false, self: false }] },
});
const withShareRead = projectSkinRuntimePluginContext(["session.members.read", "voice.screenShare.read"], context);
assert.deepEqual(JSON.parse(JSON.stringify(withShareRead)), {
session: { members: [{
id: "42", name: "Sharing member", channelId: "channel-1", status: "online", speaking: false, self: false,
screenSharing: true, screenShareStreamId: "share-opaque-id",
}] },
});
});
test("runtime context keeps safe server names and redacts connection targets from all public labels", () => {
const projected = projectSkinRuntimePluginContext(
["session.status.read", "favorites.read", "servers.quickList.read"],
+16 -4
View File
@@ -20,13 +20,20 @@ interface CollectionProjection {
path: readonly string[];
permission: SkinPluginPermission;
fields: ReadonlySet<string>;
fieldPermissions?: Readonly<Record<string, SkinPluginPermission>>;
maxItems: number;
keepNewest?: boolean;
}
const COLLECTIONS: readonly CollectionProjection[] = Object.freeze([
{ path: ["session", "channels"], permission: "session.channels.read", fields: new Set(["id", "name", "parentId", "depth", "memberCount", "memberCountLabel", "maxClients", "maxClientsLimited", "current"]), maxItems: 128 },
{ path: ["session", "members"], permission: "session.members.read", fields: new Set(["id", "name", "channelId", "status", "speaking", "self"]), maxItems: 256 },
{
path: ["session", "members"],
permission: "session.members.read",
fields: new Set(["id", "name", "channelId", "status", "speaking", "self", "screenSharing", "screenShareStreamId"]),
fieldPermissions: { screenSharing: "voice.screenShare.read", screenShareStreamId: "voice.screenShare.read" },
maxItems: 256,
},
{ path: ["favorites", "items"], permission: "favorites.read", fields: new Set(["id", "label", "current", "kind"]), maxItems: 100 },
{ path: ["servers", "quickList"], permission: "servers.quickList.read", fields: new Set(["id", "label", "current", "kind", "favorite"]), maxItems: 100 },
{ path: ["chat", "messages"], permission: "chat.channel.read", fields: new Set(["id", "author", "text", "time", "kind", "channelId"]), maxItems: 50, keepNewest: true },
@@ -46,11 +53,12 @@ const CONTEXTS: readonly ContextProjection[] = Object.freeze([
{ 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", "audio", "microphoneMuted", "outputMuted", "active", "starting", "viewing", "maxClientsLimited"]);
const BOOLEAN_FIELDS = new Set(["connected", "connecting", "current", "favorite", "speaking", "self", "screenSharing", "audio", "microphoneMuted", "outputMuted", "active", "starting", "viewing", "maxClientsLimited"]);
const NUMBER_FIELDS = new Set(["depth", "memberCount", "targetCount", "ownerClientId", "viewerCount", "maxClients"]);
const TEXT_LIMITS: Readonly<Record<string, number>> = Object.freeze({
id: 128,
streamId: 128,
screenShareStreamId: 128,
channelId: 128,
parentId: 128,
name: 160,
@@ -161,9 +169,13 @@ export function projectSkinRuntimePluginContext(
const raw = readPath(context, definition.path);
if (!Array.isArray(raw)) continue;
const selected = definition.keepNewest ? raw.slice(-definition.maxItems) : raw.slice(0, definition.maxItems);
const items = selected.map((item, index) => projectCollectionItem(definition, item, index)).filter((item): item is Record<string, unknown> => Boolean(item));
const fields = definition.fieldPermissions
? new Set([...definition.fields].filter((field) => !definition.fieldPermissions?.[field] || allowed.has(definition.fieldPermissions[field])))
: definition.fields;
const visibleDefinition = fields === definition.fields ? definition : { ...definition, fields };
const items = selected.map((item, index) => projectCollectionItem(visibleDefinition, item, index)).filter((item): item is Record<string, unknown> => Boolean(item));
writePath(projected, definition.path, items);
projectedCollections.push({ definition, items });
projectedCollections.push({ definition: visibleDefinition, items });
}
// Keep the snapshot within the independent context budget even when a server is unusually large.