VideoSDK Class Methods - iOS
createRoom()
- Creates a
Room. The room has not joined yet. Calljoin()on it to join. - Pass your
tokenhere. There is no separate config step. To generate a token, see this documentation. - Only
roomIdandtokenare required. See Creating a Room for all the parameters. createRoom()throws, so call it withtry.
Throws
VideoSDKError.ERROR_INVALID_PARAMETER(3073) ifroomIdortokenis empty. The token itself is checked when you join the room.
Returns
Room
Example
do {
room = try VideoSDK.createRoom(
roomId: "abc-1234-xyz",
token: "<YOUR_TOKEN>",
participantName: "John Doe",
micEnabled: true,
camEnabled: true
)
} catch {
print("Room setup failed: \(error)")
}
getAudioPermissionStatus()
- Returns the microphone permission status of your app.
Returns
AuthorisationStatus.notDetermined: the user has not been asked yet..restricted: access is blocked on the device, for example by parental controls. The user cannot change it..denied: the user denied access. They can allow it in the Settings app..authorized: the user allowed access.
Example
if VideoSDK.getAudioPermissionStatus() == .authorized {
print("Microphone access is allowed")
}
getVideoPermissionStatus()
- Returns the camera permission status of your app.
Returns
AuthorisationStatus.notDetermined: the user has not been asked yet..restricted: access is blocked on the device, for example by parental controls. The user cannot change it..denied: the user denied access. They can allow it in the Settings app..authorized: the user allowed access.
Example
if VideoSDK.getVideoPermissionStatus() == .authorized {
print("Camera access is allowed")
}
getAudioPermission()
-
It prompts the system alert to access the microphone for your app.
-
It will only prompt when the status for the audio permission is
.notDetermined. -
It returns before the user answers. To wait for the answer, call
await AVCaptureDevice.requestAccess(for: .audio)instead. -
If the status is
.denied, iOS does not show the alert again. Ask the user to allow microphone access in the Settings app, as shown in thegetVideoPermission()example. -
See our guide on handling permissions before a call here.
Returns
Void
Example
VideoSDK.getAudioPermission()
getVideoPermission()
-
It prompts the system alert to access the camera for your app.
-
It will only prompt when the status for the video permission is
.notDetermined. -
It returns before the user answers. To wait for the answer, call
await AVCaptureDevice.requestAccess(for: .video)instead. -
If the status is
.denied, iOS does not show the alert again. Ask the user to allow camera access in the Settings app. -
See our guide on handling permissions before a call here.
Returns
Void
Example
switch VideoSDK.getVideoPermissionStatus() {
case .notDetermined:
VideoSDK.getVideoPermission()
case .denied:
// Open your app's page in the Settings app
if let settingsURL = URL(string: UIApplication.openSettingsURLString) {
UIApplication.shared.open(settingsURL)
}
default:
break
}
getCameras()
- Lists the front and back cameras the SDK can open (the wide-angle camera on each side), as
CameraDeviceInfovalues. - Pass a camera's
deviceIdtochangeCam(deviceId:)of the room, or ascameraIdtocreateCameraVideoTrack(). ThedeviceIdis the camera'sAVCaptureDevice.uniqueID, not its name.
Returns
[CameraDeviceInfo]
Example
let cameras = VideoSDK.getCameras()
for camera in cameras {
print(camera.label, camera.deviceId, camera.facingMode?.rawValue ?? "external")
}
// Sample output:
// Front Camera com.apple.avfoundation.avcapturedevice.built-in_video:1 front
// Back Camera com.apple.avfoundation.avcapturedevice.built-in_video:0 back
getMics()
- Lists the audio devices you can choose from, as
MicrophoneDeviceInfovalues. The list starts withSpeaker, the loudspeaker output, followed by the microphones that are available, such asiPhone Microphoneor a connected headset. - Pass a device to
setAudioDevice(_:)of the room, itsdeviceIdtochangeMic(deviceId:)of the room, or itsdeviceIdasmicrophoneIdtocreateMicrophoneAudioTrack().
Returns
[MicrophoneDeviceInfo]
Example
let mics = VideoSDK.getMics()
print(mics.map(\.label))
// Sample output: ["Speaker", "iPhone Microphone"]
getDevices()
- Lists every camera and audio device in one array: the result of
getCameras()followed by the result ofgetMics(). - Check for
CameraDeviceInfoorMicrophoneDeviceInfo, or readkind, to tell them apart.
Returns
[DeviceInfo]
Example
for device in VideoSDK.getDevices() {
if let camera = device as? CameraDeviceInfo {
print("Camera: \(camera.label)")
} else {
print("Audio device: \(device.label)")
}
}
getSelectedVideoDevice()
- Returns the camera the SDK opens or is using.
- Returns
nilwhen there is no camera on that side.
Returns
CameraDeviceInfo?
Example
if let camera = VideoSDK.getSelectedVideoDevice() {
print("Current camera: \(camera.label)")
}
getSelectedAudioDevice()
- Returns the audio device in use:
Speakerwhile audio plays on the loudspeaker, otherwise the current microphone input. - Returns
nilwhen neither is known.
Returns
MicrophoneDeviceInfo?
Example
if let device = VideoSDK.getSelectedAudioDevice() {
print("Current audio device: \(device.label)")
}
createCameraVideoTrack()
- Creates a custom camera video track with the encoder settings you choose. Pass it to
createRoom(customCameraTrack:), or toenableCam(customCameraTrack:)orchangeCam(customCameraTrack:)of the room. - It opens the camera for a local preview. Nothing is sent until a room publishes the track.
- It is
async throws. Call it withtry await. - It never asks for camera permission. Until access is granted, it throws
ERROR_CAMERA_ACCESS_DENIED_OR_DISMISSED. Ask first withgetVideoPermission(). - It waits up to 2 seconds for the camera to open and throws the errors that happen in that time. If the camera fails after that, the track ends and its
onEndedhandler receives the error. - See Custom Tracks for more about custom tracks.
Parameters
- encoderConfig:
CustomCameraTrackConfig?, default.h720p_w1280p. The resolution and frame rate of the track. - facingMode:
FacingMode?, default.front..frontor.back. If there is no camera on that side, the other camera is used. - multiStream:
Bool?, defaulttrue. Whentrue, the track is sent in several resolution layers. - cameraId:
String?, defaultnil. ThedeviceIdof a camera fromgetCameras(). When you set it, it picks the camera instead offacingMode. - maxLayer:
EncodingLayer?, default.MAX_LAYER_3. Used only whenmultiStreamistrue. - bitrateMode:
BitrateMode?, default.BALANCED. - codec:
VideoCodec?, default.VP8.
Throws
VideoSDKError:ERROR_INVALID_CUSTOM_TRACK_CONFIG(3071) when no camera has thedeviceIdyou passed ascameraId.ERROR_CAMERA_ACCESS_DENIED_OR_DISMISSED(3017) when camera access is not granted.ERROR_CAMERA_NOT_FOUND(3021) when the device has no camera.ERROR_CAMERA_IN_USE(3023) when another app is using the camera.ERROR_VIDEO_SOURCE_INITIATION_FAILED(3026) when the camera could not be opened.
Returns
CustomStreamTrack
Example
Task {
do {
let cameraTrack = try await VideoSDK.createCameraVideoTrack(
encoderConfig: .h720p_w1280p,
facingMode: .front,
multiStream: true
)
try await room?.enableCam(customCameraTrack: cameraTrack)
} catch let error as VideoSDKError {
print("Could not turn on the camera: \(error.message)")
} catch {
print("Could not turn on the camera: \(error)")
}
}
createMicrophoneAudioTrack()
- Creates a custom microphone audio track with the audio processing and encoder settings you choose. Pass it to
createRoom(customMicrophoneTrack:), or tounmuteMic(customMicrophoneTrack:)orchangeMic(customMicrophoneTrack:)of the room. - It is
async throws. Call it withtry await. - It never asks for microphone permission. Until access is granted, it throws
ERROR_MICROPHONE_ACCESS_DENIED_OR_DISMISSED. Ask first withgetAudioPermission(). - It waits up to 2 seconds for the microphone to open and throws the errors that happen in that time. If the microphone fails after that, the track ends and its
onEndedhandler receives the error.
Parameters
- encoderConfig:
CustomMicrophoneTrackConfig?, default.speech_standard. - microphoneId:
String?, defaultnil. ThedeviceIdof a microphone fromgetMics(). - noiseConfig:
NoiseConfig?, defaultnil. Turns noise suppression, echo cancellation, automatic gain control and the high-pass filter on or off. See Custom Audio Track.
Throws
VideoSDKError:ERROR_INVALID_CUSTOM_TRACK_CONFIG(3071) when no microphone has thedeviceIdyou passed asmicrophoneId.ERROR_MICROPHONE_ACCESS_DENIED_OR_DISMISSED(3018) when microphone access is not granted.ERROR_MICROPHONE_NOT_FOUND(3022) when the device has no microphone.ERROR_MICROPHONE_IN_USE(3024) when another app is using the microphone.
Returns
CustomStreamTrack
Example
Task {
do {
let microphoneTrack = try await VideoSDK.createMicrophoneAudioTrack(
encoderConfig: .speech_standard,
noiseConfig: NoiseConfig(
noiseSuppression: true,
echoCancellation: true,
autoGainControl: true,
highPassFilter: false
)
)
try await room?.unmuteMic(customMicrophoneTrack: microphoneTrack)
} catch {
print("Could not turn on the microphone: \(error)")
}
}
createScreenShareVideoTrack()
- Creates a screen-share track with the encoder settings you choose. Pass it to
enableScreenShare(_:)of the room to start sharing. - It does not start capture. Capture starts after the user confirms the system picker that
enableScreenShare(_:)shows.
Parameters
- encoderConfig:
CustomScreenShareTrackConfig, default.h720p_15fps. One of.h360p_30fps,.h480p_15fps,.h480p_30fps,.h720p_5fps,.h720p_15fps,.h720p_30fps,.h1080p_15fpsor.h1080p_30fps. - multiStream:
Bool, defaultfalse. Whentrue, the share is sent in three quality layers. Whenfalse, it is sent in one layer. - withAudio:
Bool, defaultfalse. Accepted and ignored: screen share on iOS carries no audio.
Returns
CustomStreamTrack. It holds only the share settings: itsvideoTrackandaudioTrackarenil.
Example
let screenShareTrack = VideoSDK.createScreenShareVideoTrack(encoderConfig: .h1080p_15fps)
Task {
do {
try await room?.enableScreenShare(screenShareTrack)
} catch {
print("Could not start screen share: \(error)")
}
}
setKeyProvider()
- Sets the
BaseKeyProviderthat holds the end-to-end encryption (E2EE) keys. Call it before you join the room. - A shared key (
setSharedKey(_:)) encrypts the whole room. Without one, only participants given a key withsetParticipantKey()are encrypted. - To turn E2EE off for the next join, call
removeKeyProvider(). - See E2EE for the methods of
BaseKeyProvider.
Parameters
- provider:
BaseKeyProvider
Returns
Void
Example
do {
let keyProvider = BaseKeyProvider()
try keyProvider.setSharedKey("<YOUR_SHARED_KEY>")
VideoSDK.setKeyProvider(keyProvider)
} catch {
print("Could not set the encryption key: \(error)")
}
removeKeyProvider()
- Turns E2EE off for the next join and forgets the provider set with
setKeyProvider().
Returns
Void
Example
VideoSDK.removeKeyProvider()
getKeyProvider()
- Returns the provider you set with
setKeyProvider(), ornilif none is set.
Returns
BaseKeyProvider?
Example
let e2eeConfigured = VideoSDK.getKeyProvider() != nil
setParticipantKey()
- Sets, changes or removes the E2EE key of one participant. It takes effect at once, also while in a room.
- Set a key provider with
setKeyProvider()first. Without one, it throwsERROR_INVALID_PARAMETER(3073). - The key is also saved in that provider, so a rejoin uses the same keys.
- Participant keys are not used while a shared key is set.
- The ID and key are used exactly as you pass them.
- See E2EE for the methods of
BaseKeyProvider.
Parameters
- participantId:
String - key:
String?. Passnilto remove the participant's key.
Returns
Void
Example
do {
try VideoSDK.setParticipantKey("<PARTICIPANT_ID>", key: "<NEW_KEY>")
} catch {
print("Could not set the participant key: \(error)")
}
runPreCallTest()
- Checks the camera and microphone, and then measures the upload and download network quality, before the user joins a room.
- It is
async throws. Call it withtry await. - Camera and microphone access must already be granted.
- If you do not pass your own tracks in the options, the SDK opens the camera and microphone itself. A track the SDK opened that passed the check stays open and is returned in the result's
camera.trackandmicrophone.track. Callstop()on it when you are done. - Run it before
createRoom(), or after you leave the room. Only one test can run at a time. - Cancelling the calling
Taskstops the test, likestopPreCallTest(). - See Pre-call Test for the option and result types, and Precall Setup for a full pre-call flow.
Parameters
- options:
PreCallTestOptions. The token, how long to measure the network (samplingDuration, 10 000 to 120 000 ms, default 15 000) and the devices to test. - onStatsChange: optional closure that receives the latest
PreCallNetworkQualityon the main thread while the test runs.
Throws
PreCallTestErrorwith a stringcode, such asERROR_PRECALL_INVALID_TOKEN,ERROR_PRECALL_TEST_ALREADY_RUNNINGorERROR_PRECALL_AFTER_INIT.
Returns
PreCallTestResultwith thecamera,microphoneandnetworkQualityresults. Itsabortedproperty istruewhen the test was stopped.
Example
Task {
do {
let result = try await VideoSDK.runPreCallTest(
PreCallTestOptions(token: "<YOUR_TOKEN>", samplingDuration: 15_000)
) { stats in
print("Upload quality: \(stats.uplink.quality)")
}
print("Download quality: \(result.networkQuality?.downlink.quality ?? 0)")
} catch let error as PreCallTestError {
print("Pre-call test failed: \(error.code) \(error.message)")
} catch {
print("Pre-call test failed: \(error)")
}
}
stopPreCallTest()
- Stops the running pre-call test and returns once it has stopped. The pending
runPreCallTest()call then returns a result whoseabortedproperty istrue. - Calling it when no test is running does nothing.
Returns
Void
Example
Task {
await VideoSDK.stopPreCallTest()
}
setScreenFlash()
- Sets the screen flash that lights the user's face when you call
captureImage(width:height:flash:)withflash: .ONon a camera that has no torch, such as most front cameras. WhiteOverlayScreenFlashcovers a window in warm white at full brightness while the photo is taken.- The SDK keeps the screen flash until you replace it.
Parameters
- flash:
ScreenFlash?. The screen flash to use, for exampleWhiteOverlayScreenFlash(window:). Passnilto remove it.
Returns
Void
Example
VideoSDK.setScreenFlash(WhiteOverlayScreenFlash(window: view.window))
setLogLevel()
- Sets how much the SDK logs to the Xcode console. Before you call it, the level is
.INFO. If you call it without a level, it uses.INFO. - From least to most verbose:
.NONE,.ERROR,.WARN,.INFO,.DEBUG,.ALL. Each level includes the ones before it. - See Log Level for more details.
Parameters
- level:
LogLevel, default.INFO.
Returns
Void
Example
VideoSDK.setLogLevel(level: .DEBUG)
getLogLevel()
- Returns the level you set with
setLogLevel(), or.INFOif you have not set one.
Returns
LogLevel
Example
if VideoSDK.getLogLevel() == .DEBUG {
print("Debug logs are on")
}
Device types
DeviceInfo
- A device the SDK can use: a camera or an audio device.
getDevices()returns both kinds in one array. - Two
DeviceInfovalues are equal when theirkindanddeviceIdmatch.
Properties
- label:
String. The name to show in a picker. - kind:
MediaKind..videofor a camera,.audiofor an audio device. - deviceId:
String. The ID to pass back to the SDK, for example ascameraIdor tochangeMic(deviceId:).
CameraDeviceInfo
- A camera, listed by
getCameras(). It is aDeviceInfowithkind.video. - Its
labelis the camera's name and itsdeviceIdisAVCaptureDevice.uniqueID.
Properties
- facingMode:
FacingMode?. Which way the lens points, ornilfor a camera that is neither front nor back.
MicrophoneDeviceInfo
- An audio device, listed by
getMics(). It is aDeviceInfowithkind.audio. - It is either a microphone input or the
Speakeroutput. ItsdeviceIdis the input port's unique ID, orSpeakerfor the loudspeaker. Itslabelis the name to show, such asSpeakerorHeadphones.
FacingMode
- Which way a camera points. Used by
createCameraVideoTrack(facingMode:),createRoom(defaultCamera:)andCameraDeviceInfo.facingMode.
Values
.front: the front (user-facing) camera..back: the back (environment-facing) camera.
Got a Question? Ask us on discord

