Swift SDK (iOS & macOS)
The Swift SDK is a native port of the browser client for iOS 17+ and macOS 14+. It speaks the exact same Phoenix channel protocol, so iOS, macOS, and browser users join the same rooms under the same subscriptions/2 policy with zero server changes.
Installation
Section titled “Installation”Add Octoroom via Swift Package Manager (the Package.swift manifest lives at the repository root):
dependencies: [ .package(url: "https://github.com/samrat/octoroom.git", branch: "main")]
// Target dependencies.product(name: "Octoroom", package: "octoroom").product(name: "OctoroomAgents", package: "octoroom") // optional: AI agent helpersPackage products
Section titled “Package products”OctoroomCore— Phoenix Channels client, signaling, and data types behind aMediaEngineprotocol (no WebRTC dependency, fast offline unit tests).Octoroom— WebRTC engine (stasel/WebRTC), mic/camera/screen capture, and SwiftUIVideoView. Re-exportsOctoroomCore.OctoroomAgents—@ObservableAgentsclient for agent presence, transcripts, and typed messages.
Joining a room
Section titled “Joining a room”import Octoroomimport SwiftUI
@MainActorfunc makeRoom(token: String) -> RoomClient { let socket = PhoenixSocket( endpoint: URL(string: "wss://example.com/socket")!, params: ["token": token] ) return RoomClient( socket: socket, topic: "room:lobby", params: ["name": "Ada"], video: true )}
try await room.join()room.setMuted(true)room.mute(.camera, true) // sends black frames; no renegotiationtry await room.startCamera()try await room.shareScreen()await room.stop(.camera)room.leave()SwiftUI views & AI agents
Section titled “SwiftUI views & AI agents”Both RoomClient and Agents are @Observable, so SwiftUI views bind to them directly:
import Octoroomimport OctoroomAgentsimport SwiftUI
struct CallView: View { let room: RoomClient let agents: Agents
var body: some View { VStack { ForEach(room.tracks.filter { $0.kind == .video }) { track in VideoView(track) // remote video } if let camera = room.localTracks[.camera] { VideoView(camera) // self view, mirrored } ForEach(agents.agents) { agent in Text("\(agent.name): \(agent.state?.rawValue ?? "")") } ForEach(agents.transcript("assistant")) { item in Text(item.text) } } }}For imperative events, iterate for await event in room.events() (.roomEvent, .reconnecting, .reconnected(resumed:), .connection, .workerEvent, .left(reason), .error). Call await room.levels() for speaking-indicator audio levels.
Platform notes
Section titled “Platform notes”- Permissions: Add
NSMicrophoneUsageDescriptionandNSCameraUsageDescriptiontoInfo.plist. - Screen sharing: iOS captures the app’s own screen via ReplayKit (for whole-device capture, feed
engine.makeFrameTrack()from a broadcast upload extension). macOS uses ScreenCaptureKit and requires Screen Recording permission. Native clients do not publishscreen_audio. - Audio route: On iOS,
WebRTCEngine(speaker: true)(default) routes to the loudspeaker; passfalsefor the earpiece. - Custom media: Pass
media: [.camera: track]usingengine.makeFrameTrack()to push customCVPixelBuffers. - Leaving on quit: Call
room.leave()when ending a call; otherwise the server holds the participant for the resume grace period.
See examples/ios for a complete runnable SwiftUI app.