olcRTC exposes two embeddable Go packages:Documentation Index
Fetch the complete documentation index at: https://mintlify.com/openlibrecommunity/olcrtc/llms.txt
Use this file to discover all available pages before exploring further.
pkg/olcrtc provides a client session that returns a net.Conn-compatible handle backed by a WebRTC data channel, while pkg/olcrtc/tunnel provides the server-side tunnel that accepts encrypted connections and proxies them to arbitrary TCP targets. Both packages can be imported independently into any Go program.
Installation
pkg/olcrtc
Import path:github.com/openlibrecommunity/olcrtc/pkg/olcrtc
This package implements the client half of the tunnel. It handles authentication with a built-in provider (jitsi, telemost, wbstream) or connects directly to any LiveKit-compatible SFU, then returns a net.Conn whose reads and writes are transparently relayed over WebRTC.
RegisterDefaults
livekit, goolom, jitsi) and auth providers (jitsi, telemost, wbstream). Safe to call multiple times. Use this when you do not want to manage blank imports manually.
Config
Config is the input to New. Fill only the fields that apply to your mode.
| Field | Type | Description |
|---|---|---|
Auth | string | Built-in auth provider name: "jitsi", "telemost", or "wbstream". When set, auth mode is used and RoomID is forwarded to the provider. |
RoomID | string | Room reference for the auth provider — typically the full Jitsi room URL, e.g. "https://meet.example.org/myroom". |
Engine | string | Direct engine mode: "livekit", "goolom", or "jitsi". Defaults to "livekit" when Auth is empty. |
URL | string | SFU WebSocket URL for direct engine mode (e.g. "wss://sfu.example/"). |
Token | string | JWT token for direct engine mode. |
Name | string | Display name used when joining the conference room. |
DNSServer | string | Optional custom DNS resolver address, e.g. "8.8.8.8:53". |
ProxyAddr | string | Outbound SOCKS5 proxy host. |
ProxyPort | int | Outbound SOCKS5 proxy port. |
Session
Session is the library handle returned by New. It is not connected until Dial or Connect is called.
New
Session from cfg. If cfg.Auth is set, the built-in auth provider is used; otherwise direct engine mode applies (requires URL and Token).
Returns ErrURLRequired or ErrTokenRequired when required direct-mode fields are missing. Returns an error if the named auth provider is not registered.
Dial
net.Conn backed by the WebRTC data channel. This is the highest-level entry point — it calls Connect internally, starts the connection watcher in a goroutine, and wraps everything in a net.Conn interface.
The returned net.Conn:
Readis backed by anio.Pipefed by the engine’sOnDatacallback.Writecalls the engine’sSendmethod.SetDeadline/SetReadDeadline/SetWriteDeadlinereturnerrors.ErrUnsupported— use context cancellation instead.- When the session ends permanently,
ReadreturnsErrSessionEnded.
Connect
ctx is cancelled. Lower-level than Dial — use Dial unless you need manual control.
Send
Close
WatchConnection
Dial launches this in a background goroutine. Call it manually only if you are using Connect directly.
CanSend
SetEndedCallback
Close. The reason string describes why the session ended.
SetShouldReconnect
false from fn to disable reconnection.
CreateRoom
jitsi, telemost, wbstream) currently return ErrRoomCreationUnsupported.
Error Variables
| Variable | Description |
|---|---|
ErrURLRequired | Returned when direct engine mode is used without setting Config.URL. |
ErrTokenRequired | Returned when direct engine mode is used without setting Config.Token. |
ErrRoomCreationUnsupported | Returned by CreateRoom when the auth provider does not support room creation. |
ErrSessionEnded | Returned from Read/Write on the net.Conn when the session has ended permanently. |
Code Examples
pkg/olcrtc/tunnel
Import path:github.com/openlibrecommunity/olcrtc/pkg/olcrtc/tunnel
This package implements the server half of the tunnel. A Server connects to a WebRTC SFU room, accepts encrypted smux streams from clients, and proxies each stream to the client-requested TCP target.
In the tunnel API, the
Carrier field in Config is kept for compatibility
with existing integrations. Semantically it is the auth.provider name —
the same values apply: "jitsi", "telemost", "wbstream", "none".RegisterDefaults (tunnel)
jitsi, telemost, wbstream), links, and transports (datachannel, videochannel, seichannel, vp8channel). Safe to call multiple times.
Config
| Field | Description |
|---|---|
Transport | WebRTC transport to use: "datachannel", "videochannel", "seichannel", or "vp8channel". |
Carrier | Auth provider / carrier name: "jitsi", "telemost", "wbstream", or "none" for direct engine mode. |
RoomURL | The conference room identifier passed to the carrier (e.g. a Jitsi room URL). |
Engine | Direct engine name when Carrier == "none": "livekit", "goolom", or "jitsi". |
URL | SFU WebSocket URL for direct engine mode. |
Token | JWT for direct engine mode. |
KeyHex | 64-character hex string (32 bytes) — the shared encryption key. Generate with openssl rand -hex 32. Must match the client. |
DNSServer | Custom DNS resolver for target TCP dials, e.g. "8.8.8.8:53". |
SOCKSProxyAddr | Outbound SOCKS5 proxy host for target connections. |
SOCKSProxyPort | Outbound SOCKS5 proxy port. |
SOCKSProxyUser | SOCKS5 proxy username (RFC 1929). |
SOCKSProxyPass | SOCKS5 proxy password (RFC 1929). |
TransportOptions | Transport-specific tuning (e.g. vp8channel.Options). Pass nil for datachannel. |
AuthHook | func(deviceID string, claims map[string]any) (string, error) — authorizes the client and issues a session ID. Returning a non-nil error rejects the handshake. If nil, every client is admitted with a random UUID. |
OnSessionOpen | func(sid, dev string, claims map[string]any) — fires after a successful handshake, before tunnel streams are accepted. |
OnSessionClose | func(sid, reason string) — fires when a session ends. Reason is "reconnect" or "closed". |
OnTraffic | func(sid, addr string, in, out uint64) — fires once per tunnel stream; in = client→target bytes, out = target→client bytes. |
New
Server configured by cfg. The server is not started until Run is called.
Run
ctx is cancelled or the carrier disconnects. Returns an error if the carrier cannot be reached or if the server exits abnormally.
Code Example
The
AuthHook error message is forwarded to the client as the rejection
reason, so it should not leak sensitive internal details.