enableCam

suspend fun enableCam(customCameraTrack: CustomStreamTrack? = null)

Enables the local participant's webcam and publishes it to the room.

Without a customCameraTrack, the camera opens with the settings this room already holds: those of the last custom track, plus the lens and device in use, or the default capture profile if the camera has never been opened. Passing a track replaces those settings, and later enableCam() calls reuse them until another track replaces them.

Requires a joined room. Called before the join completes, it does nothing and emits RoomEventListener.onError with code 3035 (ERROR_ACTION_PERFORMED_BEFORE_ROOM_JOINED); while the room is RoomState.RECONNECTING, with code 3065 (ERROR_ROOM_RECONNECTING). A rejected call releases customCameraTrack, so a refused enable never leaves the camera open. An ended track is reported on onError as code 3031 (ERROR_CUSTOM_VIDEO_TRACK_ENDED) and the camera opens with the stored settings instead.

Events:

Code Example:

lifecycleScope.launch { room.enableCam() }

// or publish a custom camera track
lifecycleScope.launch {
val track = VideoSDK.createCameraVideoTrack(
encoderConfig = CustomCameraTrackConfig.H720P_W1280P,
facingMode = FacingMode.front,
)
room.enableCam(track)
}

Parameters

customCameraTrack

the track to publish, from VideoSDK.createCameraVideoTrack. If null, the room's stored camera settings are used.

See also

Throws

code 3054 (ERROR_ALREADY_IN_REQUESTED_STATE) if the webcam is already on, code 3055 (ERROR_OPERATION_IN_PROGRESS) while another webcam toggle or a changeMode is still running, code 3066 (ERROR_ACTION_NOT_SUPPORTED_IN_MODE) outside Mode.SEND_AND_RECV, or the camera error already reported on onError if the camera cannot be opened.