Four signaling transports, one WebRTC engine
Why signaling — not WebRTC — is the hard part on iOS. And how I made four transports interchangeable.
WebRTC is the easy part.
Everyone who writes a WebRTC tutorial focuses on the peer connection: createOffer, setLocalDescription, ICE candidates, media tracks. All of that is in the spec. All of it is documented.
Nobody talks about how the SDP gets from your peer to the other peer. That's called signaling, and it isn't part of WebRTC. You pick the channel. The spec just hands you a blob and says: good luck.
After shipping WebRTC in three production apps, I open-sourced WebRTCDemo — one codebase with four interchangeable signaling transports— because the signaling choice is where most iOS WebRTC projects die, not the WebRTC itself. This chapter walks through them.
The envelope that makes them interchangeable.
Before you can swap transports, you need a single message shape every transport can carry. One Codable envelope with just enough structure to represent an offer, an answer, an ICE candidate, and a hangup:
1enum SignalingMessage: Codable, Sendable {2 case offer(SessionDescription)3 case answer(SessionDescription)4 case candidate(IceCandidate)5 case bye(reason: String?)67 struct SessionDescription: Codable, Sendable {8 let type: String // "offer" | "answer"9 let sdp: String10 }1112 struct IceCandidate: Codable, Sendable {13 let sdp: String14 let sdpMid: String?15 let sdpMLineIndex: Int3216 }17}
The transport's job is: “hand me one of these, I'll get it to the other side.” That's the entire protocol. Which means your WebRTC core doesn't care if the message rode over a WebSocket, bounced off a Multipeer session, or was manually pasted into a text field.
Transport 01 — Clipboard JSON (the learning tool).
The simplest possible signaling: encode the message to base64, copy it to the clipboard, hand your phone to a friend, let them paste it on their end. Manual, two-player, zero infrastructure.
This sounds useless. It's actually the single most educational transport. You can see, in your own hand, the thing that normally travels invisibly over a WebSocket. The first time you watch the offer SDP and the answer SDP being copied back and forth, WebRTC stops being magic.
I keep this transport in the demo because every intern who runs the project learns more from it in 5 minutes than from a week of reading the spec.
Transport 02 — Step-by-step (the diagnostic tool).
Same idea as clipboard, but the UI walks you through each state: “create offer” → “share offer” → “paste remote offer” → “create answer” → “share answer” → “gather ICE” → “paste remote ICE” → connected.
You see the state machine light up a cell at a time. When your production app hangs at have-local-offer and you don't know why, this transport is your reproducer. Half of my production WebRTC bugs were first reproduced in this mode.
Transport 03 — Multipeer Connectivity (peer-to-peer, no server).
This one surprises people. iOS's MultipeerConnectivity framework handles device discovery and session setup over Bluetooth and WiFi, with zero infrastructure. You can run a real WebRTC call between two phones in airplane mode with Bluetooth on.
For the signaling transport, Multipeer is just a message pipe. You:
- Start advertising a service type.
- Start browsing for the same service type.
- When you discover a peer, invite them to a session.
- Encode SignalingMessage, send over the session.
The WebRTC media still goes peer-to-peer over the local network (ICE host candidates), so you don't need Multipeer for the actual audio/video — just for the SDP exchange. End result: a working call with no server, no signup, no account, no router config.
Transport 04 — Local Network / Bonjour (same subnet, LAN-only).
If both devices are on the same WiFi, you can skip Multipeer and use Apple'sNetwork.framework with Bonjour service discovery. Advertise a TCP service, browse for it, open a NWConnection, exchange messages.
Why have both? Multipeer is forgiving (Bluetooth fallback, lossy conditions) but has a hard ceiling on throughput. Bonjour over TCP is fast and predictable but requires WiFi. In production you'd probably pick one; in a demo it's useful to show both.
How they stay interchangeable.
Every transport conforms to the same two-method protocol:
1protocol SignalingTransport: Sendable {2 var incoming: AsyncStream<SignalingMessage> { get }3 func send(_ message: SignalingMessage) async throws4}56// Four concrete implementations — same contract.7final class ClipboardTransport: SignalingTransport { /* ... */ }8final class StepByStepTransport: SignalingTransport { /* ... */ }9final class MultipeerTransport: SignalingTransport { /* ... */ }10final class LocalNetworkTransport: SignalingTransport { /* ... */ }1112// The engine holds any transport. It doesn't know which.13final actor WebRTCEngine {14 init(signaling: any SignalingTransport) { /* ... */ }15}
The WebRTCEngine holds a SignalingTransport, nothing more. Swap the concrete type in your DI container and the engine never notices.
What this teaches you.
- Your WebRTC core should not care about transport. If it does, you'll end up rewriting it when the business switches from WebSocket to gRPC. Costly.
- Signaling is testable. With the clipboard transport you can deterministically reproduce any state the peer connection can get into. Use this for every bug reproduction.
- You can ship WebRTC without a signaling server for some use cases.Nearby collaboration, local-only tools, offline-first products. Multipeer and Bonjour open doors a WebSocket-first design closes.
Where this came from.
I started WebRTCDemo as my own learning tool after years of production work. It was supposed to be a weekend project; it became a reference implementation three new engineers at YEO used as their onboarding doc. The Medium write-up covers the architectural reasoning in more detail if you want to go deeper.
Full source: github.com/AbhishekSuryawanshi/WebRTCDemo. MIT licensed. PRs welcome. The repo has runnable iOS projects for all four transports; you can be in a working peer-to-peer call between two devices in under 90 seconds.