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>
pull/348/head
hieuit095 2 months ago
parent 3258673e79
commit bcbd1f2219

@ -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<NextResponse> {
// 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,
})
}

Loading…
Cancel
Save