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

+5
View File
@@ -1313,6 +1313,7 @@ const screenShareControls = useWebClientScreenShare({
leaveScreenShare,
nickname,
avatarStyle,
memberAvatar: memberAvatarById,
t,
});
const { settingsOpen: screenShareSettingsOpen, errorText: screenShareErrorText } = screenShareControls;
@@ -2190,6 +2191,10 @@ function avatarStyle(name: string, isSelf = false, avatar = "") {
};
}
function memberAvatarById(clientId: number): string {
return members.find((candidate) => candidate.id === clientId)?.avatar ?? "";
}
function messageAvatar(message: ChatMessage): string {
const member = members.find((candidate) =>
(typeof message.senderId === "number" && candidate.id === message.senderId) ||