WebRTC Configuration Reference

WebRTC listener configuration for the Elide HTTP server.

A WebRTC listener binds a UDP socket for STUN/DTLS/SCTP traffic and dispatches incoming data-channel connections to a JS handler. Each listener manages its own set of PeerConnections independently.

Multiple listeners can be configured for different ports, handler scripts, or isolation boundaries (e.g., one per tenant).

Example

pkl
webrtc {
  new WebRtcListener {
    port = 3478
    handler = "./rtc-handler.js"
    contextMode = "daemon"
    iceServers { "stun:stun.l.google.com:19302" }
  }
}

> This page is auto-generated from the PKL schema. See the guide for usage examples.

Types

ContextMode

JS context lifecycle mode for the handler that processes data-channel connections.

"spawn" — create a fresh JS context per incoming connection. Each connection gets a clean global scope with no shared state. Higher isolation but more overhead per connection. "daemon" — dispatch all connections to a single long-running JS context. Lower overhead, suitable for stateful handlers that need to coordinate across connections.
pkl
typealias ContextMode = "spawn" | "daemon"

---

WebRtcListener

Describes a single WebRTC listener endpoint.

Each listener binds one UDP socket and manages its own pool of PeerConnections. Multiple listeners can coexist on different ports for isolation by JS isolate, tenant, or realm.
FieldTypeDefaultDescription
portUInt16(isPositive)(required)UDP port to bind for STUN/DTLS/SCTP traffic.
handlerString?nullPath to a JS handler script for data-channel dispatch.
contextModeContextMode"spawn"JS context lifecycle for the handler script.
iceServersListing(empty)ICE server URIs for NAT traversal.
maxConnectionsUInt0Maximum number of concurrent PeerConnections on this listener.
idleTimeoutDuration60.sIdle timeout for PeerConnections with no active data channels.

port

UDP port to bind for STUN/DTLS/SCTP traffic.

The listener binds on all interfaces (0.0.0.0:). Must be a positive 16-bit integer.

handler

Path to a JS handler script for data-channel dispatch.

When set, incoming data-channel connections are forwarded to this script's default export. When null, the WebRTC transport is active but data channels must be consumed via the programmatic API.

contextMode

JS context lifecycle for the handler script.

Controls whether each connection gets its own JS context or shares one with all other connections. See ContextMode.

Default: "spawn" (one context per connection).

iceServers

ICE server URIs for NAT traversal.

Accepts both STUN and TURN URIs:
pkl
`"stun:stun.l.google.com:19302"`
`"turn:turn.example.com:3478?transport=udp"`

When empty (default), only host candidates are gathered — the listener will not attempt STUN binding or TURN relay allocation.

maxConnections

Maximum number of concurrent PeerConnections on this listener.

When the limit is reached, new connection attempts receive an ICE failure. Default: 0 (unlimited).

idleTimeout

Idle timeout for PeerConnections with no active data channels.

PeerConnections that remain idle (no open data channels) longer than this duration are closed automatically. Set to 0.s to disable idle cleanup. Default: 60 seconds.

---