mirror of
https://github.com/EchoSixHIYA/WebSpeak-client-for-TeamSpeak.git
synced 2026-12-02 19:42:51 +08:00
feat(kaak): show channel occupancy limits
This commit is contained in:
1 parent
387462d89a
commit
a3bf476db6
23 files changed
+244
-20
No files matched your search
@@ -12,7 +12,7 @@ const samples: Record<ServerMessage["type"], ServerMessage> = {
|
||||
memberEnter: { type: "memberEnter", id: 2, nickname: "Visitor", uid: "uid-2", isSelf: false },
|
||||
memberLeave: { type: "memberLeave", id: 2 },
|
||||
memberAvatar: { type: "memberAvatar", id: 2, avatar: "data:image/png;base64,test" },
|
||||
channelList: { type: "channelList", channels: [{ id: "1", parentID: "0", name: "Lobby", members: [{ id: 1, nickname: "Owner" }] }] },
|
||||
channelList: { type: "channelList", channels: [{ id: "1", parentID: "0", name: "Lobby", maxClients: 10, maxClientsLimited: true, members: [{ id: 1, nickname: "Owner" }] }] },
|
||||
chatMessage: { type: "chatMessage", scope: "channel", targetId: "1", invokerId: 2, message: "hello" },
|
||||
pokeReceived: { type: "pokeReceived", invokerId: 2, message: "poke" },
|
||||
serverEvent: { type: "serverEvent", event },
|
||||
@@ -61,6 +61,8 @@ test("malformed nested directory and event data is rejected before client state
|
||||
{ type: "connected", tsClientId: 1, members: [{ id: "1", nickname: "bad id" }] },
|
||||
{ type: "connected", tsClientId: 1, serverEventLog: [{ id: "incomplete" }] },
|
||||
{ type: "channelList", channels: [{ id: "1", parentID: "0", name: "Lobby", members: [{}] }] },
|
||||
{ type: "channelList", channels: [{ id: "1", parentID: "0", name: "Lobby", maxClients: 10 }] },
|
||||
{ type: "channelList", channels: [{ id: "1", parentID: "0", name: "Lobby", maxClients: 65536, maxClientsLimited: true }] },
|
||||
{ type: "memberEnter", id: 65536, nickname: "bad id" },
|
||||
{ type: "memberEnter", id: 1, nickname: "bad flag", inputMuted: "false" },
|
||||
{ type: "serverEvent", event: { ...event, timestamp: Infinity } },
|
||||
|
||||
@@ -60,6 +60,9 @@ function member(value: unknown): value is ChannelMember {
|
||||
function channel(value: unknown): value is ChannelInfo {
|
||||
return isRecord(value) && text(value.id) && channelId(value.id) && text(value.parentID) && channelId(value.parentID)
|
||||
&& text(value.name) && optional(value.order, text) && optional(value.description, text)
|
||||
&& optional(value.maxClients, maximum => finite(maximum) && Number.isInteger(maximum) && maximum >= 0 && maximum <= 65_535)
|
||||
&& optional(value.maxClientsLimited, boolean)
|
||||
&& (value.maxClients === undefined) === (value.maxClientsLimited === undefined)
|
||||
&& optional(value.members, members => arrayOf(members, member));
|
||||
}
|
||||
|
||||
|
||||
@@ -216,7 +216,7 @@ const COLLECTION_PERMISSION: Record<string, SkinPluginPermission> = {
|
||||
"screenShare.streams": "voice.screenShare.read",
|
||||
};
|
||||
const COLLECTION_FIELDS: Record<string, ReadonlySet<string>> = {
|
||||
"session.channels": new Set(["id", "name", "parentId", "depth", "memberCount", "current"]),
|
||||
"session.channels": new Set(["id", "name", "parentId", "depth", "memberCount", "memberCountLabel", "maxClients", "maxClientsLimited", "current"]),
|
||||
"session.members": new Set(["id", "name", "avatarInitial", "channelId", "status", "speaking", "self"]),
|
||||
"favorites.items": new Set(["id", "label", "current", "kind"]),
|
||||
"servers.quickList": new Set(["id", "label", "monogram", "tone", "current", "kind", "favorite"]),
|
||||
|
||||
@@ -9,7 +9,7 @@ test("runtime context exposes only fields covered by declared read permissions",
|
||||
const projected = projectSkinRuntimePluginContext(["session.channels.read"], {
|
||||
session: {
|
||||
status: { connected: true, serverLabel: "voice.internal.example:9987" },
|
||||
channels: [{ id: "channel-1", name: "Lobby", parentId: null, depth: 0, memberCount: 2, current: true, address: "voice.internal.example:9987", members: [{ name: "private nested member" }] }],
|
||||
channels: [{ id: "channel-1", name: "Lobby", parentId: null, depth: 0, memberCount: 2, memberCountLabel: "02", maxClients: 10, maxClientsLimited: true, current: true, address: "voice.internal.example:9987", members: [{ name: "private nested member" }] }],
|
||||
members: [{ id: "member-1", name: "private member" }],
|
||||
},
|
||||
favorites: { items: [{ id: "opaque-1", label: "Saved", address: "secret.example:9987" }] },
|
||||
@@ -17,7 +17,7 @@ test("runtime context exposes only fields covered by declared read permissions",
|
||||
|
||||
assert.deepEqual(JSON.parse(JSON.stringify(projected)), {
|
||||
session: {
|
||||
channels: [{ id: "channel-1", name: "Lobby", parentId: null, depth: 0, memberCount: 2, current: true }],
|
||||
channels: [{ id: "channel-1", name: "Lobby", parentId: null, depth: 0, memberCount: 2, memberCountLabel: "02", maxClients: 10, maxClientsLimited: true, current: true }],
|
||||
},
|
||||
});
|
||||
assert.equal(JSON.stringify(projected).includes("voice.internal.example"), false);
|
||||
@@ -50,6 +50,22 @@ test("runtime context redacts connection targets from quick-list labels and drop
|
||||
assert.equal(JSON.stringify(projected).includes("2001:db8::1"), false);
|
||||
});
|
||||
|
||||
test("runtime channel limits are bounded public metadata and do not admit neighboring fields", () => {
|
||||
const projected = projectSkinRuntimePluginContext(["session.channels.read"], {
|
||||
session: {
|
||||
channels: [{
|
||||
id: "channel-1", name: "Lobby", memberCount: 2, memberCountLabel: "02",
|
||||
maxClients: 65_536, maxClientsLimited: true, address: "voice.internal.example:9987",
|
||||
}],
|
||||
},
|
||||
});
|
||||
|
||||
assert.deepEqual(JSON.parse(JSON.stringify(projected)), {
|
||||
session: { channels: [{ id: "channel-1", name: "Lobby", memberCount: 2, memberCountLabel: "02", maxClientsLimited: true }] },
|
||||
});
|
||||
assert.equal(JSON.stringify(projected).includes("voice.internal.example"), false);
|
||||
});
|
||||
|
||||
test("profile-picture display permission does not expose image data to declarative or Wasm contexts", () => {
|
||||
const context = {
|
||||
session: {
|
||||
|
||||
@@ -25,7 +25,7 @@ interface CollectionProjection {
|
||||
}
|
||||
|
||||
const COLLECTIONS: readonly CollectionProjection[] = Object.freeze([
|
||||
{ path: ["session", "channels"], permission: "session.channels.read", fields: new Set(["id", "name", "parentId", "depth", "memberCount", "current"]), maxItems: 128 },
|
||||
{ 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: ["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 },
|
||||
@@ -46,8 +46,8 @@ 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"]);
|
||||
const NUMBER_FIELDS = new Set(["depth", "memberCount", "targetCount", "ownerClientId", "viewerCount"]);
|
||||
const BOOLEAN_FIELDS = new Set(["connected", "connecting", "current", "favorite", "speaking", "self", "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,
|
||||
@@ -63,6 +63,7 @@ const TEXT_LIMITS: Readonly<Record<string, number>> = Object.freeze({
|
||||
source: 48,
|
||||
kind: 48,
|
||||
time: 48,
|
||||
memberCountLabel: 12,
|
||||
text: 1_024,
|
||||
});
|
||||
|
||||
@@ -86,7 +87,7 @@ function readPath(value: unknown, path: readonly string[]): unknown {
|
||||
function boundedValue(field: string, value: unknown): string | number | boolean | null | undefined {
|
||||
if (value === null) return field === "parentId" ? null : undefined;
|
||||
if (BOOLEAN_FIELDS.has(field)) return typeof value === "boolean" ? value : undefined;
|
||||
if (NUMBER_FIELDS.has(field)) return typeof value === "number" && Number.isSafeInteger(value) && value >= 0 && value <= 1_000_000_000
|
||||
if (NUMBER_FIELDS.has(field)) return typeof value === "number" && Number.isSafeInteger(value) && value >= 0 && value <= (field === "maxClients" ? 65_535 : 1_000_000_000)
|
||||
? value
|
||||
: undefined;
|
||||
if (typeof value !== "string") return undefined;
|
||||
|
||||
@@ -19,6 +19,10 @@ export interface ChannelInfo {
|
||||
order?: string;
|
||||
name: string;
|
||||
description?: string;
|
||||
/** Maximum clients for this channel, when TeamSpeak reports a finite or unlimited setting. */
|
||||
maxClients?: number;
|
||||
/** False means the channel has no individual client limit. */
|
||||
maxClientsLimited?: boolean;
|
||||
members?: ChannelMember[];
|
||||
}
|
||||
|
||||
|
||||
Reference in new issue
Block a user