@ -3,6 +3,8 @@ import crypto from 'crypto'
import { setTurnCredentials } from '../../../coturn'
import { setTurnCredentials } from '../../../coturn'
const turnHost = process . env . TURN_HOST || '127.0.0.1'
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 stunServer = process . env . STUN_SERVER || 'stun:stun.l.google.com:19302'
const peerjsHost = process . env . PEERJS_HOST || '0.peerjs.com'
const peerjsHost = process . env . PEERJS_HOST || '0.peerjs.com'
const peerjsPath = process . env . PEERJS_PATH || '/'
const peerjsPath = process . env . PEERJS_PATH || '/'
@ -24,16 +26,16 @@ export async function POST(): Promise<NextResponse> {
// Store credentials in Redis
// Store credentials in Redis
await setTurnCredentials ( username , password , ttl )
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 ( {
return NextResponse . json ( {
host : peerjsHost ,
host : peerjsHost ,
path : peerjsPath ,
path : peerjsPath ,
iceServers : [
iceServers ,
{ urls : stunServer } ,
{
urls : [ ` turn: ${ turnHost } :3478 ` , ` turns: ${ turnHost } :5349 ` ] ,
username ,
credential : password ,
} ,
] ,
} )
} )
}
}