Membrane.WebRTC.Server.Message (WebRTC Server v0.1.3) View Source

Struct defining messages exchanged between peers and rooms.

Fields

  • :data - Main part of the message. Value under that field MUST BE encodable by Jason.Encoder.
  • :event - Topic of the message.
  • :from - Peer ID of a sender.
  • :to - Either list of peer IDs of addressees or "all". If this field is set to "all", the message will be broadcasted: all peers in the room (except for the peer specified under from field) will receive this message.

Messages in Server API

Messages used by Membrane.WebRTC.Server.Room and Membrane.WebRTC.Server.Peer modules:

Note that these are NOT the only types of Messages, that can be used in applications. Custom types can be defined with t/1.

Link to this section Summary

Types

Sent to client after peer successfully initialize and join the room.

Error message.

Broadcasted by a room when a peer joins the room.

Broadcasted by a room when a peer leaves the room.

t()

Type prepared for defining custom Membrane.WebRTC.Server.Message.

Link to this section Types

Link to this type

authenticated_message()

View Source

Specs

authenticated_message() :: %Membrane.WebRTC.Server.Message{
  data: %{peer_id: Membrane.WebRTC.Server.Peer.peer_id()},
  event: String.t(),
  from: nil,
  to: [Membrane.WebRTC.Server.Peer.peer_id()]
}

Sent to client after peer successfully initialize and join the room.

:event is set to "authenticated".

Data fields

  • :peer_id - Identifier of the peer, that has joined the room.

Specs

error_message() :: %Membrane.WebRTC.Server.Message{
  data: %{description: String.t(), details: Jason.Encoder.t()},
  event: String.t(),
  from: nil,
  to: [Membrane.WebRTC.Server.Peer.peer_id()]
}

Error message.

:event is set to "error".

Data fields

  • :description- Topic of error message.
  • :details - Details of error.

Descriptions used in server API

  • "Invalid message" Sent to client after JSON decoding error.

  • "Could not join room" Sent to client after Membrane.WebRTC.Server.Room.on_join/2 return {:error, error}.

  • "Room closed" Send to client after the room's process shut down.

Specs

joined_message() :: %Membrane.WebRTC.Server.Message{
  data: %{peer_id: Membrane.WebRTC.Server.Peer.peer_id()},
  event: String.t(),
  from: nil,
  to: String.t()
}

Broadcasted by a room when a peer joins the room.

:event is set to "joined".

:to is set to "all".

Data fields

  • :peer_id - Identifier of the peer, that has joined the room.

Specs

left_message() :: %Membrane.WebRTC.Server.Message{
  data: %{peer_id: Membrane.WebRTC.Server.Peer.peer_id()},
  event: String.t(),
  from: nil,
  to: String.t()
}

Broadcasted by a room when a peer leaves the room.

:event is set to "left".

Data fields:

  • :peer_id - Identifier of the peer, that has left the room.

Specs

t() :: t(Jason.Encoder.t() | nil)

Specs

t(d) :: %Membrane.WebRTC.Server.Message{
  data: d,
  event: String.t(),
  from: Membrane.WebRTC.Server.Peer.peer_id() | nil,
  to: [Membrane.WebRTC.Server.Peer.peer_id()] | String.t() | nil
}

Type prepared for defining custom Membrane.WebRTC.Server.Message.

d MUST BE encodable by Jason.Encoder.