dart_webrtc
dart_webrtc (WebrTC Implementation for The Dart language)
A pure Dart implementation of WebRTC — ICE, STUN, TURN, DTLS, TLS, SRTP, RTP, RTCP, SDP — with no native dependencies. Includes a full ion-style SFU (example/ion_style_sfu/) with sharding, clustering, simulcast, TWCC/REMB, NACK/RTX, audio observer, and Prometheus stats.
Inspired by webrtc-nuts-and-bolts
✨ Highlights
- Pure Dart end-to-end stack — no libwebrtc / libsrtp / libnice. Easy to embed and audit.
- Ion-style SFU with isolate-based sharding, cluster coordinator, UDP relay transport, leaky-bucket pacer, BWE, jitter buffer, simulcast layer rewriter, and audio-level observer.
- 516 unit tests in the SFU package, 93–100 % line coverage across major files.
- VP8 / VP9 / Opus / PCMA / PCMU, RTX (RFC 4588), NACK, PLI, FIR, REMB, TWCC, audio level (RFC 6464), playout-delay codec.
- Built-in load-test harness and synthetic loss simulator.
- Prometheus metrics + JSON
/statsendpoint.
📦 Installation
clone the repo
Then run:
dart pub get
Requires Dart 3.x or later.
📚 Documentation (WIP)
- API Reference
- Example usage in the
/bindirectory
💡 Examples
GitHub: examples
Ion-style SFU server
dart run example/ion_style_sfu/bin/sfu_server.dart \
--ip 0.0.0.0 \
--ws-port 9091 \
--rtp-base 51000 \
--announce-ip <your-public-ip> \
--ice-server stun:stun.l.google.com:19302
Browser demo client:
cd example/ion_style_sfu/web
python -m http.server 8000 --bind 0.0.0.0
# open http://localhost:8000/meet.html
Run the SFU test suite:
cd example/ion_style_sfu
dart test
Walkie-talkie SFU + Flutter PTT client
Push-to-talk multi-channel walkie-talkie built on top of
example/ion_style_sfu/. Server adds in-memory user accounts
(PBKDF2 + JWT), /auth/register, /auth/login, /channels, and a
JWT-gated /ws upgrade. Flutter client (Android / iOS / macOS /
Windows / Linux / Web) ships an auth screen, channel list, PTT screen
with optional per-peer camera toggle (publisher renegotiation).
# server
dart run example/ion_style_sfu/bin/walkie_sfu.dart \
--ip 0.0.0.0 --ws-port 7080 --announce-ip <public-ip>
# client
cd example/walkie_talkie_client
flutter run
See example/walkie_talkie_client/README.md.
WHIP recorder + security-camera Flutter client
Cloud / on-prem video-recording pipeline: a pure-Dart WHIP ingest
server that depacketizes VP8 RTP and writes each publisher session to
its own .ivf file on disk, paired with a Flutter app that captures
the device camera + microphone and publishes via WHIP. Intended for
unattended security-camera deployments — drop a phone or tablet
running the client at every site, point it at the recorder, done.
# server (writes IVF files to ./recordings)
dart run example/whip_recorder/bin/whip_recorder.dart \
--ip 0.0.0.0 --token <secret> --out ./recordings
# list / download recordings
curl -H "Authorization: Bearer <secret>" http://<host>:8080/recordings
# client
cd example/security_camera_client
flutter run
See example/whip_recorder/README.md and example/security_camera_client/README.md.
DTLS server
dart bin/srtp_webrtc.dart
dart bin/dart_webrtc.dart
dart lib/src/dtls/examples/server/psk_ccm8.dart
dart lib/src/dtls/examples/server/psk_ccm.dart
SRTP/DTLS server
dart bin/srtp_webrtc.dart
DTLS client
dart lib/src/dtls3/handshaker/client/dtls_client.dart
STUN Server
dart lib/src/stun3/stun_server7.dart
STUN client
dart lib/src/stun3/stun_client.dart
STUN/DTLS/SRTP/RTCP multiplexing
This example recieves stun, dtls, rtp packets. It decrypts, encrypts and sends the packets back to the sender. copy the sdp offer from this file:
lib\src\sdp8\sdp_test.dart
Adjust the the fingerprint and ice candidate
cd WebRTC-Simple-SDP-Handshake-Demo
php -S localhost:3000
Navigate to the link in your browser=> localhost:3000 Paste the sdp in the sdp offer box
Run this command
dart bin\srtp_webrtc.dart
In your browser, click create answer
🎯 Roadmap
✅ Shipped
Signaling & NAT traversal
xSTUN (client + server)xSIPTURN (UDP)
ICE
xVanilla ICExTrickle ICExICE-Lite (client + server)ICE Restart
Security
xDTLS 1.2 + DTLS-SRTPxCurve25519, P-256xPSK (CCM, CCM-8)
TLS 1.2
RTP / RTCP
xRFC 3550 RTP base + header extensions (audio level, playout delay, abs-send-time, TWCC)xPayload formats: VP8, VP9, Opus, PCMA, PCMUxRTX (RFC 4588), RED scaffoldingxRTCP: SR/RR, NACK, PLI, FIR, REMB, TWCCH264, AV1, SVC
SDP / PeerConnection
xSDP parsing + generation, m-line reusexPeerConnection APIxSimulcast (RID + SIM SSRC group, recv + forward)xBandwidth estimation (sender-side TWCC + REMB)
SFU (example/ion_style_sfu/)
xSession / Peer / Publisher / Subscriber / Router / Receiver / DownTrackxIsolate-based session sharding (SessionShard,ShardedSfu)xCluster coordinator + UDP relay transport (cascade between SFUs)xAudio observer (RFC 6464) + audio-level forwarding policyxLeaky-bucket pacer, byte budget, NACK buffer, RTCP rewritexSynthetic loss simulator + load-test harnessxPrometheus stats + JSON snapshot,/streamsaggregator (Phase B11)xWebSocket signalling server (runIonStyleSfuServer)xMulti-room cluster snapshot rehydration
Compatibility
xChrome / Edge / Firefoxxwebrtc-rs interopPion / aiortc / sipsorcery interop suite
🔜 Roadmap
VP9 SVC layer selectorH264 forwardingInsertable streams / SFrame (E2EE)xRecording (VP8 → IVF, viaexample/whip_recorder/)Recording (Opus, VP9 → IVF, MP4 remux)Published throughput benchmarks + Helm chartDataChannel (SCTP)TURN (UDP + TCP)getStats()browser-compatible APIICE Restart
🔗 References
Libraries
- dart_webrtc
- dartls
- ecc
- ecdsa
- h264
- Public entry point for the H.264 RTP payloader / depayloader (RFC 6184). See packetizeH264AccessUnit, H264RtpDepacketizer, splitAnnexB, and decodeSpropParameterSets.
- signal/fingerprint
- signal/sdp/sdp_codec
- signal/sdp/sdp_offer_answer
- signal/sdp/sdp_session
- signal/sdp_v2
- types/types
- vpx
- Public entry point for the VP8 / VP9 wrapper around libvpx.
- webrtc/media_stream
- webrtc/parameter
- webrtc/peer_connection
- webrtc/rtc_data_channel
- webrtc/rtc_ice_candidate
- webrtc/rtc_rtp_transceiver
- webrtc/rtc_session_description
- webrtc/rtc_stats
- webrtc/rtc_udp_transport
- webrtc/webrtc