mob_webrtc

WebRTC peer connections for Mob apps: ex_webrtc running on the device's BEAM, with its DTLS (ex_dtls, OpenSSL) and SRTP (ex_libsrtp, libsrtp2) NIFs linked into the app statically. One Elixir API on iOS, Android and the host.

Video is RTP in and out: the app hands it encoded frames as RTP packets (the H264 mob_screencast produces, for example) and incoming H264 is decoded into MobWebrtc.VideoView. Audio is a media path of its own: MobWebrtc.Audio encodes the microphone with Opus (through mob_audio_io, whose default :voice preset is the platform's echo-cancelling input) and plays the remote side through an adaptive playout buffer. Data channels carry messages. See the design records in mob, decisions/2026-11-27-webrtc-engine-split.md and decisions/2026-11-27-webrtc-media-plane-in-plugin.md.

Install

# mix.exs
{:mob_webrtc, "~> 0.1"}

# mob.exs (mob_audio_io comes with mob_webrtc; MobWebrtc.Audio plays and records through it)
config :mob, :plugins, [:mob_webrtc, :mob_audio_io]

# mob.exs: ex_sctp's Rustler crate, linked as a static NIF. Every peer needs
# it (ex_webrtc sets up SCTP in each one), not only data channels: without
# this line start_peer/1 answers {:error, {:native, status}}.
config :mob_dev,
  static_nifs: [%{module: :ex_sctp, init: "nif_init", archs: [:all]}]

Then mix mob.plugin.trust mob_webrtc and mix mob.deploy --native.

ex_webrtc compiles its data-channel code only when ExSCTP is there at its compile time: in a project that built ex_webrtc before it had ex_sctp, run mix deps.compile ex_webrtc --force once.

ex_sctp's crate (rustler 0.34) exports its init function as plain nif_init, so it can't share an app with another Rustler crate that does the same: iOS fails the link with a duplicate symbol and Android could link only one of them.

The native build needs:

Use

{:ok, peer} = MobWebrtc.start_peer(ice_servers: [%{urls: "stun:stun.l.google.com:19302"}])
{:ok, track} = MobWebrtc.add_track(peer, :video)
{:ok, offer} = MobWebrtc.create_offer(peer)
:ok = MobWebrtc.set_local_description(peer, offer)
# send `offer` to the remote side over your signaling channel, then:
:ok = MobWebrtc.set_remote_description(peer, answer)

def handle_info({:mob_webrtc, peer, {:ice_candidate, candidate}}, socket) # -> send to remote
def handle_info({:mob_webrtc, peer, {:connection_state, :connected}}, socket)
def handle_info({:mob_webrtc, peer, {:keyframe_request, track}}, socket)  # e.g. MobScreencast.request_keyframe()

MobWebrtc.send_rtp(peer, track, %ExRTP.Packet{...})

Descriptions and candidates are JSON-shaped maps with string keys, the shapes a browser's RTCPeerConnection uses, so signaling can pass them through. The full message and error list is in MobWebrtc's moduledoc.

Support

iOS Android Host
Peers, ICE, DTLS-SRTP, RTP ✓ ✓ ✓ with host NIFs
Data channels (ex_sctp) ✓ ✓ ✓
Opus audio (MobWebrtc.Audio) ✓ ✓ ✗ ({:error, :nif_not_loaded})
H264 decode into MobWebrtc.VideoView ✓ (VideoToolbox) ✓ (MediaCodec) ✗

For agents

Repository