View Source Jellyfish.Room (Jellyfish Server SDK v0.4.0)
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, %Jellyfish.Peer{
...> status: :disconnected,
...> type: Jellyfish.Peer.WebRTC,
...> tracks: []
...> } = peer, _peer_token} = 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.
Peer token, created by Jellyfish. Required by client application to open connection to Jellyfish.
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 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 ]
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 tonil
or unspecified, the number of peers is unlimited.:video_codec
- enforces specific video codec for each peer in the room. If set tonil
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.
@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
@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
.
@spec add_peer( Jellyfish.Client.t(), id(), Jellyfish.Peer.options() | Jellyfish.Peer.type() ) :: {:ok, Jellyfish.Peer.t(), peer_token()} | {:error, atom() | String.t()}
Adds a peer to the room with room_id
.
@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
.
@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
.
@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
.
@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
.
@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.
@spec hls_subscribe(Jellyfish.Client.t(), id(), [ Jellyfish.Peer.id() | Jellyfish.Component.id() ]) :: :ok | {:error, atom() | String.t()}
Adds peers and components tracks to hls component
In order to subscribe to HLS peers/components, the HLS 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 via HLS. 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.