authoravatarclover caruso<git@paperclover.net>2026-11-22 11:31:43+00:00
committeravatarclover caruso<git@paperclover.net>2026-11-22 11:39:56+00:00
logd559ec390582fe4bd7e029097434273bbe1ddd9b
tree897212ae55cce903824bc68a6d7ac3c30f1b48ef
parent1e32e2ab9fc916bbdefd5efe7a151e083345c19f

Expose native Snowcord voice media alongside Pion

Publish a separate native UDP port and route the Phoenix VM tailnet address to it. Share the fixed endpoint relay with the guest and preserve the existing voice hostname and Pion listener. Assisted-by: gpt-6.2-sol

6 files changed, 73 insertions(+), 4 deletions(-)

nixos/snowglobe.nix+13-1
...@@ -7,7 +7,7 @@ let...@@ -7,7 +7,7 @@ let
7 xmppUDPPorts = [ xmppNetwork.turn xmppNetwork.turn_tls ];7 xmppUDPPorts = [ xmppNetwork.turn xmppNetwork.turn_tls ];
8 irohNetwork = builtins.fromJSON (builtins.readFile ../service/iroh-relay/network.json);8 irohNetwork = builtins.fromJSON (builtins.readFile ../service/iroh-relay/network.json);
9 spacebarVoice = builtins.fromJSON (builtins.readFile ../service/spacebar/voice-network.json);9 spacebarVoice = builtins.fromJSON (builtins.readFile ../service/spacebar/voice-network.json);
10 udpPorts = xmppUDPPorts ++ [ irohNetwork.quic spacebarVoice.media ];10 udpPorts = xmppUDPPorts ++ [ irohNetwork.quic spacebarVoice.media spacebarVoice.nativeMedia ];
11 encryptionRoots = {11 encryptionRoots = {
12 clover = "clover";12 clover = "clover";
13 media = "clover/Media";13 media = "clover/Media";
...@@ -40,6 +40,18 @@ in...@@ -40,6 +40,18 @@ in
40 reverse_proxy 127.0.0.1:${toString spacebarVoice.signaling}40 reverse_proxy 127.0.0.1:${toString spacebarVoice.signaling}
41 '';41 '';
4242
43 systemd.services.phoenix-voice-udp-relay = {
44 wantedBy = [ "multi-user.target" ];
45 wants = [ "network-online.target" ];
46 after = [ "network-online.target" "nomad.service" ];
47 serviceConfig = {
48 DynamicUser = true;
49 ExecStart = "${pkgs.nodejs_24}/bin/node ${../tools/phoenix-voice-udp-relay.mjs} ${spacebarVoice.phoenixRelayAddress} ${(builtins.head config.networking.interfaces.enp4s0.ipv4.addresses).address} ${toString spacebarVoice.nativeMedia}";
50 Restart = "always";
51 RestartSec = 5;
52 };
53 };
54
43 systemd.services.public-ports = {55 systemd.services.public-ports = {
44 wantedBy = [ "multi-user.target" ];56 wantedBy = [ "multi-user.target" ];
45 wants = [ "network-online.target" ];57 wants = [ "network-online.target" ];
service/spacebar/build/supervisor.mjs+6-1
...@@ -9,7 +9,7 @@ import { createInterface } from "node:readline";...@@ -9,7 +9,7 @@ import { createInterface } from "node:readline";
9import { setTimeout as sleep } from "node:timers/promises";9import { setTimeout as sleep } from "node:timers/promises";
10import { promisify } from "node:util";10import { promisify } from "node:util";
1111
12const { BRANCH, PORT, VOICE_PUBLIC_HOST, VOICE_SIGNALING_PORT, VOICE_MEDIA_PORT } = process.env;12const { BRANCH, PORT, VOICE_PUBLIC_HOST, VOICE_SIGNALING_PORT, VOICE_MEDIA_PORT, VOICE_NATIVE_MEDIA_PORT } = process.env;
13const WORK = "/work";13const WORK = "/work";
14const REPO = "/source.git";14const REPO = "/source.git";
15const POLL_MS = 250;15const POLL_MS = 250;
...@@ -231,6 +231,11 @@ async function startVoice(release) {...@@ -231,6 +231,11 @@ async function startVoice(release) {
231 WRTC_PUBLIC_IP: ip,231 WRTC_PUBLIC_IP: ip,
232 WRTC_PORT_MIN: VOICE_MEDIA_PORT,232 WRTC_PORT_MIN: VOICE_MEDIA_PORT,
233 WRTC_PORT_MAX: VOICE_MEDIA_PORT,233 WRTC_PORT_MAX: VOICE_MEDIA_PORT,
234 ...(VOICE_NATIVE_MEDIA_PORT ? {
235 VOICE_UDP_PORT: VOICE_NATIVE_MEDIA_PORT,
236 VOICE_UDP_PUBLIC_IP: ip,
237 VOICE_UDP_LOOPBACK_RELAY: "true",
238 } : {}),
234 });239 });
235 await waitForVoice(voice.signaling, () => fetch(`http://127.0.0.1:${VOICE_SIGNALING_PORT}/`, {240 await waitForVoice(voice.signaling, () => fetch(`http://127.0.0.1:${VOICE_SIGNALING_PORT}/`, {
236 signal: AbortSignal.timeout(1000),241 signal: AbortSignal.timeout(1000),
service/spacebar/service.pkl+2
...@@ -41,6 +41,7 @@ container {...@@ -41,6 +41,7 @@ container {
41 when (!site.preview) {41 when (!site.preview) {
42 new { name = "voice"; containerPort = voice.signaling; hostPort = containerPort }42 new { name = "voice"; containerPort = voice.signaling; hostPort = containerPort }
43 new { name = "voice-media"; containerPort = voice.media; hostPort = containerPort; loopback = false }43 new { name = "voice-media"; containerPort = voice.media; hostPort = containerPort; loopback = false }
44 new { name = "voice-native-media"; containerPort = voice.nativeMedia; hostPort = containerPort; loopback = false }
44 }45 }
45 }46 }
4647
...@@ -64,6 +65,7 @@ container {...@@ -64,6 +65,7 @@ container {
64 ["VOICE_PUBLIC_HOST"] = voiceHost65 ["VOICE_PUBLIC_HOST"] = voiceHost
65 ["VOICE_SIGNALING_PORT"] = voice.signaling.toString()66 ["VOICE_SIGNALING_PORT"] = voice.signaling.toString()
66 ["VOICE_MEDIA_PORT"] = voice.media.toString()67 ["VOICE_MEDIA_PORT"] = voice.media.toString()
68 ["VOICE_NATIVE_MEDIA_PORT"] = voice.nativeMedia.toString()
67 }69 }
68 }70 }
6971
service/spacebar/voice-network.json+3-1
...@@ -1,5 +1,7 @@...@@ -1,5 +1,7 @@
1{1{
2 "subdomain": "voice.phoenix-selfhosted",2 "subdomain": "voice.phoenix-selfhosted",
3 "signaling": 17404,3 "signaling": 17404,
4 "media": 60004 "media": 6000,
5 "nativeMedia": 6001,
6 "phoenixRelayAddress": "100.64.0.1"
5}7}
tools/phoenix-voice-udp-relay.mjs created+41
...@@ -0,0 +1,41 @@
1import { createSocket } from "node:dgram";
2import { isIPv4 } from "node:net";
3
4const [listenAddress, upstreamAddress, configuredPort] = process.argv.slice(2);
5const port = Number(configuredPort);
6if (!isIPv4(listenAddress ?? "") || !isIPv4(upstreamAddress ?? "") || listenAddress === upstreamAddress ||
7 listenAddress === "0.0.0.0" || upstreamAddress === "0.0.0.0" || !Number.isInteger(port) || port < 1 || port > 65535) {
8 throw new Error("Expected distinct local and upstream IPv4 addresses and a fixed shared UDP port");
9}
10
11const listener = createSocket("udp4");
12const clients = new Map();
13
14listener.on("message", (packet, remote) => {
15 if (!packet.length || packet.length > 4096) return;
16 const key = `${remote.address}:${remote.port}`;
17 let client = clients.get(key);
18 if (!client) {
19 if (clients.size >= 64) return;
20 const socket = createSocket("udp4");
21 const close = () => {
22 clients.delete(key);
23 clearTimeout(idle);
24 socket.close();
25 };
26 const idle = setTimeout(close, 300_000).unref();
27 client = { socket, idle };
28 clients.set(key, client);
29 // Keep the upstream tuple stable for this caller's discovery and media.
30 socket.on("message", (reply, source) => {
31 if (source.address !== upstreamAddress || source.port !== port || reply.length > 4096) return;
32 idle.refresh();
33 if (listener.getSendQueueCount() < 64) listener.send(reply, remote.port, remote.address, () => {});
34 });
35 socket.once("error", close);
36 }
37 client.idle.refresh();
38 if (client.socket.getSendQueueCount() < 64) client.socket.send(packet, port, upstreamAddress, () => {});
39});
40
41listener.bind(port, listenAddress);
tools/spacebar.md+8-1
...@@ -54,10 +54,17 @@ start that is still waiting. Rolling back is pushing the old commit again....@@ -54,10 +54,17 @@ start that is still waiting. Rolling back is pushing the old commit again.
5454
55The production service publishes the voice WebSocket at `voice.phoenix-selfhosted.paperclover.net:443`.55The production service publishes the voice WebSocket at `voice.phoenix-selfhosted.paperclover.net:443`.
56[`voice-network.json`](../service/spacebar/voice-network.json) configures the56[`voice-network.json`](../service/spacebar/voice-network.json) configures the
57loopback WebSocket mapping and the UDP media port. The supervisor builds Pion57WebSocket port and separate UDP ports for Pion and native Discord voice. The supervisor builds Pion
58from the Snowcord revision's `flake.lock`: git fetches the pinned commit, `go.sum`58from the Snowcord revision's `flake.lock`: git fetches the pinned commit, `go.sum`
59pins the modules, and the build and SFU run with a minimal environment. The binary59pins the modules, and the build and SFU run with a minimal environment. The binary
60is kept in `/work` for that pin, so a restart needs no network.60is kept in `/work` for that pin, so a restart needs no network.
61It starts one SFU and one standalone voice process after the API is healthy.61It starts one SFU and one standalone voice process after the API is healthy.
62Each app release restarts voice, and an unavailable voice process retries62Each app release restarts voice, and an unavailable voice process retries
63while the API continues serving. Previews leave voice disabled.63while the API continues serving. Previews leave voice disabled.
64
65Snow Globe's tailnet UDP relay forwards the native media port to the published
66container port. The Phoenix VM uses the same relay tool bound to loopback with
67Snow Globe's tailnet address as upstream. Its gateway relay sets
68`X-Snowcord-Voice-Relay: phoenix-loopback` so voice advertises the VM's loopback
69address. The guest profile lets Phoenix bind and receive UDP on its temporary
70ports and send UDP only to the local relay port.