publish: mirror TS6's pending-join model instead of refusing

Live testing against a real TS6 client settled how both settings actually
behave, and neither is what the previous commit assumed.

The server enforces nothing. It stores accessibility and viewer_limit,
echoes them back in notifystreamstarted, and then forwards every join
request anyway - a PRIVATE stream at viewer_limit=1 still had both
viewers announced to us. Enforcement is entirely the publisher's job.

And a refusal is the wrong tool for it. TS6's own rule, from main.js:

    !autoAccept || full ? pendingJoinRequests.push(...)
                        : joinStreamResponse(...)

A request it will not take automatically is left *pending*, not denied.
That matters because a denial does not stick - TS6 pairs its own deny
with a ban (blockAndDenyJoinRequest) precisely because of this - so a
refused client just asks again. Measured: 7 retries in 40 s, with nothing
shown to the person waiting. Left pending, the same client asks once and
displays "waiting for access" until answered, then connects normally.

So: PUBLIC with room to spare admits; anything else queues for the user,
including a full stream. Deny is now an explicit choice, and block is the
sticky variant. CONTACTS_ONLY behaves as PRIVATE because the contact list
is a TS6 account feature we cannot read.

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 4d0954054c
commit 13d3f56c89
4 files changed
+174 -15

No files matched your search

