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:
LainHE committed 2026-10-16 09:47:01 +08:00
1 parent 62af82f253
commit bfa26da9eb
8 files changed
+128 -5

No files matched your search

+11 -2
View File
@@ -233,11 +233,20 @@ export class ScreenShareCoordinator {
.filter((entry): entry is ScreenShareParticipant => Boolean(entry))
.slice(0, 64)
.map((entry) => {
const avatar = entry.members.get(entry.tsClient.getClientId())?.avatar;
// Send the client id, not the avatar: receivers already hold member
// avatars from the directory, and this roster is rebroadcast to the
// whole channel on every join and leave. Inlining avatars here scales
// with (viewers x avatar size x channel members) per event.
let clientId: number | undefined;
try {
clientId = entry.tsClient.getClientId();
} catch {
clientId = undefined;
}
return {
peerId: entry.screenPeerId,
nickname: entry.nickname,
...(avatar && avatar.length <= 128 * 1024 ? { avatar } : {}),
...(typeof clientId === "number" && clientId > 0 ? { clientId } : {}),
};
});
}