Membrane.WebRTC.Server.Room behaviour (WebRTC Server v0.1.3) View Source
A behaviour module for WebRTC room that manages peers and mediate in their communication.
Rooms have to be created explicitly (preferably by start_supervised/2
function).
Link to this section Summary
Types
Defines a custom state of the room, passed as argument and returned by callbacks.
Functions
Returns a specification to start this module under a supervisor.
Forwards the message to the addressees given under message.to
key.
Starts a room based on the options.module
, registers it in options.registry
(under the options.name
) and links it to the current process.
Creates a room under the default room supervisor.
Stops room process.
Callbacks
Callback invoked before forwarding messages either peers.
Callback invoked when a room is created.
Callback invoked when a peer is about to join the room.
Callback invoked when a peer is leaving the room.
Callback invoked when the room is shutting down.
Link to this section Types
Specs
internal_state() :: any()
Defines a custom state of the room, passed as argument and returned by callbacks.
Link to this section Functions
Returns a specification to start this module under a supervisor.
See Supervisor
.
Specs
forward_message(room :: pid(), message :: Membrane.WebRTC.Server.Message.t()) :: :ok | {:error, :no_such_peer} | {:error, :unknown_error}
Forwards the message to the addressees given under message.to
key.
Messages meant to be broadcasted should have message.to
set to "all". Broadcasted message will
be forwarded to all peers, except for sender (given under message.from
).
Specs
start_link(options :: Membrane.WebRTC.Server.Room.Options.t()) :: GenServer.on_start()
Starts a room based on the options.module
, registers it in options.registry
(under the options.name
) and links it to the current process.
options.custom_options
are passed to module's on_init/1
callback.
Specs
start_supervised(options :: Membrane.WebRTC.Server.Room.Options.t()) :: DynamicSupervisor.on_start_child()
Creates a room under the default room supervisor.
Calls start_link/1
underneath.
Specs
stop(room :: pid()) :: :ok
Stops room process.
Link to this section Callbacks
Specs
on_forward( message :: Membrane.WebRTC.Server.Message.t(), state :: internal_state() ) :: {:ok, internal_state()} | {:ok, Membrane.WebRTC.Server.Message.t(), internal_state()}
Callback invoked before forwarding messages either peers.
This mean this callback will be invoked every time message is forwarded or the room broadcasts messages by itself (e.g. when peer joins the room).
Room will forward_message message returned by this callback, ergo returning {:ok, state}
will cause ignoring message.
Specs
on_init(options :: Membrane.WebRTC.Server.Room.Options.custom_options()) :: {:ok, internal_state()}
Callback invoked when a room is created.
Specs
on_join( auth_data :: Membrane.WebRTC.Server.Peer.AuthData.t(), state :: internal_state() ) :: {:ok, internal_state()} | {{:error, error :: atom()}, internal_state()}
Callback invoked when a peer is about to join the room.
Useful for authorizing or performing other checks (e.g. controlling number of peers in room).
Returning {:error, error}
will cause peer sending
Membrane.WebRTC.Server.Message.error_message/0
to the client and closing WebSocket.
Specs
on_leave( peer_id :: Membrane.WebRTC.Server.Peer.peer_id(), state :: internal_state() ) :: {:ok, internal_state()}
Callback invoked when a peer is leaving the room.
Specs
on_terminate(state :: internal_state()) :: :ok
Callback invoked when the room is shutting down.
Useful for any cleanup required.