From 4d0954054c2dd5af3ee349a1e9708732277fe494 Mon Sep 17 00:00:00 2001 From: Moepchi Date: Thu, 10 Sep 2026 20:24:55 +0000 Subject: [PATCH] publish: actually enforce the viewer limit viewer_limit went out with setupstream and was then never looked at again - admit() handed a peer connection to every join request that arrived. Nothing establishes that the server turns anyone away, so the setting was advisory at best. The publisher is the only side that can enforce it: it is the one handing out peer connections, and in P2P mode each one is another encode. respondJoinStream(accept: false) was already plumbed end to end down to decision=0 in the connector; it just had no caller. Co-Authored-By: Claude Opus 5 Claude-Session: https://claude.ai/code/session_01Hu2cuPLqpuKVfd9wWFFakU --- web/src/publish.ts | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) diff --git a/web/src/publish.ts b/web/src/publish.ts index e59dbcd..379b32d 100644 --- a/web/src/publish.ts +++ b/web/src/publish.ts @@ -203,6 +203,22 @@ export class StreamPublisher { } if (this.viewers.has(clid)) return; + // `viewer_limit` goes out with setupstream, but nothing guarantees the + // server turns anyone away - so the publisher enforces its own limit. This + // is the only place that can: we are the one handing out peer connections, + // and in P2P mode each one costs another encode. + const limit = this.options?.viewerLimit ?? 0; + if (limit > 0 && this.viewers.size >= limit) { + this.opts.send({ + type: "respondJoinStream", + streamId: this.streamId, + clientId: clid, + accept: false, + message: "Stream is full", + }); + return; + } + const pc = new RTCPeerConnection({ iceServers: this.opts.iceServers ?? DEFAULT_ICE_SERVERS }); const viewer: Viewer = { pc, pending: [], answered: false }; this.viewers.set(clid, viewer);