mirror of
https://github.com/EchoSixHIYA/WebSpeak-client-for-TeamSpeak.git
synced 2026-12-03 03:52:50 +08:00
fix(screen-share): resolve viewer avatars from client ids instead of the roster
The screen-share viewer roster embedded every viewer's avatar as a base64 data URL, and the gateway rebroadcast the whole roster to the channel on every viewer join and leave. With the 64-viewer cap and the 128 KiB avatar cap that is up to ~8 MB of JSON per event, multiplied by every member of the channel -- even though the player renders at most five avatars and every client already holds member avatars from the directory it received through the connected and memberAvatar messages. Send the TeamSpeak client id instead and resolve the avatar locally, mirroring how a stream's ownerClientId already maps to a member card. This removes the payload entirely rather than trimming it: the roster no longer scales with avatar size at all. The legacy inline avatar is still parsed so a newer client keeps working against an older gateway, and a viewer missing from the local directory degrades to the existing initial-based avatar fallback. Verified by a regression test that gives every viewer a 128 KiB avatar and asserts the roster stays under 16 KiB. Restoring the previous behaviour makes that assertion fail at 1049182 bytes for eight viewers.
This commit is contained in:
1 parent
62af82f253
commit
bfa26da9eb
8 files changed
+128
-5
No files matched your search
@@ -81,6 +81,16 @@ export type ScreenSharePeerSignal =
|
||||
export interface ScreenShareViewerDescription {
|
||||
peerId: string;
|
||||
nickname: string;
|
||||
/**
|
||||
* TeamSpeak client id. The gateway sends this instead of an inline avatar so
|
||||
* a receiving client can resolve the avatar it already holds for that member
|
||||
* from the directory, rather than the roster carrying the image again.
|
||||
*/
|
||||
clientId?: number;
|
||||
/**
|
||||
* Legacy inline avatar. Current gateways do not set this; it is still parsed
|
||||
* so a newer web client keeps rendering avatars against an older gateway.
|
||||
*/
|
||||
avatar?: string;
|
||||
}
|
||||
|
||||
|
||||
@@ -101,3 +101,29 @@ test("legacy screen streams receive defaults and untrusted viewer data is bounde
|
||||
assert.equal(message.streams[0]?.viewers[0]?.nickname.length, 120);
|
||||
assert.equal(parseScreenShareStream({ streamId: "s", ownerPeerId: [] }), null);
|
||||
});
|
||||
|
||||
test("screen share viewers carry a client id and still accept a legacy inline avatar", () => {
|
||||
const message = parseServerMessage({
|
||||
type: "screenShareList",
|
||||
streams: [{
|
||||
streamId: "s", ownerPeerId: "owner",
|
||||
viewers: [
|
||||
{ peerId: "v1", nickname: "One", clientId: 42 },
|
||||
{ peerId: "v2", nickname: "Two", avatar: "data:image/png;base64,AAAA" },
|
||||
{ peerId: "v3", nickname: "Three", clientId: -1 },
|
||||
{ peerId: "v4", nickname: "Four", clientId: 70_000 },
|
||||
],
|
||||
}],
|
||||
});
|
||||
assert.ok(message?.type === "screenShareList");
|
||||
const viewers = message.streams[0]?.viewers ?? [];
|
||||
assert.equal(viewers.length, 4);
|
||||
assert.equal(viewers[0]?.clientId, 42);
|
||||
assert.equal("avatar" in viewers[0]!, false);
|
||||
// An older gateway still inlines the avatar; keep honouring it.
|
||||
assert.equal(viewers[1]?.avatar, "data:image/png;base64,AAAA");
|
||||
assert.equal(viewers[1]?.clientId, undefined);
|
||||
// Out-of-range ids are dropped rather than forwarded.
|
||||
assert.equal(viewers[2]?.clientId, undefined);
|
||||
assert.equal(viewers[3]?.clientId, undefined);
|
||||
});
|
||||
@@ -103,6 +103,7 @@ export function parseScreenShareViewers(raw: unknown): ScreenShareViewerDescript
|
||||
return raw.filter((viewer): viewer is RecordValue & { peerId: string; nickname: string } => isRecord(viewer) && text(viewer.peerId) && text(viewer.nickname))
|
||||
.slice(0, 64).map(viewer => ({
|
||||
peerId: viewer.peerId.slice(0, 128), nickname: viewer.nickname.slice(0, 120),
|
||||
...(clientId(viewer.clientId) ? { clientId: viewer.clientId } : {}),
|
||||
...(text(viewer.avatar) && viewer.avatar.length <= 128 * 1024 ? { avatar: viewer.avatar } : {}),
|
||||
}));
|
||||
}
|
||||
|
||||
Reference in new issue
Block a user