From 54cf03a66db6e0c904e75d8e9fc266346b7be157 Mon Sep 17 00:00:00 2001 From: Anastasiia Kim <70285484+gingermuffin@users.noreply.github.com> Date: Sat, 20 Dec 2025 23:57:24 +0000 Subject: [PATCH] Add local host and path for peerjs (#321) --- README.md | 2 ++ src/app/api/ice/route.ts | 6 ++++++ src/components/WebRTCProvider.tsx | 6 +++++- 3 files changed, 13 insertions(+), 1 deletion(-) diff --git a/README.md b/README.md index 0268a52..decb9f9 100644 --- a/README.md +++ b/README.md @@ -54,6 +54,8 @@ The server can be customized with the following environment variables: - `TURN_HOST` – Hostname or IP address of the TURN server. Defaults to `127.0.0.1`. - `TURN_REALM` – Realm used when generating TURN credentials. Defaults to `file.pizza`. - `STUN_SERVER` – STUN server URL to use when `COTURN_ENABLED` is disabled. Defaults to `stun:stun.l.google.com:19302`. +- `PEERJS_HOST` – Hostname or IP address to the self-hosted PeerJS server. Defaults to `0.peerjs.com`. +- `PEERJS_PATH` – Path to self-hosted PeerJS server. Defaults to `/`. ## FAQ diff --git a/src/app/api/ice/route.ts b/src/app/api/ice/route.ts index 781772f..fe965ef 100644 --- a/src/app/api/ice/route.ts +++ b/src/app/api/ice/route.ts @@ -4,10 +4,14 @@ import { setTurnCredentials } from '../../../coturn' const turnHost = process.env.TURN_HOST || '127.0.0.1' const stunServer = process.env.STUN_SERVER || 'stun:stun.l.google.com:19302' +const peerjsHost = process.env.PEERJS_HOST || '0.peerjs.com' +const peerjsPath = process.env.PEERJS_PATH || '/' export async function POST(): Promise { if (!process.env.COTURN_ENABLED) { return NextResponse.json({ + host: peerjsHost, + path: peerjsPath, iceServers: [{ urls: stunServer }], }) } @@ -21,6 +25,8 @@ export async function POST(): Promise { await setTurnCredentials(username, password, ttl) return NextResponse.json({ + host: peerjsHost, + path: peerjsPath, iceServers: [ { urls: stunServer }, { diff --git a/src/components/WebRTCProvider.tsx b/src/components/WebRTCProvider.tsx index 7a52bf8..0153e87 100644 --- a/src/components/WebRTCProvider.tsx +++ b/src/components/WebRTCProvider.tsx @@ -34,13 +34,17 @@ async function getOrCreateGlobalPeer(): Promise { const response = await fetch('/api/ice', { method: 'POST', }) - const { iceServers } = await response.json() + const { host, path, iceServers } = await response.json() console.log('[WebRTCProvider] ICE servers:', iceServers) + console.log('[WebRTCProvider] host:', host) + console.log('[WebRTCProvider] path:', path) globalPeer = new Peer({ debug: 3, config: { iceServers, + host, + path, }, }) }