Skip to content

Minimal WebRTC sender client with WHIP, DTLS via NWConnection, and SRTP#229

Closed
Copilot wants to merge 6 commits intomainfrom
copilot/implement-webrtc-client-sender
Closed

Minimal WebRTC sender client with WHIP, DTLS via NWConnection, and SRTP#229
Copilot wants to merge 6 commits intomainfrom
copilot/implement-webrtc-client-sender

Conversation

Copy link
Copy Markdown
Contributor

Copilot AI commented Feb 9, 2026

From-scratch WebRTC send-only client: single outgoing stream (H.264 video + Opus audio), WHIP signaling, local ICE candidates only. No incoming streams, no data channels, no WHEP, no STUN/TURN.

DTLS uses NWConnection with NWParameters(dtls:udp:) rather than a custom protocol implementation — Apple handles the handshake natively.

New files (Moblin/Media/HaishinKit/WebRtc/)

  • RtpPacket.swift — RTP header encode/decode, sequencer with SSRC/timestamp management
  • StunMessage.swift — STUN binding request/response (RFC 5389) for ICE connectivity checks
  • SdpMessage.swift — SDP offer/answer generation and parsing; sendonly, BUNDLE, rtcp-mux
  • IceAgent.swift — Host candidate gathering via getifaddrs() (IPv4 only)
  • WhipSession.swift — WHIP client: POST offer → parse answer → DELETE teardown; whip://https://
  • DtlsSession.swiftNWConnection-based DTLS 1.2 session with self-signed EC P-256 certificate, SHA-256 fingerprint for SDP, SRTP keying material export via SSLExportKeyingMaterial
  • SrtpSession.swift — SRTP key derivation (RFC 3711), AES-128-CTR payload encryption, HMAC-SHA1 auth tags
  • WebRtcStream.swift — Top-level stream wiring WHIP → ICE → DTLS → SRTP → encoder pipeline

DTLS approach

let params = NWParameters(dtls: tlsOptions, udp: .init())
connection = NWConnection(host: nwHost, port: nwPort, using: params)
// NWConnection.State.ready = DTLS handshake complete
// SRTP keys extracted via sec_protocol_metadata_access_handle

Self-signed cert created via keychain (SecIdentity), fingerprint derived from DER data, keychain entries cleaned up immediately after identity creation.

Integration

  • SettingsStreamProtocol — added .webRtc
  • SettingsStream.getProtocol() — maps whip:// scheme → .webRtc
  • Media.swiftwebRtcStream lifecycle, WebRtcStreamDelegate conformance
  • ModelStream.swift.webRtc case in start/stop stream
  • Validate.swiftwhip recognized as valid URL scheme

✨ Let Copilot coding agent set things up for you — coding agent works faster and does higher quality work when set up for your repo.

Copilot AI and others added 2 commits February 9, 2026 05:35
Co-authored-by: eerimoq <176810+eerimoq@users.noreply.github.com>
…rser

Co-authored-by: eerimoq <176810+eerimoq@users.noreply.github.com>
Copilot AI changed the title [WIP] Implement minimal WebRTC client sender in Swift Implement minimal WebRTC sender client with WHIP protocol Feb 9, 2026
Copilot AI requested a review from eerimoq February 9, 2026 05:39
Co-authored-by: eerimoq <176810+eerimoq@users.noreply.github.com>
Copilot AI changed the title Implement minimal WebRTC sender client with WHIP protocol Add fingerprint to WebRTC SDP offer Feb 9, 2026
Co-authored-by: eerimoq <176810+eerimoq@users.noreply.github.com>
Copilot AI changed the title Add fingerprint to WebRTC SDP offer Minimal WebRTC sender with WHIP, DTLS, and SRTP Feb 9, 2026
Co-authored-by: eerimoq <176810+eerimoq@users.noreply.github.com>
Copilot AI changed the title Minimal WebRTC sender with WHIP, DTLS, and SRTP Minimal WebRTC sender client with WHIP, DTLS via NWConnection, and SRTP Feb 9, 2026
@eerimoq eerimoq closed this Feb 9, 2026
@eerimoq eerimoq deleted the copilot/implement-webrtc-client-sender branch February 10, 2026 21:30
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants