# Erlang/elixir sample code for real time voice chat?

**URL:** <https://forum.elixirforum.com/t/erlang-elixir-sample-code-for-real-time-voice-chat/38809>\
**Category:** Questions\
**Tags:** troubleshooting\
**Created:** [April 8, 2021, 6:26am UTC](https://forum.elixirforum.com/t/erlang-elixir-sample-code-for-real-time-voice-chat/38809 "2021-04-08T06:26:57Z")\
**Posts on this page:** 1\
**Showing post:** 8

<div class="post-metadata">

**Author:** ![mat-hek](https://forum.elixirforum.com/user_avatar/forum.elixirforum.com/mat-hek/32/38168_2.png) [@mat-hek](https://forum.elixirforum.com/u/mat-hek)\
**Post date:** [April 9, 2021, 10:31am UTC](https://forum.elixirforum.com/t/erlang-elixir-sample-code-for-real-time-voice-chat/38809/8 "2021-04-09T10:31:08Z")

</div>

1. It’s an [SFU server](https://bloggeek.me/webrtc-multiparty-video-alternatives/)

2. You can easily find a lot of information about WebRTC on the net, for example at [https://webrtchacks.com/](https://webrtchacks.com/). In short, it goes like that:

- before starting the transmission, the session is negotiated (network addresses, certificates, tracks, codecs etc) using the SDP offer-answer model and Interactive Connectivity Establishment (ICE) candidates, usually via WebSocket/Phoenix channel
- media connection is established via ICE
- media encryption keys are exchanged through the media connection via DTLS
- then the browser gets the track (in this case audio samples) from the microphone, encodes it (usually with OPUS), packs it into Real-time Transport Protocol (RTP) and encrypts it (so it becomes SRTP)
- the encrypted stream is sent through the ICE media connection (usually via UDP)
- if the connected peer is the Membrane server, it unpacks the audio (OPUS) stream with [Membrane.WebRTC.EndpointBin](https://github.com/membraneframework/membrane_webrtc_plugin/blob/master/lib/membrane_webrtc_plugin/endpoint_bin.ex). That bin consists of the ICE endpoint with DTLS handshake, and the RTP bin, that handles SRTP, SRTCP and some of their extensions.
- at that point, you can do anything with the received stream, while the Membrane server just passes it to Endpoint Bins of all other peers in the room
- each Endpoint Bin packs the stream to RTP, encrypts to SRTP and sends via ICE sink
- each peer’s browser gets the stream, decrypts, unpacks, decodes to raw audio and plays out

---

_[View the full topic](https://forum.elixirforum.com/t/erlang-elixir-sample-code-for-real-time-voice-chat/38809)._
