Add a STUN responder to the proxy for screen sharing between browsers

The browser build uses it automatically, so no outside server is contacted.
Covered by unit tests and a two-browser step in the web E2E.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
2026-10-01 21:38:42 +02:00
co-authored by Claude Opus 5.5
parent 13b7013004
commit 826542ed8a
10 changed files with 166 additions and 14 deletions
+6 -2
View File
@@ -5,7 +5,8 @@
import { SHARE, SHARE_DATA_ID, encodeShare, ShareAssembler, type ShareType } from '../core/share-signal.ts';
import type { User } from '../core/client.ts';
import type { Session } from './session.svelte.ts';
import { desktop } from './native.ts';
import { desktop, isWeb } from './native.ts';
import { proxyStun } from './web.svelte.ts';
import { store } from './settings.svelte.ts';
import { ui } from './ui.svelte.ts';
@@ -51,7 +52,10 @@ class ScreenShare {
private iceServers(): RTCIceServer[] {
const stun = store.settings.stunServer.trim();
return stun ? [{ urls: /^stuns?:/.test(stun) ? stun : `stun:${stun}` }] : [];
if (stun) return [{ urls: /^stuns?:/.test(stun) ? stun : `stun:${stun}` }];
// The browser build falls back to the proxy it is served from
const own = isWeb ? proxyStun() : null;
return own ? [{ urls: own }] : [];
}
private others(s: Session): number[] {
+10 -1
View File
@@ -135,14 +135,17 @@ export interface ProxyServer { host: string; port: number; label: string }
class ProxyInfo {
servers = $state<ProxyServer[]>([]);
any = $state(false);
// UDP port of the proxy's STUN responder, if it runs one
stun = $state<number | null>(null);
loaded = $state(false);
error = $state('');
async load(): Promise<void> {
try {
const c = await call<{ servers: ProxyServer[]; any: boolean }>('config');
const c = await call<{ servers: ProxyServer[]; any: boolean; stun?: number | null }>('config');
this.servers = c.servers;
this.any = c.any;
this.stun = c.stun ?? null;
this.error = '';
} catch (e) {
this.error = (e as Error).message;
@@ -151,3 +154,9 @@ class ProxyInfo {
}
}
export const proxyInfo = new ProxyInfo();
// The proxy's own STUN address: a host the user already uses, so nothing new is contacted
export function proxyStun(): string | null {
if (!proxyInfo.stun || !base) return null;
try { return `stun:${new URL(base).hostname}:${proxyInfo.stun}`; } catch { return null; }
}