Add local host and path for peerjs (#321)

pull/268/merge
Anastasiia Kim 4 days ago committed by GitHub
parent bda76748b6
commit 54cf03a66d
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194

@ -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

@ -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<NextResponse> {
if (!process.env.COTURN_ENABLED) {
return NextResponse.json({
host: peerjsHost,
path: peerjsPath,
iceServers: [{ urls: stunServer }],
})
}
@ -21,6 +25,8 @@ export async function POST(): Promise<NextResponse> {
await setTurnCredentials(username, password, ttl)
return NextResponse.json({
host: peerjsHost,
path: peerjsPath,
iceServers: [
{ urls: stunServer },
{

@ -34,13 +34,17 @@ async function getOrCreateGlobalPeer(): Promise<Peer> {
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,
},
})
}

Loading…
Cancel
Save