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

+28 -2
View File
@@ -15,7 +15,7 @@ before(async () => {
({ default: VoiceChannelTree } = await vite.ssrLoadModule("/src/components/web-client/VoiceChannelTree.vue"));
});
after(async () => { await vite?.close(); });
function mount(t, initialStream = null) {
function mount(t, initialStream = null, memberAvatar = () => "") {
const listeners = new Set(), starts = [], storage = new Map(); let exits = 0, ui;
class Element {}
class Video extends Element { srcObject = null; volume = 1; plays = 0; async play() { this.plays++; } }
@@ -26,7 +26,7 @@ function mount(t, initialStream = null) {
t.after(() => { if (original) Object.defineProperty(globalThis, key, original); else delete globalThis[key]; });
}
const viewing = shallowRef(true), stream = shallowRef(initialStream), volume = shallowRef(.4), streams = [];
const app = renderer.createApp({ setup() { ui = useWebClientScreenShare({ streams, viewing, viewingStreamId: shallowRef("s"), remoteStream: stream, remoteVolume: volume, error: shallowRef(""), errorCode: shallowRef(""), startScreenShare: async (...args) => starts.push(args), joinScreenShare() {}, leaveScreenShare() {}, nickname: shallowRef("Self"), avatarStyle: () => ({}), t: key => key }); return () => null; } });
const app = renderer.createApp({ setup() { ui = useWebClientScreenShare({ streams, viewing, viewingStreamId: shallowRef("s"), remoteStream: stream, remoteVolume: volume, error: shallowRef(""), errorCode: shallowRef(""), startScreenShare: async (...args) => starts.push(args), joinScreenShare() {}, leaveScreenShare() {}, nickname: shallowRef("Self"), avatarStyle: () => ({}), memberAvatar, t: key => key }); return () => null; } });
app.mount({});
return { ui, app, doc, viewing, stream, volume, streams, starts, storage, listeners, exits: () => exits, video: () => markRaw(new Video()), player: () => markRaw(new Element()) };
}
@@ -98,6 +98,32 @@ test("known screen owner IDs cannot fall back to another member with the same ni
} finally { f.app.unmount(); }
});
test("viewers resolve their avatar locally from a client id instead of the roster payload", async t => {
// `streams` is a plain array, so `viewers` (a computed) caches its first read:
// each scenario needs its own mount.
async function avatarFor(viewer, memberAvatar = () => "") {
const f = mount(t, null, memberAvatar);
try {
f.streams[0] = { streamId: "s", viewers: [viewer] };
await nextTick();
assert.equal(f.ui.viewers.value.length, 1);
return f.ui.viewers.value[0].avatar;
} finally { f.app.unmount(); }
}
// Current gateway: the roster carries a client id and the avatar comes from the directory.
assert.equal(
await avatarFor({ peerId: "v", nickname: "Visitor", clientId: 42 }, clientId => (clientId === 42 ? "data:image/png;base64,LOCAL" : "")),
"data:image/png;base64,LOCAL",
);
// Legacy gateway: the inline avatar still renders.
assert.equal(
await avatarFor({ peerId: "v", nickname: "Visitor", avatar: "data:image/png;base64,LEGACY" }),
"data:image/png;base64,LEGACY",
);
// Unknown member: degrades to the initial instead of throwing.
assert.equal(await avatarFor({ peerId: "v", nickname: "Visitor", clientId: 99 }), "");
});
test("member cards detect and expose a remote share without depending on local share status", async () => {
let lookupCount = 0;
const html = await renderToString(createSSRApp(VoiceMemberCards, {