Swift SDK API Reference

Complete API reference for the BaxCloud Swift SDK (iOS/macOS)

Installation

Swift Package Manager

Recommended installation method

Add to Package.swift

Package.swift
1dependencies: [
2    .package(url: "https://github.com/baxcloud/swift-sdk", from: "1.0.0")
3]

Or add via Xcode

  1. File → Add Packages...
  2. Enter package URL: https://github.com/baxcloud/swift-sdk
  3. Select version and add to your target

Note: All required dependencies are bundled with the SDK.

CocoaPods

Alternative installation method

Add to Podfile

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

Info.plist
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

Info.plist
1<key>UIBackgroundModes</key>
2<array>
3    <string>audio</string>
4</array>

Request Permissions at Runtime

PermissionsManager.swift
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 ID
  • config.apiKey (String) - Your BaxCloud API key

Example

AppDelegate.swift
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: BaxCloudConnectionState

Example - Observing with Combine

ViewModel.swift
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 -> BaxcloudRoomInfo

Parameters

  • options.roomName (String) - Unique room name
  • options.liveType (BaxcloudLiveType) - Type of live session
  • options.maxParticipants (Int?, optional) - Maximum participants

Example

RoomManager.swift
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 throws

Example

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 -> BaxcloudRoomInfo

Example

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 -> BaxcloudTokenResponse

Parameters

  • options.roomName (String) - Room name
  • options.participant (BaxcloudUser) - Participant information
  • options.liveType (BaxcloudLiveType) - Type of live session
  • options.canJoinWithNoHost (Bool?, optional) - Allow joining without host

Example

TokenManager.swift
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 -> Room

Example

VideoCallView.swift
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() async

Example

await client.disconnect()
print("Disconnected from room")

isConnected

Check if currently connected

var isConnected: Bool

Example

if client.isConnected {
    print("Currently connected")
}

Media Controls

enableCamera

func enableCamera() async throws

disableCamera

func disableCamera() async throws

enableMicrophone

func enableMicrophone() async throws

disableMicrophone

func disableMicrophone() async throws

enableScreenShare

func enableScreenShare() async throws

disableScreenShare

func disableScreenShare() async throws

Messaging

sendRealtimeMessage

Send a real-time message to the room

func sendRealtimeMessage(options: BaxcloudSendRealtimeMessageOptions) async throws -> [String: Any]

Example

MessageSender.swift
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 -> BaxcloudRecordingInfo

Parameters

  • options.roomName (String) - Room name to record
  • options.filepath (String?, optional) - Custom file path for the recording
  • options.fileType (String?, optional) - Recording file type ('MP4' | 'OGG' | 'WEBM', default: 'MP4')

Example

RecordingManager.swift
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 -> BaxcloudRecordingListResponse

Parameters

  • 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

RecordingsList.swift
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 -> BaxcloudRecordingInfo

