Octoroom (octoroom v0.1.0)

Copy Markdown View Source

Programmable voice and video rooms for Phoenix apps, carried by Cloudflare Realtime SFU.

See Octoroom.Room for writing a room and Octoroom.Worker for server-side participants.

Summary

Functions

Subscribes the calling process to a room's events. It then receives {:octoroom, room_id, event} messages. scope: is required and says which events

Removes every subscription the calling process has to the room's events.

Functions

subscribe(room_id, opts)

Subscribes the calling process to a room's events. It then receives {:octoroom, room_id, event} messages. scope: is required and says which events:

  • scope: {:participant, id}: what participant id's client is sent, and nothing else. Use it for a process that renders a room for one user, such as a LiveView. The id isn't checked against anything: pass the id of the participant your code authenticated.
  • scope: :room: everything, for trusted code that doesn't act for a user (a recorder, analytics, an admin view).

With scope: {:participant, id}, event is one of:

  • {:joined, participant} and {:left, participant}, for other participants
  • {:updated, participant}: its metadata changed, or a source it publishes was muted, unmuted or unpublished (see its tracks)
  • {:published, participant}: a source it publishes (mic, camera, screen) is live at Cloudflare
  • {:worker, :added | :updated | :removed, presence}: a worker it now sees (it's subscribed to one of the worker's outputs), whose presence changed, or that it no longer sees. presence is %{id, outputs, data, state, attributes}, or just %{id} when removed.

  • {:worker_notify, worker_id, output, type, data}: a worker's notify: on an output it's subscribed to

With scope: :room, those (including the participant's own joins and leaves, every notify: except those sent to one participant, and {:worker, :updated, presence} for every presence change, but no :added or :removed) plus:

  • {:subscriptions, participant_id, track_names}: what it now hears
  • {:disconnected, participant}: its connection dropped; it's kept for the grace period
  • {:output_live, track_name}: a worker output sent its first packet
  • {:worker_event, worker_id, event}: whatever a worker emits
  • {:worker_down, worker_id, reason}: a worker crashed
  • {:error, what, reason}: the room gave up on something

The subscription is kept across room restarts, and a process may subscribe before the room or the participant exists.

unsubscribe(room_id)

Removes every subscription the calling process has to the room's events.