fix(screen-share): keep the announced viewer count in step with the roster

Two smaller gaps left over from removing the inline avatars.

The announced viewerCount summed the viewer entry ids and the native viewer
ids, while the roster silently dropped ids whose participant had vanished
from the entry map. A client that disappears without passing through the
leave path therefore inflated the count for as long as the stream lived.
Prune those ids, and derive the count in the same call that builds the
roster so the two can no longer disagree.

The legacy inline-avatar path capped each entry at 128 KiB but placed no
bound on the roster total, which still allowed 64 x 128 KiB in a single
broadcast. Bound the total as well; entries past the budget fall back to
the client-side member lookup like any other viewer without an avatar.

Both behaviours are covered by new tests: a dropped entry no longer
inflates the count, and eight 128 KiB avatars are trimmed to the budget
(measured at 1048576 bytes without the bound).
This commit is contained in:
LainHE committed 2026-10-16 09:50:26 +08:00
1 parent bfa26da9eb
commit bcc78177c2
5 files changed
+89 -7

No files matched your search

+15 -1
View File
@@ -255,15 +255,29 @@ export class ScreenShareCoordinator {
return {
type: "screenShareViewerCount",
streamId: stream.streamId,
viewerCount: stream.viewerCount,
// Derive the count from the same call as the roster so the announced
// number can never disagree with the entries actually listed.
viewerCount: this.screenShareViewerCount(stream),
viewers: this.describeScreenViewers(stream),
};
}
private screenShareViewerCount(stream: ScreenStreamRecord): number {
this.pruneStaleViewers(stream);
return stream.viewerEntryIds.size + stream.nativeViewerClids.size;
}
/**
* Drop viewer entries whose participant is gone. A client can disappear from
* the entry map without passing through the leave path, and a lingering id
* inflates the announced count while the roster silently omits it.
*/
private pruneStaleViewers(stream: ScreenStreamRecord): void {
for (const entryId of [...stream.viewerEntryIds.keys()]) {
if (!this.entries.has(entryId)) stream.viewerEntryIds.delete(entryId);
}
}
private broadcastScreenMessage(stream: ScreenStreamRecord, message: ServerMessage, excludeEntryId?: string): void {
for (const candidate of this.entries.values()) {
if (candidate.id === excludeEntryId || candidate.target && teamSpeakTargetKey(candidate.target) !== stream.targetKey) continue;