Example

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 ID
  • expiresIn (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

EventHandlers.swift
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

AppDelegate.swift
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() -> Bool

isCoHost

func isCoHost(userId: String? = nil) -> Bool

transferHost

func transferHost(
    targetUserId: String
) async throws

Host only

promoteToCoHost

func promoteToCoHost(
    userId: String
) async throws

Host only

demoteFromCoHost

func demoteFromCoHost(
    userId: String
) async throws

Host 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 throws

Host/Co-host only

pinParticipant

func pinParticipant(
    userId: String
) async throws

unpinParticipant

func unpinParticipant(
    userId: String
) async throws

getPinnedParticipants

func getPinnedParticipants() -> [String]

spotlightParticipant

func spotlightParticipant(
    userId: String
) async throws

Host/Co-host only

unspotlightParticipant

func unspotlightParticipant(
    userId: String
) async throws

Host/Co-host only

getSpotlightedParticipants

func getSpotlightedParticipants() -> [String]

Audio/Video Controls

muteMicrophone

func muteMicrophone() async throws

unmuteMicrophone

func unmuteMicrophone() async throws

isMicrophoneMuted

func isMicrophoneMuted() -> Bool

enableCamera

func enableCamera() async throws

disableCamera

func disableCamera() async throws

isCameraEnabled

func isCameraEnabled() -> Bool

muteAll

func muteAll() async throws

Host only

unmuteAll

func unmuteAll() async throws

Host only

muteParticipant

func muteParticipant(
    userId: String
) async throws

Host/Co-host only

unmuteParticipant

func unmuteParticipant(
    userId: String
) async throws

Host/Co-host only

Screen Sharing

enableScreenShare

func enableScreenShare() async throws

disableScreenShare

func disableScreenShare() async throws

isScreenShareEnabled

func isScreenShareEnabled() -> Bool

Chat System

sendChatMessage

func sendChatMessage(
    _ message: String
) async throws

getChatHistory

func getChatHistory() -> [BaxcloudChatMessage]

clearChatHistory

func clearChatHistory()

startTyping

func startTyping() async throws

Auto-stops after 3 seconds

stopTyping

func stopTyping() async throws

getTypingIndicators

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 throws

declineCallInvitation

func declineCallInvitation(
    invitationId: String
) async throws

cancelCallInvitation

func cancelCallInvitation(
    invitationId: String
) async throws

Raise Hand

raiseHand

func raiseHand() async throws

lowerHand

func lowerHand(userId: String? = nil) async throws

getRaisedHands

func getRaisedHands() -> [BaxcloudRaisedHand]

Network Quality

getNetworkQuality

func getNetworkQuality() -> BaxcloudNetworkQuality

getParticipantQuality

func getParticipantQuality(
    userId: String
) -> BaxcloudNetworkQuality

Call Management

getCallHistory

func getCallHistory() -> [BaxcloudCallRecord]

getCall

func getCall(
    callId: String
) -> BaxcloudCallRecord?

endCall

func endCall() async throws

Polling/Q&A

createPoll

func createPoll(
    question: String,
    options: [String]
) async throws -> String

Host/Co-host only. Returns poll ID

respondToPoll

func respondToPoll(
    pollId: String,
    selectedOption: String
) async throws

endPoll

func endPoll(pollId: String) async throws

Host/Co-host only

getActivePolls

func getActivePolls() -> [BaxcloudPoll]

getPoll

func getPoll(
    pollId: String
) -> BaxcloudPoll?

Breakout Rooms

createBreakoutRoom

func createBreakoutRoom(
    roomName: String,
    participantIds: [String]
) async throws -> String

Host/Co-host only. Returns room ID

joinBreakoutRoom

func joinBreakoutRoom(
    roomId: String
) async throws

leaveBreakoutRoom

func leaveBreakoutRoom(
    roomId: String
) async throws

getBreakoutRooms

func getBreakoutRooms() -> [BaxcloudBreakoutRoom]

getBreakoutRoom

func getBreakoutRoom(
    roomId: String
) -> BaxcloudBreakoutRoom?

Emoji Reactions

sendEmojiReaction

func sendEmojiReaction(
    emoji: String
) async throws

getRecentEmojiReactions

func getRecentEmojiReactions() -> [BaxcloudEmojiReaction]

Waiting Room

approveWaitingRoomParticipant

func approveWaitingRoomParticipant(
    userId: String
) async throws

Host/Co-host only

rejectWaitingRoomParticipant

func rejectWaitingRoomParticipant(
    userId: String
) async throws

Host/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 throws

disablePIP

func disablePIP() async throws

isPIPEnabled

func isPIPEnabled() -> Bool

Background Effects

applyBackgroundEffect

func applyBackgroundEffect(
    _ effect: BaxcloudBackgroundEffect
) async throws

removeBackgroundEffect

func removeBackgroundEffect() async throws

getCurrentBackgroundEffect

func getCurrentBackgroundEffect() -> BaxcloudBackgroundEffect?

Accessibility

updateAccessibilitySettings

func updateAccessibilitySettings(
    _ settings: BaxcloudAccessibilitySettings
)

getAccessibilitySettings

func getAccessibilitySettings() -> BaxcloudAccessibilitySettings

Type 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?
}