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 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01Hu2cuPLqpuKVfd9wWFFakU
This commit is contained in:
MoepchiandClaude Opus 5 committed 2026-09-11 05:26:33 +00:00
1 parent 115cd7150e
commit 4d0954054c
1 file changed
+16
+16
View File
@@ -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);