Skip to content

Getting Started

Octoroom uses ex_webrtc, which requires the system libsrtp library:

Terminal window
brew install srtp

Add this to your app’s config/config.exs so ex_libsrtp builds against your system libsrtp (the precompiled artifact links a libcrypto that isn’t on the default path):

config/config.exs
config :bundlex, :disable_precompiled_os_deps, apps: [:ex_libsrtp]

Add :octoroom (and optionally :octoroom_agents if you want AI voice/vision participants) to mix.exs:

defp deps do
[
{:octoroom, "~> 0.1.0"},
{:octoroom_agents, "~> 0.1.0"} # optional: AI voice & vision agents
]
end

Then fetch and compile:

Terminal window
mix deps.get

Local development (no Cloudflare account required)

Section titled “Local development (no Cloudflare account required)”

Octoroom ships with Octoroom.Cloudflare.Local, an in-process localhost SFU backed by ex_webrtc. It lets you test multi-party audio, video, and workers locally with zero credentials:

config/dev.exs
config :octoroom,
cloudflare: [client: Octoroom.Cloudflare.Local],
ice_servers: []

In production, configure Octoroom.Cloudflare.HTTP (the default client) with your Cloudflare Realtime SFU app credentials:

config/runtime.exs
config :octoroom,
cloudflare: [
client: Octoroom.Cloudflare.HTTP,
app_id: System.fetch_env!("CLOUDFLARE_SFU_APP_ID"),
app_secret: System.fetch_env!("CLOUDFLARE_SFU_APP_SECRET")
]

A room is a module using Octoroom.Room. Only join/2 is required—subscriptions/2 defaults to subscribing every participant to every other participant’s mic, camera, screen share, and every worker output:

defmodule MyApp.CallRoom do
use Octoroom.Room
@impl true
def join(%{"name" => name}, _socket) do
{:ok, %{name: name}}
end
end

Mount a Phoenix channel backed by your room:

defmodule MyAppWeb.RoomChannel do
use Octoroom.Phoenix.Channel, room: MyApp.CallRoom
end

Register it in your Phoenix UserSocket:

lib/my_app_web/channels/user_socket.ex
channel "room:*", MyAppWeb.RoomChannel

The room ID is everything after the first : in the topic—so "room:lobby" starts room "lobby", and "room:support:1234" starts room "support:1234".

Octoroom includes a zero-npm ES module browser client at priv/static/octoroom.mjs:

import { RoomClient } from "octoroom";
const room = new RoomClient({
socket, // a connected Phoenix Socket
topic: "room:lobby",
params: { name: "Ada" },
video: true,
});
room.on("participants", (list) => console.log("Participants:", list));
room.on("tracks", (tracks) => {
// Remote audio plays automatically; attach remote video tracks to <video> elements
for (const track of tracks) {
if (track.kind === "video") {
videoEl.srcObject = track.stream;
}
}
});
await room.join();