Browser Client (JS)
Octoroom ships zero-npm browser ES modules in priv/static/:
priv/static/octoroom.mjs— CoreRoomClientfor Phoenix Channels + WebRTC media.agents/priv/static/octoroom_agents.mjs—agents(room)helper for AI agent presence, transcripts, and text messages.
Joining a room
Section titled “Joining a room”import { RoomClient } from "octoroom";
const room = new RoomClient({ socket, // connected Phoenix Socket topic: `room:${roomId}`, params: { name: "Ada" }, video: true, // optional: also publish camera on join});
room.on("participants", (list) => renderParticipants(list));room.on("tracks", (tracks) => renderVideos(tracks));
await room.join(); // requests mic (and camera if video: true), publishes, and plays remote audioRemote audio plays automatically at the gain configured by the room server. For remote video, attach each video track’s stream to a <video> element’s srcObject:
function renderVideos(tracks) { for (const track of tracks) { if (track.kind === "video") { // track.source is "camera", "screen", or null (for a worker video output) // track.participant_id identifies the sender videoElement.srcObject = track.stream; } }}Media controls
Section titled “Media controls”room.setMuted(true); // mute micawait room.startCamera(); // publish camera after joiningawait room.shareScreen(); // publish screen shareroom.mute("camera", true); // sends black frames without WebRTC renegotiationawait room.stop("camera"); // unpublish cameraawait room.leave();Whether a participant’s camera is muted is reflected in participants via participant.tracks.camera.muted.
Workers & AI agents
Section titled “Workers & AI agents”Subscribe to worker state and events directly on RoomClient, or wrap it with agents(room) from octoroom_agents.mjs:
import { agents } from "octoroom_agents";
const ai = agents(room);
ai.on("agents", (list) => { // [{ id, name, description, state }] — listening, thinking, speaking, waiting renderAgentList(list);});
ai.on("transcript", ({ agent, items }) => { renderTranscript(agent, items);});
// Typed messages are always answered regardless of respond: / gate:await ai.say("assistant", "add Acme to the sheet");Low-level worker messaging is also available via await room.send("assistant", { text: "hi" }), which rejects with "not_allowed", "no_worker", "too_large", or "rate_limited" if refused by the server.
Reconnection & join timings
Section titled “Reconnection & join timings”- Automatic resume: When the Phoenix socket reconnects (including after a server restart),
RoomClientrejoins with itsresume_tokenso the existing WebRTC peer connection stays up. Listen for"reconnecting"and"reconnected"({ resumed }). - Join timings: Listen for
"timings"to inspectjoin_ms,media_ms,ice_ms,publish_ms, andconnect_ms(these are also reported to the server asOctoroom.Telemetry).