click Video
Toggles the video stream on or off based on the user's input and checks required permissions and constraints.
Parameters:
options(ClickVideoOptions): Contains the parameters needed for toggling video, including:checkMediaPermission: Boolean to verify media permission.hasCameraPermission: Boolean indicating if camera permission is granted.videoAlreadyOn: Boolean to check if the video is already on.audioOnlyRoom: Boolean indicating if the room is audio-only.recordStarted,recordResumed,recordPaused,recordStopped: Flags for recording state.recordingMediaOptions: String defining the current recording mode ("video" or "audio").islevel: User level (e.g., host, co-host).showAlert: Optional function for displaying alerts.vidCons: Video constraints for video width, height, etc.frameRate: Preferred frame rate for video.userDefaultVideoInputDevice: The device ID of the user's preferred video input device.currentFacingMode: The facing mode for the camera (e.g., front or back).
Process:
Permission and Recording State Check:
Checks if the user is in an audio-only room or if video toggling conflicts with ongoing recording.
Video Turn Off:
If the video is already on, it disables the video tracks and disconnects the transport.
Video Turn On:
Checks for admin or co-host restrictions before proceeding.
If permitted, requests camera access if not already granted, applies media constraints, and initiates the video stream.
Helper Functions:
buildMediaConstraints: Builds media constraints using device ID and other parameters.
buildAltMediaConstraints: Builds alternative media constraints when the preferred device is unavailable.
buildFinalMediaConstraints: Builds final media constraints for the video stream.
attemptStream: Attempts to initialize the video stream with the specified constraints.
Example Usage:
val options = ClickVideoOptions(
parameters = object : ClickVideoParameters {
override val checkMediaPermission: Boolean = true
override val hasCameraPermission: Boolean = false
override val videoAlreadyOn: Boolean = false
override val audioOnlyRoom: Boolean = false
override val vidCons: VidCons = VidCons(width = 1280, height = 720)
override val frameRate: Int = 30
override val userDefaultVideoInputDevice: String = "front"
override val currentFacingMode: String = "user"
// Other properties...
}
)
clickVideo(options)Error Handling:
Handles permission issues by displaying alerts.
Attempts to access alternative video devices if the preferred device is unavailable.
Displays a message if camera access is denied or unavailable.