Swift SDK API Reference
Complete API reference for the BaxCloud Swift SDK (iOS/macOS)
Table of Contents
Installation
Swift Package Manager
Recommended installation method
Add to Package.swift
1dependencies: [
2 .package(url: "https://github.com/baxcloud/swift-sdk", from: "1.0.0")
3]Or add via Xcode
- File → Add Packages...
- Enter package URL:
https://github.com/baxcloud/swift-sdk - Select version and add to your target
Note: All required dependencies are bundled with the SDK.
CocoaPods
Alternative installation method
Add to Podfile
1pod 'BaxCloudClient', '~> 1.0.0'Note: All required dependencies are included. You don't need to add them separately.
iOS Setup
Required Permissions
Add to your Info.plist file
1<key>NSCameraUsageDescription</key>
2<string>We need access to your camera for video calls</string>
3<key>NSMicrophoneUsageDescription</key>
4<string>We need access to your microphone for audio calls</string>Background Audio (Optional)
Enable background audio for continuous calls
1<key>UIBackgroundModes</key>
2<array>
3 <string>audio</string>
4</array>Request Permissions at Runtime
1import AVFoundation
2
3func requestPermissions() {
4 // Request camera permission
5 AVCaptureDevice.requestAccess(for: .video) { granted in
6 if granted {
7 print("Camera permission granted")
8 } else {
9 print("Camera permission denied")
10 }
11 }
12
13 // Request microphone permission
14 AVCaptureDevice.requestAccess(for: .audio) { granted in
15 if granted {
16 print("Microphone permission granted")
17 } else {
18 print("Microphone permission denied")
19 }
20 }
21}BaxCloudClient
Constructor
Initialize the BaxCloud client
BaxCloudClient(config: BaxCloudConfig)Parameters
config.projectId(String) - Your BaxCloud project IDconfig.apiKey(String) - Your BaxCloud API key
Example
1import BaxCloudClient
2
3let client = BaxCloudClient(config: BaxCloudConfig(
4 projectId: "your-project-id",
5 apiKey: "your-api-key"
6))Properties
room
Get the current active Room instance
var room: Room?Note: The Room type is internal to the SDK.
connectionState
Published property for connection state changes
@Published var connectionState: BaxCloudConnectionStateExample - Observing with Combine
1import Combine
2
3class ViewModel: ObservableObject {
4 @Published var state: BaxCloudConnectionState = .disconnected
5 private var cancellables = Set<AnyCancellable>()
6
7 init(client: BaxCloudClient) {
8 client.$connectionState
9 .sink { [weak self] state in
10 self?.state = state
11 }
12 .store(in: &cancellables)
13 }
14}Room Management
createRoom
Create a new room
func createRoom(options: BaxcloudCreateRoomOptions) async throws -> BaxcloudRoomInfoParameters
options.roomName(String) - Unique room nameoptions.liveType(BaxcloudLiveType) - Type of live sessionoptions.maxParticipants(Int?, optional) - Maximum participants
Example
1Task {
2 do {
3 let room = try await client.createRoom(options: BaxcloudCreateRoomOptions(
4 roomName: "meeting-123",
5 liveType: .videoConference,
6 maxParticipants: 50
7 ))
8
9 print("Room created: \(room.roomName)")
10 } catch {
11 print("Failed to create room: \(error)")
12 }
13}deleteRoom
Delete a room
func deleteRoom(roomName: String) async throwsExample
try await client.deleteRoom(roomName: "meeting-123")listRooms
List all rooms in the project
func listRooms() async throws -> [BaxcloudRoomInfo]Example
let rooms = try await client.listRooms()
print("Total rooms: \(rooms.count)")getRoom
Get information about a specific room
func getRoom(roomName: String) async throws -> BaxcloudRoomInfoExample
let room = try await client.getRoom(roomName: "meeting-123")
print("Room info: \(room)")getToken
Get an access token for joining a room
func getToken(options: BaxcloudRoomOptions) async throws -> BaxcloudTokenResponseParameters
options.roomName(String) - Room nameoptions.participant(BaxcloudUser) - Participant informationoptions.liveType(BaxcloudLiveType) - Type of live sessionoptions.canJoinWithNoHost(Bool?, optional) - Allow joining without host
Example
1let token = try await client.getToken(options: BaxcloudRoomOptions(
2 roomName: "meeting-123",
3 participant: BaxcloudUser(
4 userId: "user-1",
5 name: "Alice",
6 avatarUrl: "https://example.com/avatar.jpg",
7 isHost: true
8 ),
9 liveType: .videoConference
10))
11
12print("Access token: \(token.token)")Connection Methods
connect
Connect to a room
func connect(options: BaxcloudRoomOptions) async throws -> RoomExample
1Task {
2 do {
3 let room = try await client.connect(options: BaxcloudRoomOptions(
4 roomName: "meeting-123",
5 participant: BaxcloudUser(
6 userId: "user-1",
7 name: "Alice",
8 isHost: true
9 ),
10 liveType: .videoCall,
11 canJoinWithNoHost: true
12 ))
13
14 print("Connected to room: \(room.name)")
15 } catch {
16 print("Connection failed: \(error)")
17 }
18}disconnect
Disconnect from the current room
func disconnect() asyncExample
await client.disconnect()
print("Disconnected from room")isConnected
Check if currently connected
var isConnected: BoolExample
if client.isConnected {
print("Currently connected")
}Media Controls
enableCamera
func enableCamera() async throwsdisableCamera
func disableCamera() async throwsenableMicrophone
func enableMicrophone() async throwsdisableMicrophone
func disableMicrophone() async throwsenableScreenShare
func enableScreenShare() async throwsdisableScreenShare
func disableScreenShare() async throwsMessaging
sendRealtimeMessage
Send a real-time message to the room
func sendRealtimeMessage(options: BaxcloudSendRealtimeMessageOptions) async throws -> [String: Any]Example
1try await client.sendRealtimeMessage(
2 options: BaxcloudSendRealtimeMessageOptions(
3 roomName: "meeting-123",
4 message: "Hello everyone!",
5 sender: BaxcloudUser(
6 userId: "user-1",
7 name: "Alice"
8 )
9 )
10)Recording APIs
startRecording
Start recording a room
func startRecording(options: BaxcloudStartRecordingOptions) async throws -> BaxcloudRecordingInfoParameters
options.roomName(String) - Room name to recordoptions.filepath(String?, optional) - Custom file path for the recordingoptions.fileType(String?, optional) - Recording file type ('MP4' | 'OGG' | 'WEBM', default: 'MP4')
Example
1Task {
2 do {
3 let recording = try await client.startRecording(
4 options: BaxcloudStartRecordingOptions(
5 roomName: "my-room",
6 fileType: "MP4"
7 )
8 )
9 print("Recording started: \(recording.egressId)")
10 } catch {
11 print("Failed to start recording: \(error)")
12 }
13}Note: Recording events (recording.started, recording.completed, recording.failed) are automatically sent to your configured webhooks in the dashboard if webhooks are enabled for your project.
stopRecording
Stop an active recording
func stopRecording(egressId: String) async throws -> [String: Any]Example
try await client.stopRecording(egressId: recording.egressId)
print("Recording stopped")listActiveRecordings
List all active recordings/egresses
func listActiveRecordings(roomName: String? = nil) async throws -> [BaxcloudRecordingInfo]Example
// List all active recordings
let activeRecordings = try await client.listActiveRecordings()
// List active recordings for a specific room
let roomRecordings = try await client.listActiveRecordings(roomName: "my-room")listRecordings
List all recordings with pagination support
func listRecordings(options: BaxcloudListRecordingsOptions? = nil) async throws -> BaxcloudRecordingListResponseParameters
options.status(String?, optional) - Filter by status ('STARTED' | 'COMPLETED' | 'FAILED')options.page(Int?, optional) - Page number (default: 1)options.limit(Int?, optional) - Items per page (default: 10)
Example
1let recordings = try await client.listRecordings(
2 options: BaxcloudListRecordingsOptions(
3 status: "COMPLETED",
4 page: 1,
5 limit: 20
6 )
7)
8
9print("Recordings: \(recordings.items)")
10print("Total: \(recordings.meta.total)")getRecording
Get detailed information about a specific recording
func getRecording(recordingId: String) async throws -> BaxcloudRecordingInfoExample
let recording = try await client.getRecording(recordingId: "recording-123")
print("Recording status: \(recording.status)")getRecordingDownloadUrl
Get a temporary download URL for a recording file
func getRecordingDownloadUrl(recordingId: String, expiresIn: Int? = nil) async throws -> [String: Any]Parameters
recordingId(String) - Recording IDexpiresIn(Int?, optional) - URL expiration time in seconds (default: 3600)
Example
let response = try await client.getRecordingDownloadUrl(
recordingId: "recording-123",
expiresIn: 7200
)
print("Download URL (expires in 2 hours): \(response["downloadUrl"])")Event Handlers
Listen for events happening in the room.
onUserJoined
func onUserJoined(
handler: @escaping (Any) -> Void
)onUserLeft
func onUserLeft(
handler: @escaping (Any) -> Void
)onMessageReceived
func onMessageReceived(
handler: @escaping (
BaxcloudRealtimeMessage,
Any?
) -> Void
)onMediaStarted
func onMediaStarted(
handler: @escaping (
Any, Any, Any
) -> Void
)onMediaStopped
func onMediaStopped(
handler: @escaping (
Any, Any, Any
) -> Void
)onConnected
func onConnected(
handler: @escaping () -> Void
)onDisconnected
func onDisconnected(
handler: @escaping (String?) -> Void
)onReconnecting
func onReconnecting(
handler: @escaping () -> Void
)onReconnected
func onReconnected(
handler: @escaping () -> Void
)Event Handler Example
1import BaxCloudClient
2
3class RoomManager {
4 private let client: BaxCloudClient
5
6 init(client: BaxCloudClient) {
7 self.client = client
8 setupEventHandlers()
9 }
10
11 private func setupEventHandlers() {
12 client.onUserJoined { user in
13 print("User joined: \(user)")
14 }
15
16 client.onUserLeft { user in
17 print("User left: \(user)")
18 }
19
20 client.onConnected {
21 print("Connected to room")
22 }
23
24 client.onDisconnected { reason in
25 print("Disconnected: \(reason ?? "Unknown reason")")
26 }
27
28 client.onMessageReceived { message, sender in
29 print("Message from \(sender ?? "Unknown"): \(message)")
30 }
31 }
32}BaxCloudRoomController
Overview
Singleton controller for centralized room management
Access the controller via BaxCloudRoomController.shared
Initialization
1import BaxCloudClient
2
3class AppDelegate: UIResponder, UIApplicationDelegate {
4 let client = BaxCloudClient(config: BaxCloudConfig(
5 projectId: "your-project-id",
6 apiKey: "your-api-key"
7 ))
8
9 func application(
10 _ application: UIApplication,
11 didFinishLaunchingWithOptions launchOptions: [UIApplication.LaunchOptionsKey: Any]?
12 ) -> Bool {
13 BaxCloudRoomController.shared.initialize(client: client)
14 return true
15 }
16}Host/Co-Host Management
isHost
func isHost() -> BoolisCoHost
func isCoHost(userId: String? = nil) -> BooltransferHost
func transferHost(
targetUserId: String
) async throwsHost only
promoteToCoHost
func promoteToCoHost(
userId: String
) async throwsHost only
demoteFromCoHost
func demoteFromCoHost(
userId: String
) async throwsHost only
getCoHosts
func getCoHosts() -> [String]Participant Management
getParticipants
func getParticipants() -> [Any]getParticipant
func getParticipant(
userId: String
) -> Participant?kickParticipant
func kickParticipant(
userId: String,
reason: String? = nil
) async throwsHost/Co-host only
pinParticipant
func pinParticipant(
userId: String
) async throwsunpinParticipant
func unpinParticipant(
userId: String
) async throwsgetPinnedParticipants
func getPinnedParticipants() -> [String]spotlightParticipant
func spotlightParticipant(
userId: String
) async throwsHost/Co-host only
unspotlightParticipant
func unspotlightParticipant(
userId: String
) async throwsHost/Co-host only
getSpotlightedParticipants
func getSpotlightedParticipants() -> [String]Audio/Video Controls
muteMicrophone
func muteMicrophone() async throwsunmuteMicrophone
func unmuteMicrophone() async throwsisMicrophoneMuted
func isMicrophoneMuted() -> BoolenableCamera
func enableCamera() async throwsdisableCamera
func disableCamera() async throwsisCameraEnabled
func isCameraEnabled() -> BoolmuteAll
func muteAll() async throwsHost only
unmuteAll
func unmuteAll() async throwsHost only
muteParticipant
func muteParticipant(
userId: String
) async throwsHost/Co-host only
unmuteParticipant
func unmuteParticipant(
userId: String
) async throwsHost/Co-host only
Screen Sharing
enableScreenShare
func enableScreenShare() async throwsdisableScreenShare
func disableScreenShare() async throwsisScreenShareEnabled
func isScreenShareEnabled() -> BoolChat System
sendChatMessage
func sendChatMessage(
_ message: String
) async throwsgetChatHistory
func getChatHistory() -> [BaxcloudChatMessage]clearChatHistory
func clearChatHistory()startTyping
func startTyping() async throwsAuto-stops after 3 seconds
stopTyping
func stopTyping() async throwsgetTypingIndicators
func getTypingIndicators() -> [BaxcloudTypingIndicator]Invitation System
sendCallInvitation
func sendCallInvitation(
options: BaxcloudInvitationOptions
) async throws -> [String: Any]Returns
Dictionary with success and invitationId
acceptCallInvitation
func acceptCallInvitation(
invitationId: String
) async throwsdeclineCallInvitation
func declineCallInvitation(
invitationId: String
) async throwscancelCallInvitation
func cancelCallInvitation(
invitationId: String
) async throwsRaise Hand
raiseHand
func raiseHand() async throwslowerHand
func lowerHand(userId: String? = nil) async throwsgetRaisedHands
func getRaisedHands() -> [BaxcloudRaisedHand]Network Quality
getNetworkQuality
func getNetworkQuality() -> BaxcloudNetworkQualitygetParticipantQuality
func getParticipantQuality(
userId: String
) -> BaxcloudNetworkQualityCall Management
getCallHistory
func getCallHistory() -> [BaxcloudCallRecord]getCall
func getCall(
callId: String
) -> BaxcloudCallRecord?endCall
func endCall() async throwsPolling/Q&A
createPoll
func createPoll(
question: String,
options: [String]
) async throws -> StringHost/Co-host only. Returns poll ID
respondToPoll
func respondToPoll(
pollId: String,
selectedOption: String
) async throwsendPoll
func endPoll(pollId: String) async throwsHost/Co-host only
getActivePolls
func getActivePolls() -> [BaxcloudPoll]getPoll
func getPoll(
pollId: String
) -> BaxcloudPoll?Breakout Rooms
createBreakoutRoom
func createBreakoutRoom(
roomName: String,
participantIds: [String]
) async throws -> StringHost/Co-host only. Returns room ID
joinBreakoutRoom
func joinBreakoutRoom(
roomId: String
) async throwsleaveBreakoutRoom
func leaveBreakoutRoom(
roomId: String
) async throwsgetBreakoutRooms
func getBreakoutRooms() -> [BaxcloudBreakoutRoom]getBreakoutRoom
func getBreakoutRoom(
roomId: String
) -> BaxcloudBreakoutRoom?Emoji Reactions
sendEmojiReaction
func sendEmojiReaction(
emoji: String
) async throwsgetRecentEmojiReactions
func getRecentEmojiReactions() -> [BaxcloudEmojiReaction]Waiting Room
approveWaitingRoomParticipant
func approveWaitingRoomParticipant(
userId: String
) async throwsHost/Co-host only
rejectWaitingRoomParticipant
func rejectWaitingRoomParticipant(
userId: String
) async throwsHost/Co-host only
getWaitingRoomParticipants
func getWaitingRoomParticipants() -> [BaxcloudWaitingRoomParticipant]Host/Co-host only
Picture-in-Picture
Note: PIP is not yet fully implemented for iOS. This is a placeholder for future implementation using AVPictureInPictureController.
enablePIP
func enablePIP() async throwsdisablePIP
func disablePIP() async throwsisPIPEnabled
func isPIPEnabled() -> BoolBackground Effects
applyBackgroundEffect
func applyBackgroundEffect(
_ effect: BaxcloudBackgroundEffect
) async throwsremoveBackgroundEffect
func removeBackgroundEffect() async throwsgetCurrentBackgroundEffect
func getCurrentBackgroundEffect() -> BaxcloudBackgroundEffect?Accessibility
updateAccessibilitySettings
func updateAccessibilitySettings(
_ settings: BaxcloudAccessibilitySettings
)getAccessibilitySettings
func getAccessibilitySettings() -> BaxcloudAccessibilitySettingsType Definitions
BaxCloudConnectionState
enum BaxCloudConnectionState {
case disconnected
case connecting
case connected
case reconnecting
case failed
}BaxcloudLiveType
enum BaxcloudLiveType {
case videoCall
case videoConference
case audioConference
case liveStreaming
}BaxcloudUser
struct BaxcloudUser {
let userId: String
let name: String
let avatarUrl: String?
let isHost: Bool
let metadata: [String: Any]?
}BaxcloudRoomOptions
struct BaxcloudRoomOptions {
let roomName: String
let participant: BaxcloudUser
let liveType: BaxcloudLiveType
let roomMetadata: [String: Any]?
let canJoinWithNoHost: Bool?
}BaxcloudNetworkQuality
struct BaxcloudNetworkQuality {
let connectionQuality: String // 'excellent' | 'good' | 'poor' | 'unknown'
let rtt: Double?
let jitter: Double?
let packetLoss: Double?
}