iOS Swift Client SDK
This document describes how to install the Nabto WebRTC SDK for iOS Swift. This library provides signaling for iOS Swift based projects used with the Nabto WebRTC Signaling Service.
Installation
Currently the SDK only supports Swift Package Manager. Proper support for Cocoapods is planned, it is however already possible to use an SPM package in a Cocoapods project.
In your .xcodeproj or .xcworkspace, add the package by pressing File > Add Package Dependencies...
then go to the settings for your target in your xcode project and add NabtoWebRTC
and NabtoWebRTCUtil
to the “Frameworks, Libraries, and Embedded Content” option.
If you are using a Package.swift
file to specify dependencies, first add the following line to the dependencies
list.
.package(url: "https://github.com/nabto/nabto-webrtc-sdk-ios.git", from: "v0.0.2")
Then add NabtoWebRTC
and NabtoWebRTCUtil
to your target’s dependencies
.target(name: "example", dependencies: ["NabtoWebRTC", "NabtoWebRTCUtil"]),
Quick Start
import NabtoWebRTC
import NabtoWebRTCUtil
// Options that control which camera to connect to
let productId = "..." // Initialize your productId
let deviceId = "..." // Initialize your deviceId
let sharedSecret = "..." // Initialize your sharedSecret
// Build the signaling client options
let options = SignalingClientOptions(
productId: productId,
deviceId: deviceId
)
// Create the signaling client and observer
let client = createSignalingClient(options)
let observer = MyObserver()
let messageTransport: MessageTransport? = nil
do {
messageTransport = try createClientMessageTransport(
client: signalingClient,
options: .sharedSecret(sharedSecret: sharedSecret)
)
messageTransport?.addObserver(observer)
try client.start()
} catch {
// Handle potential errors from starting the client
print(error)
}
// Class that implements MessageTransportObserver
class MyObserver: MessageTransportObserver {
func messageTransport(_ transport: any MessageTransport, didGet message: WebrtcSignalingMessage) {
// Handle signaling messages here
}
func messageTransport(_ transport: any MessageTransport, didError error: any Error) {
// Handle potential errors here
}
func messageTransport(_ transport: any MessageTransport, didFinishSetup iceServers: [SignalingIceServer]) {
// Create the RTCPeerConnection here
}
}