+52
View File
@@ -4111,3 +4111,55 @@
min-width: 160px;
}
}
/* A join request waiting for a decision. TS6 shows the viewer "waiting for
access" the whole time this is on screen, so it should not be subtle. */
.ts-stream-request {
display: flex;
align-items: center;
gap: 0.4rem;
padding: 0.45rem 0.55rem;
border-top: 1px solid var(--ts-border, #2a2f3a);
background: var(--ts-accent-soft, rgba(90, 140, 255, 0.12));
font-size: 0.82rem;
}
.ts-stream-request-who {
flex: 1;
min-width: 0;
display: flex;
flex-direction: column;
overflow: hidden;
text-overflow: ellipsis;
white-space: nowrap;
}
.ts-stream-request-who em {
opacity: 0.7;
font-size: 0.75rem;
font-style: normal;
}
.ts-stream-request button {
flex: none;
padding: 0.2rem 0.5rem;
border: 1px solid var(--ts-border, #2a2f3a);
border-radius: 4px;
background: var(--ts-surface, #1b1f27);
color: inherit;
cursor: pointer;
font-size: 0.78rem;
}
.ts-stream-request button:hover {
border-color: var(--ts-accent, #5a8cff);
}
.ts-stream-request-allow {
background: var(--ts-accent, #5a8cff) !important;
color: #fff;
}
.ts-stream-request-block {
opacity: 0.65;
}
+32
View File
@@ -5660,6 +5660,7 @@ function AppInner() {
const streamViewerRef = useRef<StreamViewer | null>(null);
const [publishState, setPublishState] = useState<PublishState>("idle");
const [publishViewers, setPublishViewers] = useState<number[]>([]);
const [publishPending, setPublishPending] = useState<[number, string][]>([]);
const [publishError, setPublishError] = useState<string | null>(null);
const publisherRef = useRef<StreamPublisher | null>(null);
const publishPreviewRef = useRef<HTMLVideoElement | null>(null);
@@ -6624,6 +6625,7 @@ function AppInner() {
publisherRef.current = null;
setPublishState("idle");
setPublishViewers([]);
setPublishPending([]);
removeSession(sessionId, { skipSocketClose: true });
break;
}
@@ -7931,6 +7933,7 @@ function AppInner() {
publisherRef.current = null;
setPublishState("idle");
setPublishViewers([]);
setPublishPending([]);
};
const handleStreamButton = () => {
@@ -7941,6 +7944,9 @@ function AppInner() {
setStreamSettingsOpen(true);
};
const publishClientName = (clid: number) =>
clients.find((c) => c.id === clid)?.name ?? `#${clid}`;
const handleStartPublishing = (options: StreamPublishOptions) => {
if (ownClientId === null) return;
setStreamSettingsOpen(false);
@@ -7955,9 +7961,11 @@ function AppInner() {
if (state === "stopped" || state === "idle") {
publisherRef.current = null;
setPublishViewers([]);
setPublishPending([]);
}
},
onViewersChange: setPublishViewers,
onPendingChange: setPublishPending,
onError: setPublishError,
});
publisherRef.current = publisher;
@@ -9636,6 +9644,30 @@ function AppInner() {
</div>
{/* muted: this is our own capture playing back locally */}
<video ref={publishPreviewRef} autoPlay playsInline muted />
{publishPending.map(([clid, message]) => (
<div className="ts-stream-request" key={clid}>
<span className="ts-stream-request-who">
{publishClientName(clid)}
{message && <em>{message}</em>}
</span>
<button
className="ts-stream-request-allow"
onClick={() => void publisherRef.current?.approve(clid)}
>
{t("publish.request.allow")}
</button>
<button onClick={() => publisherRef.current?.deny(clid)}>
{t("publish.request.deny")}
</button>
<button
className="ts-stream-request-block"
onClick={() => publisherRef.current?.deny(clid, true)}
title={t("publish.request.blockHint")}
>
{t("publish.request.block")}
</button>
</div>
))}
{publishError && <div className="ts-stream-panel-error">{publishError}</div>}
</div>
)}
+8
View File
@@ -382,6 +382,10 @@ const translations: Record<Lang, Record<string, string>> = {
"publish.screen": "Bildschirm",
"publish.starting": "Wird gestartet…",
"publish.viewers": "{count} Zuschauer",
"publish.request.allow": "Zulassen",
"publish.request.deny": "Ablehnen",
"publish.request.block": "Sperren",
"publish.request.blockHint": "Ablehnen und nicht erneut fragen",
"publish.dialog.title": "Stream-Einstellungen",
"publish.dialog.basic": "Grundeinstellungen",
"publish.dialog.advanced": "Erweiterte Einstellungen",
@@ -1011,6 +1015,10 @@ const translations: Record<Lang, Record<string, string>> = {
"publish.screen": "Screen",
"publish.starting": "Starting…",
"publish.viewers": "{count} watching",
"publish.request.allow": "Allow",
"publish.request.deny": "Deny",
"publish.request.block": "Block",
"publish.request.blockHint": "Deny and stop asking",
"publish.dialog.title": "Stream settings",
"publish.dialog.basic": "Basic settings",
"publish.dialog.advanced": "Advanced settings",
+82 -15
View File
@@ -79,6 +79,8 @@ export interface StreamPublisherOptions {
ownClientId: number;
onStateChange?: (state: PublishState) => void;
onViewersChange?: (viewers: number[]) => void;
/** Join requests awaiting a decision, as [clid, message] pairs. */
onPendingChange?: (pending: [number, string][]) => void;
onError?: (error: string) => void;
iceServers?: RTCIceServer[];
}
@@ -95,6 +97,10 @@ interface Viewer {
export class StreamPublisher {
private readonly opts: StreamPublisherOptions;
private readonly viewers = new Map<number, Viewer>();
/** Requests waiting for the user to decide: clid -> the viewer's message. */
private readonly pending = new Map<number, string>();
/** Clients denied with "block"; they are refused without asking again. */
private readonly blocked = new Set<number>();
private media: MediaStream | null = null;
private state: PublishState = "idle";
private options: StreamPublishOptions | null = null;
@@ -191,7 +197,21 @@ export class StreamPublisher {
}
}
/** Accepts a viewer and sends it our offer. */
/**
* Decides what to do with an incoming join request.
*
* This mirrors TS6's own publisher-side rule, which is the only place either
* setting is enforced at all - the server stores `accessibility` and
* `viewer_limit`, echoes them back, and then forwards every request anyway
* (verified live: a PRIVATE stream at viewer_limit=1 still had both viewers
* announced to us).
*
* The important half is what happens to a request we do not take: TS6 leaves
* it *pending* rather than refusing it. A refusal is not sticky - TS6's own
* "block" path is deny plus a ban - so a refused client simply asks again, in
* a loop, and shows its user nothing. Left pending, it asks once and displays
* "waiting for access" until we answer.
*/
private async admit(args: Record<string, string>): Promise<void> {
const clid = Number(args.clid);
if (!Number.isFinite(clid) || !this.media || !this.streamId) return;
@@ -199,26 +219,66 @@ export class StreamPublisher {
// is_remove=1 is how TS6 says "stop watching"; the same notify carries it.
if (args.is_remove === "1") {
this.dropViewer(clid);
this.pending.delete(clid);
this.notifyPending();
return;
}
if (this.viewers.has(clid)) return;
if (this.viewers.has(clid) || this.pending.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",
});
// Explicitly blocked earlier: refuse without bothering the user again.
if (this.blocked.has(clid)) {
this.refuse(clid, "Blocked");
return;
}
const limit = this.options?.viewerLimit ?? 0;
const full = limit > 0 && this.viewers.size >= limit;
const autoAccept = this.options?.accessibility === StreamAccess.PUBLIC && !full;
if (!autoAccept) {
// CONTACTS_ONLY behaves as PRIVATE here: the contact list is a TS6
// account feature webspeak3 has no access to, so it cannot be consulted.
this.pending.set(clid, args.msg ?? "");
this.notifyPending();
return;
}
await this.openTo(clid);
}
/** Lets a pending viewer in. Called by admit() or by the user. */
async approve(clid: number): Promise<void> {
if (!this.pending.delete(clid)) return;
this.notifyPending();
await this.openTo(clid);
}
/**
* Turns a pending viewer away. `block` also remembers the refusal, which is
* what makes it stick - TS6 pairs its deny with a ban for the same reason.
*/
deny(clid: number, block = false): void {
this.pending.delete(clid);
if (block) this.blocked.add(clid);
this.notifyPending();
this.refuse(clid, block ? "Blocked" : "Denied");
}
private refuse(clid: number, message: string): void {
if (!this.streamId) return;
this.opts.send({
type: "respondJoinStream",
streamId: this.streamId,
clientId: clid,
accept: false,
message,
});
}
/** Builds the peer connection for a viewer we have decided to let in. */
private async openTo(clid: number): Promise<void> {
if (!this.media || !this.streamId || this.viewers.has(clid)) return;
const pc = new RTCPeerConnection({ iceServers: this.opts.iceServers ?? DEFAULT_ICE_SERVERS });
const viewer: Viewer = { pc, pending: [], answered: false };
this.viewers.set(clid, viewer);
@@ -378,11 +438,14 @@ export class StreamPublisher {
private teardown(state: PublishState): void {
for (const [, viewer] of this.viewers) viewer.pc.close();
this.viewers.clear();
this.pending.clear();
this.blocked.clear();
for (const track of this.media?.getTracks() ?? []) track.stop();
this.media = null;
this.streamId = null;
this.options = null;
this.notifyViewers();
this.notifyPending();
this.setState(state);
}
@@ -404,6 +467,10 @@ export class StreamPublisher {
this.opts.onViewersChange?.([...this.viewers.keys()]);
}
private notifyPending(): void {
this.opts.onPendingChange?.([...this.pending.entries()]);
}
private fail(message: string): void {
this.opts.onError?.(message);
}