JMM’s notes on

WebRTC

GStreamer

It seems like GStreamer has utilities for WebRTC. It’s part of “gst-plugins-bad” though. I should try out the steps in the usage section of rswebrtc.

It seems like you might be able to remotely control a desktop.

WHIP

WebRTC-HTTP ingestion protocol is currently in draft. See the IETF draft here.

Lorenzo Miniero has an interesting blog post on WISH, WHIP, and Janus.

ICE

Interactive Connectivity Establishment is documented in RFC 8445.

Misc

It looks like you get more ICE candidates when you have getUserMedia permissions (like microphone/camera). See the Trickle ICE WebRTC sample and RFC 8828. Not sure how this works if you just want to send data. You probably just ask for microphone/camera permissions anyway.

TURN

TURN specified by RFC 8656.

I should check out coturn.

Long-term credentials mechanism (LTCM) described by https://datatracker.ietf.org/doc/html/rfc5389#section-10.2 and https://datatracker.ietf.org/doc/html/rfc5389#section-15.4. User needs to provide username, password, and optionally the origin value. See https://webrtc.org/getting-started/turn-server for an example of providing credentials. When constructing RTCPeerConnection, options should include an iceServers property. Include a server with properties for urls, username, credential.

coturn

Can start with nix-shell -p coturn. It seems like the main server is called turnserver. See man turnserver for documentation there. Also check the examples/scripts directory of how to run programs. Like there’s a secure_relay_with_db_psql.sh script (see raw version here) that’s worth looking at.

Some options to probably use.
Option Meaning
--listening-ip=12.34.56.78 Sets the listening IP.
--psql-userdb="host=localhost dbname=coturn user=turn password=turn connect_timeout=30" Sets postgres connection.
-n Do not use configuration file, only command line.
-c /some/file/turnserver.conf Use some configuration.
--lt-cred-match Long-term credentials mechanism, apparently needed for WebRTC.
--max-bps=3000000 Set max bandwidth. Need to decide on value.
--fingerprint Adds a fingerprint? Not sure what that means. “WebRTC Usage” section says WebRTC usually uses it.
--log-file=stdout Log to standard output.
--no-multicast-peers Prevent using 224.0.0.0 and above. Seems like reasonable thing to include.
--allow-loopback-peers Only in development! Possible security issues in production.
--min-port=32355 --max-port=65535 Set min and max UDP ports for relaying.
--relay-threads=3 Don't necessarily need to set.
--bps-capacity=somenumber Total bandwidth turn server can use, combined.
-v “WebRTC Usage” section says this may be nice.
--realm=jmm.io Set authentication realm? Not sure what to set this to.
--no-cli Seems like telnet CLI is turned on by default without a password. Either set a password or disable.

Coturn to-dos

  • Set up postgres db, user, password. What’s the format of the table needed for credentials? See docs/PostgreSQL.md and docker/postgresql/schema.sql.
  • Find out how to set long-term credentials (or short-term)? Again see docs/PostgreSQL.md for some turnadmin commands. I may want to use a --static-auth-secret stored inside the turn_secret table.
  • Set up nftables with min/max UDP ports for relay.
  • I probably need to give turnserver access to certificate. Can I do that with systemd credentials?
  • Make a coturn NixOS configuration.

Misc

Janus

Janus is a general-purpose WebRTC server. I have not yet tried it out, but it looks interesting. Might be able to bridge WebRTC with SIP gateways (like, have a phone working in the browser).

FreeSWITCH

FreeSWITCH apparently has some way of interfacing with WebRTC (see this WebRTC page in the FreeSWITCH documentation). I think I tried using Verto a long time ago, but couldn’t figure it out.

LiveKit

Haven’t tried out LiveKit (https://livekit.io/) but it seems like it helps with WebRTC ingress. I saw it mentioned in this Matrix blogpost and in this GStreamer plugin so it might be worth looking into.