mirror of
https://github.com/Moepchi/webspeak3.git
synced 2026-12-03 01:42:50 +08:00
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:
1 parent
4d0954054c
commit
13d3f56c89
4 files changed
+174
-15
No files matched your search
@@ -4111,3 +4111,55 @@
|
|||||||
min-width: 160px;
|
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;
|
||||||
|
}
|
||||||
@@ -5660,6 +5660,7 @@ function AppInner() {
|
|||||||
const streamViewerRef = useRef<StreamViewer | null>(null);
|
const streamViewerRef = useRef<StreamViewer | null>(null);
|
||||||
const [publishState, setPublishState] = useState<PublishState>("idle");
|
const [publishState, setPublishState] = useState<PublishState>("idle");
|
||||||
const [publishViewers, setPublishViewers] = useState<number[]>([]);
|
const [publishViewers, setPublishViewers] = useState<number[]>([]);
|
||||||
|
const [publishPending, setPublishPending] = useState<[number, string][]>([]);
|
||||||
const [publishError, setPublishError] = useState<string | null>(null);
|
const [publishError, setPublishError] = useState<string | null>(null);
|
||||||
const publisherRef = useRef<StreamPublisher | null>(null);
|
const publisherRef = useRef<StreamPublisher | null>(null);
|
||||||
const publishPreviewRef = useRef<HTMLVideoElement | null>(null);
|
const publishPreviewRef = useRef<HTMLVideoElement | null>(null);
|
||||||
@@ -6624,6 +6625,7 @@ function AppInner() {
|
|||||||
publisherRef.current = null;
|
publisherRef.current = null;
|
||||||
setPublishState("idle");
|
setPublishState("idle");
|
||||||
setPublishViewers([]);
|
setPublishViewers([]);
|
||||||
|
setPublishPending([]);
|
||||||
removeSession(sessionId, { skipSocketClose: true });
|
removeSession(sessionId, { skipSocketClose: true });
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
@@ -7931,6 +7933,7 @@ function AppInner() {
|
|||||||
publisherRef.current = null;
|
publisherRef.current = null;
|
||||||
setPublishState("idle");
|
setPublishState("idle");
|
||||||
setPublishViewers([]);
|
setPublishViewers([]);
|
||||||
|
setPublishPending([]);
|
||||||
};
|
};
|
||||||
|
|
||||||
const handleStreamButton = () => {
|
const handleStreamButton = () => {
|
||||||
@@ -7941,6 +7944,9 @@ function AppInner() {
|
|||||||
setStreamSettingsOpen(true);
|
setStreamSettingsOpen(true);
|
||||||
};
|
};
|
||||||
|
|
||||||
|
const publishClientName = (clid: number) =>
|
||||||
|
clients.find((c) => c.id === clid)?.name ?? `#${clid}`;
|
||||||
|
|
||||||
const handleStartPublishing = (options: StreamPublishOptions) => {
|
const handleStartPublishing = (options: StreamPublishOptions) => {
|
||||||
if (ownClientId === null) return;
|
if (ownClientId === null) return;
|
||||||
setStreamSettingsOpen(false);
|
setStreamSettingsOpen(false);
|
||||||
@@ -7955,9 +7961,11 @@ function AppInner() {
|
|||||||
if (state === "stopped" || state === "idle") {
|
if (state === "stopped" || state === "idle") {
|
||||||
publisherRef.current = null;
|
publisherRef.current = null;
|
||||||
setPublishViewers([]);
|
setPublishViewers([]);
|
||||||
|
setPublishPending([]);
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
onViewersChange: setPublishViewers,
|
onViewersChange: setPublishViewers,
|
||||||
|
onPendingChange: setPublishPending,
|
||||||
onError: setPublishError,
|
onError: setPublishError,
|
||||||
});
|
});
|
||||||
publisherRef.current = publisher;
|
publisherRef.current = publisher;
|
||||||
@@ -9636,6 +9644,30 @@ function AppInner() {
|
|||||||
</div>
|
</div>
|
||||||
{/* muted: this is our own capture playing back locally */}
|
{/* muted: this is our own capture playing back locally */}
|
||||||
<video ref={publishPreviewRef} autoPlay playsInline muted />
|
<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>}
|
{publishError && <div className="ts-stream-panel-error">{publishError}</div>}
|
||||||
</div>
|
</div>
|
||||||
)}
|
)}
|
||||||
|
|||||||
@@ -382,6 +382,10 @@ const translations: Record<Lang, Record<string, string>> = {
|
|||||||
"publish.screen": "Bildschirm",
|
"publish.screen": "Bildschirm",
|
||||||
"publish.starting": "Wird gestartet…",
|
"publish.starting": "Wird gestartet…",
|
||||||
"publish.viewers": "{count} Zuschauer",
|
"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.title": "Stream-Einstellungen",
|
||||||
"publish.dialog.basic": "Grundeinstellungen",
|
"publish.dialog.basic": "Grundeinstellungen",
|
||||||
"publish.dialog.advanced": "Erweiterte Einstellungen",
|
"publish.dialog.advanced": "Erweiterte Einstellungen",
|
||||||
@@ -1011,6 +1015,10 @@ const translations: Record<Lang, Record<string, string>> = {
|
|||||||
"publish.screen": "Screen",
|
"publish.screen": "Screen",
|
||||||
"publish.starting": "Starting…",
|
"publish.starting": "Starting…",
|
||||||
"publish.viewers": "{count} watching",
|
"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.title": "Stream settings",
|
||||||
"publish.dialog.basic": "Basic settings",
|
"publish.dialog.basic": "Basic settings",
|
||||||
"publish.dialog.advanced": "Advanced settings",
|
"publish.dialog.advanced": "Advanced settings",
|
||||||
|
|||||||
+82
-15
@@ -79,6 +79,8 @@ export interface StreamPublisherOptions {
|
|||||||
ownClientId: number;
|
ownClientId: number;
|
||||||
onStateChange?: (state: PublishState) => void;
|
onStateChange?: (state: PublishState) => void;
|
||||||
onViewersChange?: (viewers: number[]) => void;
|
onViewersChange?: (viewers: number[]) => void;
|
||||||
|
/** Join requests awaiting a decision, as [clid, message] pairs. */
|
||||||
|
onPendingChange?: (pending: [number, string][]) => void;
|
||||||
onError?: (error: string) => void;
|
onError?: (error: string) => void;
|
||||||
iceServers?: RTCIceServer[];
|
iceServers?: RTCIceServer[];
|
||||||
}
|
}
|
||||||
@@ -95,6 +97,10 @@ interface Viewer {
|
|||||||
export class StreamPublisher {
|
export class StreamPublisher {
|
||||||
private readonly opts: StreamPublisherOptions;
|
private readonly opts: StreamPublisherOptions;
|
||||||
private readonly viewers = new Map<number, Viewer>();
|
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 media: MediaStream | null = null;
|
||||||
private state: PublishState = "idle";
|
private state: PublishState = "idle";
|
||||||
private options: StreamPublishOptions | null = null;
|
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> {
|
private async admit(args: Record<string, string>): Promise<void> {
|
||||||
const clid = Number(args.clid);
|
const clid = Number(args.clid);
|
||||||
if (!Number.isFinite(clid) || !this.media || !this.streamId) return;
|
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.
|
// is_remove=1 is how TS6 says "stop watching"; the same notify carries it.
|
||||||
if (args.is_remove === "1") {
|
if (args.is_remove === "1") {
|
||||||
this.dropViewer(clid);
|
this.dropViewer(clid);
|
||||||
|
this.pending.delete(clid);
|
||||||
|
this.notifyPending();
|
||||||
return;
|
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
|
// Explicitly blocked earlier: refuse without bothering the user again.
|
||||||
// server turns anyone away - so the publisher enforces its own limit. This
|
if (this.blocked.has(clid)) {
|
||||||
// is the only place that can: we are the one handing out peer connections,
|
this.refuse(clid, "Blocked");
|
||||||
// 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;
|
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 pc = new RTCPeerConnection({ iceServers: this.opts.iceServers ?? DEFAULT_ICE_SERVERS });
|
||||||
const viewer: Viewer = { pc, pending: [], answered: false };
|
const viewer: Viewer = { pc, pending: [], answered: false };
|
||||||
this.viewers.set(clid, viewer);
|
this.viewers.set(clid, viewer);
|
||||||
@@ -378,11 +438,14 @@ export class StreamPublisher {
|
|||||||
private teardown(state: PublishState): void {
|
private teardown(state: PublishState): void {
|
||||||
for (const [, viewer] of this.viewers) viewer.pc.close();
|
for (const [, viewer] of this.viewers) viewer.pc.close();
|
||||||
this.viewers.clear();
|
this.viewers.clear();
|
||||||
|
this.pending.clear();
|
||||||
|
this.blocked.clear();
|
||||||
for (const track of this.media?.getTracks() ?? []) track.stop();
|
for (const track of this.media?.getTracks() ?? []) track.stop();
|
||||||
this.media = null;
|
this.media = null;
|
||||||
this.streamId = null;
|
this.streamId = null;
|
||||||
this.options = null;
|
this.options = null;
|
||||||
this.notifyViewers();
|
this.notifyViewers();
|
||||||
|
this.notifyPending();
|
||||||
this.setState(state);
|
this.setState(state);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -404,6 +467,10 @@ export class StreamPublisher {
|
|||||||
this.opts.onViewersChange?.([...this.viewers.keys()]);
|
this.opts.onViewersChange?.([...this.viewers.keys()]);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private notifyPending(): void {
|
||||||
|
this.opts.onPendingChange?.([...this.pending.entries()]);
|
||||||
|
}
|
||||||
|
|
||||||
private fail(message: string): void {
|
private fail(message: string): void {
|
||||||
this.opts.onError?.(message);
|
this.opts.onError?.(message);
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in new issue
Block a user