XGW.Spike.SDP (xgw v0.1.0)

Copy Markdown View Source

Minimal SDP answer builder and helpers for the browser spike (mix xgw.spike).

Summary

Functions

Builds a minimal WebRTC answer from an offer and local ICE/DTLS parameters.

Host candidate IPs for the spike answer: loopback plus non-loopback IPv4 locals.

Coerces a codec atom or header string to :opus | :pcmu | :pcma | :g722.

Parses the browser's ICE ufrag and pwd from an offer SDP.

Functions

answer(offer, opts)

@spec answer(
  binary(),
  keyword()
) :: binary()

Builds a minimal WebRTC answer from an offer and local ICE/DTLS parameters.

Opts may include :codec as :opus | :pcmu | :pcma | :g722 (default :opus). The answer lists only that codec so the browser is forced onto it.

When the offer includes an SCTP application m-line, the answer BUNDLEs a matching m=application with a=sctp-port / a=max-message-size.

detect_advert_ips()

@spec detect_advert_ips() :: [:inet.ip_address()]

Host candidate IPs for the spike answer: loopback plus non-loopback IPv4 locals.

normalize_codec(codec)

@spec normalize_codec(term()) :: :opus | :pcmu | :pcma | :g722

Coerces a codec atom or header string to :opus | :pcmu | :pcma | :g722.

parse_ice(offer)

@spec parse_ice(binary()) :: {String.t() | nil, String.t() | nil}

Parses the browser's ICE ufrag and pwd from an offer SDP.

Uses the last match so media-level credentials win over session-level duplicates.