feat: optional TURN relay for screen streams

TURN_URLS on the gateway is handed to the browser in "hello" and added to the
STUN defaults for both watching and publishing. With TURN_SECRET (coturn's
use-auth-secret) each socket gets its own credential valid for 24 h; static
TURN_USERNAME/TURN_CREDENTIAL work too but are public to every visitor.

Also moves GATEWAY_FEATURES above the runtime-config comment it had split.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01Hu2cuPLqpuKVfd9wWFFakU
This commit is contained in:
MoepchiandClaude Opus 5.5 committed 2026-10-03 00:58:22 +00:00
1 parent d67053f2dd
commit 23e61c86b3
5 files changed
+30 -14

No files matched your search

+6 -1
View File
@@ -34,7 +34,7 @@ import {
type PublishState,
type StreamPublishOptions,
} from "./publish";
import { StreamViewer, parseStreamInfo, type StreamEvent, type StreamInfo } from "./stream";
import { DEFAULT_ICE_SERVERS, StreamViewer, parseStreamInfo, type StreamEvent, type StreamInfo } from "./stream";
import { DEMO_HOST, DEMO_MODE, DemoSocket } from "./demoMode";
import {
SOUND_EVENTS,
@@ -6424,6 +6424,8 @@ function AppInner() {
// What the gateway announced in its "hello" (gateway/src/index.ts). Empty for
// a gateway older than the handshake, so a feature newer than it stays hidden.
const [gatewayFeatures, setGatewayFeatures] = useState<ReadonlySet<string>>(new Set());
// TURN relay the gateway offers for screen streams (TURN_URLS), if any.
const [turnServers, setTurnServers] = useState<RTCIceServer[]>([]);
// Terms of use, own-hosted instance only (see IS_OWN_HOSTED_INSTANCE): shown
// mandatorily on first visit, reopenable any time from the menu afterwards.
const [tosOpen, setTosOpen] = useState(false);
@@ -7290,6 +7292,7 @@ function AppInner() {
}
if (data.type === "hello") {
setGatewayFeatures(new Set(Array.isArray(data.features) ? data.features : []));
setTurnServers(Array.isArray(data.iceServers) ? data.iceServers : []);
return;
}
@@ -8989,6 +8992,7 @@ function AppInner() {
const viewer = new StreamViewer(info.id, info.clientId, {
send: (message) => socketRef.current?.send(JSON.stringify(message)),
onTrack: setStreamMedia,
iceServers: [...DEFAULT_ICE_SERVERS, ...turnServers],
onStateChange: setStreamState,
onError: setStreamError,
onClosed: () => {
@@ -9042,6 +9046,7 @@ function AppInner() {
onViewersChange: setPublishViewers,
onPendingChange: setPublishPending,
onError: setPublishError,
iceServers: [...DEFAULT_ICE_SERVERS, ...turnServers],
});
publisherRef.current = publisher;
void publisher.start(options);
+1 -7
View File
@@ -15,7 +15,7 @@
// TS6's P2P mode is a mesh: there is no SFU in the path, so every viewer gets
// its own peer connection and its own copy of the encoded media.
import type { StreamEvent } from "./stream";
import { DEFAULT_ICE_SERVERS, type StreamEvent } from "./stream";
// The three enums below are read straight out of TS6's own UI bundle
// (main.js), not inferred - see ts6-re/findings §10.
@@ -44,12 +44,6 @@ export const StreamMode = {
SFU: 2,
} as const;
const DEFAULT_ICE_SERVERS: RTCIceServer[] = [
{ urls: "stun:turn.teamspeak.com:3478" },
{ urls: "stun:turn2.teamspeak.com:3478" },
{ urls: "stun:stun.l.google.com:19302" },
];
export interface StreamPublishOptions {
name: string;
/** Send the capture's audio track too, when the source has one. */
+1 -1
View File
@@ -62,7 +62,7 @@ export interface StreamViewerOptions {
iceServers?: RTCIceServer[];
}
const DEFAULT_ICE_SERVERS: RTCIceServer[] = [
export const DEFAULT_ICE_SERVERS: RTCIceServer[] = [
{ urls: "stun:turn.teamspeak.com:3478" },
{ urls: "stun:turn2.teamspeak.com:3478" },
{ urls: "stun:stun.l.google.com:19302" },