Audio & Video Bridge | WebRTC
NEW VIDEO BRIDGE and NEW AUDIO BRIDGE allocate a signaling room on Ocalt's servers for a fixed number of peers. The room object they return is overloaded: it carries ready-to-send join links with a built-in minimal call UI, a raw connection URL for wiring into your own frontend, and the room's internal id for closing it later. Ocalt's server only relays signaling - it never touches your audio or video.
Creating a Bridge
Give the number of peers the room should hold. Every peer slot is generated up front, at creation time.
NEW VIDEO BRIDGE 2 PEERS SET ?room
AFTER EMIT ?room("peers")(0)
AFTER EMIT ?room("peers")(1)
NEW AUDIO BRIDGE 2 PEERS SET ?room
AFTER EMIT ?room("peers")(0)
AFTER EMIT ?room("peers")(1)
VIDEO and AUDIO bridges use an identical signaling layer - the only difference is what a peer's frontend requests from getUserMedia(): video and audio together, or audio alone. The built-in UI (see below) handles this for you automatically based on which verb created the room.
The Room Object
The variable you SET the room into - ?room here, but the name is yours - is an overloaded object with three faces. Use whichever fits how you want to build.
| Accessor | What it is |
|---|---|
?room("peers")(i) | A ready-to-send join link for peer slot i. Open it in a browser - or send it to someone - and it loads Ocalt's default minimal call interface, already wired to that slot. No code required. Nothing to build. |
?room("connection") | The raw connection URL - a plain parameter you feed into your own frontend code. Use this when you are building a custom call interface instead of using the ready-made links. |
?room("id") | The internal id/token Ocalt registers for this room. You pass it to BRIDGE CLOSE to tear the room down. |
The Easy Path - Ready-Made Join Links
Each ?room("peers")(i) is a complete, working call page hosted by Ocalt. You do not build anything - you distribute the links. Send peer 0's link to one participant and peer 1's to the other, however you like: email, SMS, a button on your site, a chat message.
NEW VIDEO BRIDGE 2 PEERS SET ?room
AFTER EMIT "Your link: " & ?room("peers")(0)
AFTER EMIT "Their link: " & ?room("peers")(1)
(* Each link opens Ocalt's built-in call UI, already bound to that peer slot.
Whoever opens peer 0's link is peer 0; whoever opens peer 1's link is peer 1. *)
n PEERS creates n join links and lets up to n people be in the room at once. The links are equivalent entry points - identity is assigned as each person actually connects, in the order they arrive, not fixed to a particular link ahead of time. Hand out one link per participant; when the room is full, further connections are refused until someone leaves. If every peer disconnects, the room is torn down after a short grace period.The Custom Path - Your Own Frontend
If you want your own interface instead of the built-in UI, take ?room("connection") and open it from your own JavaScript. It is the same underlying signaling channel the ready-made links use - you are simply supplying your own page around it.
NEW VIDEO BRIDGE 2 PEERS SET ?room
AFTER NEW HTML SET ?page
OPEN
HTML "body"
OPEN
HTML "video" ATTR "id" WITH "local" AND ATTR "autoplay" WITH "" AND ATTR "muted" WITH "" AND ATTR "playsinline" WITH ""
AFTER HTML "video" ATTR "id" WITH "remote" AND ATTR "autoplay" WITH "" AND ATTR "playsinline" WITH ""
AFTER HTML "script" TEXT "const CONNECTION = '" & ?room("connection") & "';"
AFTER HTML "script" ATTR "src" WITH "/your-call-code.js"
CLOSE
CLOSE
AFTER EMIT ?page
Closing a Bridge
A room runs independently of the script that created it. Close it explicitly with a later call, passing the room's id. BRIDGE CLOSE takes any expression that evaluates to that id - a variable, an object field, or a session value.
BRIDGE CLOSE ?room("id")
SET "myroom" AS ?room OF !SESSION
(* ...later request... *)
AFTER SET ?room AS !SESSION("myroom")
AFTER BRIDGE CLOSE ?room("id")
Or just keep the id and close directly against it - no need to reconstruct the object:
SET "myroomid" AS ?room("id") OF !SESSION
(* ...later request... *)
AFTER BRIDGE CLOSE !SESSION("myroomid")
Any of these work: BRIDGE CLOSE ?room("id"), BRIDGE CLOSE ?myid, BRIDGE CLOSE !SESSION("myroomid") - the verb only cares about the id value it receives.What Ocalt's Signaling Server Does
The connection channel carries each peer's room token. Ocalt's server matches peers into the same room and relays SDP offers/answers and ICE candidates between them until their browsers establish a direct (or TURN-relayed) peer-to-peer connection. Once connected, audio and video flow directly between the browsers, never through Ocalt's servers.
Rooms With More Than Two People
A room of more than two peers is a mesh: every browser connects to every other one. Your frontend asks for the mesh when it connects, by adding mesh: true beside the token, and the server then introduces each newcomer to everyone already there instead of to one other peer. A name travels with each peer, so a frontend can label the tiles without a second lookup.
// the room's id is the last part of ?room("connection")
const sock = io("https://bridge.ql.ocalt.com", { auth: { token: ROOM_ID, mesh: true, name: "Thabo" } });
sock.on("mesh_welcome", d => { /* d.you, d.peers: [{ id, name }] - offer to each of them */ });
sock.on("mesh_join", d => { /* d.id, d.name - they will offer to you */ });
sock.on("mesh_leave", d => { /* d.id - close that connection */ });
sock.on("mesh_signal", d => { /* d.from, d.data - an offer, an answer or an ICE candidate */ });
sock.on("mesh_message", d => { /* d.from, d.data - anything one peer sent the room */ });
sock.emit("mesh_signal", { to: peerId, data: { offer } });
sock.emit("mesh_broadcast", { data: { kind: "chat", text: "hello" } });
The newcomer makes the offers, so two peers never offer to each other at once. mesh_signal goes to one peer and mesh_broadcast to everyone else in the room; the server relays both without reading them, which makes the room a channel for chat, reactions and anything else your call needs to say, at no cost beyond the connection. A peer that leaves is announced with mesh_leave, and the call goes on for everyone else. The two-person events above are unchanged, so the ready-made links keep working in the same room.
Full Verb Reference
| Verb | Description |
|---|---|
NEW VIDEO BRIDGE n PEERS SET ?room | Allocate a video signaling room for n peers |
NEW AUDIO BRIDGE n PEERS SET ?room | Allocate an audio-only signaling room for n peers |
?room("peers")(i) | Ready-to-send join link with a built-in minimal UI, bound to peer slot i |
?room("connection") | Raw connection URL parameter for wiring into your own frontend |
?room("id") | The room's internal id/token, used to close it |
BRIDGE CLOSE ?room("id") | Explicitly close a room and its signaling state (id may be any expression) |