XGW.Peer.Sctp (xgw v0.1.0)

Copy Markdown View Source

Starts and drives the SCTP association used for WebRTC data channels.

What problem this solves

Browsers open data channels for arbitrary binary/text beside audio/video. Under the hood that is SCTP inside the DTLS tunnel. This module starts a passive association when SDP negotiated SCTP and SSL is up, then applies association events (transmit, channel open/close, messages) into Peer or XGW.Peer.Datachannel state and handler callbacks.

Production ownership of the live association and DTLS app-data socket is the per-Peer XGW.Peer.Datachannel process. Handler messages always carry the Peer pid as peer_ref (via state :peer when set).

RFCs

  • RFC 8261 -- SCTP over DTLS
  • RFC 8831 -- WebRTC data channels
  • RFC 8841 -- SDP negotiation of SCTP

Summary

Functions

Applies SCTP association events; send_dtls posts app data on the DTLS socket.

Starts a passive SCTP association when SDP negotiated SCTP and SSL is up.

Functions

flush_events(state, events, send_dtls)

@spec flush_events(map(), list(), (map(), binary() -> :ok | {:error, term()})) ::
  map()

Applies SCTP association events; send_dtls posts app data on the DTLS socket.

Events include outbound SCTP chunks to transmit, channel lifecycle, and application messages that become {:xgw, :datachannel_*, ...} callbacks.

maybe_start(state)

@spec maybe_start(map()) :: map()

Starts a passive SCTP association when SDP negotiated SCTP and SSL is up.

No-ops when SCTP was not negotiated, SSL is not ready, or ex_sctp is unloaded.