View Source Jellyfish.Room (Jellyfish Server SDK v0.5.1)

Utilities for manipulating the rooms.

Examples

iex> client = Jellyfish.Client.new()
iex> assert {:ok, %Jellyfish.Room{
...>    components: [],
...>    config: %{max_peers: 10, video_codec: nil},
...>    peers: []
...>  } = room, _jellyfish_address} = Jellyfish.Room.create(client, max_peers: 10)
iex> room == %Jellyfish.Room{
...>    id: room.id,
...>    components: [],
...>    config: %{max_peers: 10, video_codec: nil},
...>    peers: []}
true
iex> assert {:ok, %{peer: %Jellyfish.Peer{
...>    status: :disconnected,
...>    type: Jellyfish.Peer.WebRTC,
...>    tracks: []
...> } = peer}} = Jellyfish.Room.add_peer(client, room.id, Jellyfish.Peer.WebRTC)
iex> %Jellyfish.Peer{
...>    id: peer.id,
...>    status: :disconnected,
...>    type: Jellyfish.Peer.WebRTC,
...>    tracks: [],
...>    metadata: nil} == peer
true
iex> :ok = Jellyfish.Room.delete(client, room.id)
:ok

Summary

Types

Id of the room, unique within Jellyfish instance.

Options used for creating a room.

Jellyfish response to adding a peer to room. It consists of

Peer token, created by Jellyfish. Required by client application to open connection to Jellyfish.

t()

Stores information about the room.

Id of the track, unique within Jellyfish instance.

Functions

Adds a component to the room with room_id.

Adds a peer to the room with room_id.

Creates a new room.

Deletes the room with room_id.

Deletes the component with component_id from the room with room_id.

Deletes the peer with peer_id from the room with room_id.

Starts a phone call from a specified component to a provided phone number.

End a phone call on a specified SIP component.

Gets properties of the room with room_id.

Lists properties of all of the rooms.

Adds peers and components tracks to hls or recording component

Types

@type id() :: String.t()

Id of the room, unique within Jellyfish instance.

@type options() :: [
  room_id: String.t() | nil,
  max_peers: non_neg_integer() | nil,
  video_codec: :h264 | :vp8 | nil,
  webhook_url: String.t() | nil,
  peerless_purge_timeout: pos_integer() | nil,
  peer_disconnected_timeout: pos_integer() | nil
]

Options used for creating a room.

  • :room_id - custom room id, which uniquely identifies room. If not provided a random UUID is generated.
  • :max_peers - maximum number of peers present in a room simultaneously. If set to nil or unspecified, the number of peers is unlimited.
  • :video_codec - enforces specific video codec for each peer in the room. If set to nil or unspecified, any codec will be accepted. To use HLS component video codec has to be :h264.
  • :webhook_url - an address of a server receiving webhook notifications from the room.
  • :peerless_purge_timeout - duration (in seconds) after which the room will be removed if no peers are connected. If not provided, this feature is disabled.
  • :peer_disconnected_timeout - duration (in seconds) after which the peer will be removed if it is disconnected. If not provided, this feature is disabled.
Link to this type

peer_create_response()

View Source
@type peer_create_response() :: %{
  peer: Jellyfish.Peer.t(),
  token: peer_token(),
  ws_url: String.t()
}

Jellyfish response to adding a peer to room. It consists of:

  • peer structure
  • token used for authentication when connecting through websocket to jellyfish
  • ws_url that is a websocket adress to which this specific peer have to connect
@type peer_token() :: String.t()

Peer token, created by Jellyfish. Required by client application to open connection to Jellyfish.

@type t() :: %Jellyfish.Room{
  components: [Jellyfish.Component.t()],
  config: map(),
  id: id(),
  peers: [Jellyfish.Peer.t()]
}

Stores information about the room.

@type track_id() :: String.t()

Id of the track, unique within Jellyfish instance.

Functions

Link to this function

add_component(client, room_id, component)

View Source
@spec add_component(
  Jellyfish.Client.t(),
  id(),
  Jellyfish.Component.options() | Jellyfish.Component.type()
) :: {:ok, Jellyfish.Component.t()} | {:error, atom() | String.t()}

Adds a component to the room with room_id.

Link to this function

add_peer(client, room_id, peer)

View Source
@spec add_peer(
  Jellyfish.Client.t(),
  id(),
  Jellyfish.Peer.options() | Jellyfish.Peer.type()
) ::
  {:ok, peer_create_response()} | {:error, atom() | String.t()}

Adds a peer to the room with room_id.

Link to this function

create(client, opts \\ [])

View Source
@spec create(Jellyfish.Client.t(), options()) ::
  {:ok, t(), String.t()} | {:error, atom() | String.t()}

Creates a new room.

Returns an address of Jellyfish where the room was created. When running Jellyfish in a cluster, this address might be different than the one used in the initial call. Therefore, it is important to call Jellyfish.Client.update_address/2 before subsequent operations like adding peers or components.

@spec delete(Jellyfish.Client.t(), id()) :: :ok | {:error, atom() | String.t()}

Deletes the room with room_id.

Link to this function

delete_component(client, room_id, component_id)

View Source
@spec delete_component(Jellyfish.Client.t(), id(), Jellyfish.Component.id()) ::
  :ok | {:error, atom() | String.t()}

Deletes the component with component_id from the room with room_id.

Link to this function

delete_peer(client, room_id, peer_id)

View Source
@spec delete_peer(Jellyfish.Client.t(), id(), Jellyfish.Peer.id()) ::
  :ok | {:error, atom() | String.t()}

Deletes the peer with peer_id from the room with room_id.

Link to this function

dial(client, room_id, component_id, phone_number)

View Source
@spec dial(Jellyfish.Client.t(), id(), Jellyfish.Component.id(), String.t()) ::
  :ok | {:error, atom() | String.t()}

Starts a phone call from a specified component to a provided phone number.

This is asynchronous operation. In case of providing incorrect phone number you will receive a notification ComponentCrashed.

Link to this function

end_call(client, room_id, component_id)

View Source
@spec end_call(Jellyfish.Client.t(), id(), Jellyfish.Component.id()) ::
  :ok | {:error, atom() | String.t()}

End a phone call on a specified SIP component.

This is asynchronous operation.

@spec get(Jellyfish.Client.t(), id()) :: {:ok, t()} | {:error, atom() | String.t()}

Gets properties of the room with room_id.

@spec get_all(Jellyfish.Client.t()) :: {:ok, [t()]} | {:error, atom() | String.t()}

Lists properties of all of the rooms.

Link to this function

subscribe(client, room_id, component_id, origins)

View Source
@spec subscribe(Jellyfish.Client.t(), id(), Jellyfish.Component.id(), [
  Jellyfish.Peer.id() | Jellyfish.Component.id()
]) :: :ok | {:error, atom() | String.t()}

Adds peers and components tracks to hls or recording component

In order to subscribe the component to peers/components, the component should be initialized with the subscribe_mode set to :manual. This mode proves beneficial when you do not wish to record or stream all the available streams within a room. It allows for selective addition instead – you can manually select specific streams. For instance, you could opt to record only the stream of an event's host.