From bcbd1f221930813dce863fcbe8d19179cd0aff5d Mon Sep 17 00:00:00 2001 From: hieuit095 <139037144+hieuit095@users.noreply.github.com> Date: Fri, 27 Mar 2026 00:46:58 +0700 Subject: [PATCH] docs(app): add support for custom turn port and fix docker networking The current TURN configuration defaults to port 3478 but doesn't allow customization for the port. In Docker Compose setups, the TURN server may be on a different port or host. Additionally, the current configuration doesn't properly handle TLS vs non-TLS TURN connections. Affected files: route.ts Signed-off-by: hieuit095 <139037144+hieuit095@users.noreply.github.com> --- src/app/api/ice/route.ts | 18 ++++++++++-------- 1 file changed, 10 insertions(+), 8 deletions(-) diff --git a/src/app/api/ice/route.ts b/src/app/api/ice/route.ts index 7c4c7ff..110e99c 100644 --- a/src/app/api/ice/route.ts +++ b/src/app/api/ice/route.ts @@ -3,6 +3,8 @@ import crypto from 'crypto' import { setTurnCredentials } from '../../../coturn' const turnHost = process.env.TURN_HOST || '127.0.0.1' +const turnPort = parseInt(process.env.TURN_PORT || '3478', 10) +const turnTlsPort = parseInt(process.env.TURN_TLS_PORT || '5349', 10) 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 || '/' @@ -24,16 +26,16 @@ export async function POST(): Promise { // Store credentials in Redis await setTurnCredentials(username, password, ttl) + const iceServers: { urls: string; username?: string; credential?: string }[] = [ + { urls: stunServer }, + { urls: `turn:${turnHost}:${turnPort}`, username, credential: password }, + { urls: `turn:${turnHost}:${turnPort}?transport=tcp`, username, credential: password }, + { urls: `turns:${turnHost}:${turnTlsPort}?transport=tcp`, username, credential: password }, + ] + return NextResponse.json({ host: peerjsHost, path: peerjsPath, - iceServers: [ - { urls: stunServer }, - { - urls: [`turn:${turnHost}:3478`, `turns:${turnHost}:5349`], - username, - credential: password, - }, - ], + iceServers, }) }