CometChat Calls SDK v5 — Video Controls
Overview
Programmatically control the local camera (pause/resume) and switch between video input devices during an active call.
Key Imports
import { CometChatCalls } from '@cometchat/calls-sdk-javascript';
Implementation
Pause / Resume Video
CometChatCalls.pauseVideo(); // turn off camera
CometChatCalls.resumeVideo(); // turn on camera
CometChatCalls.toggleVideo(); // toggle camera state
Switch Camera (Mobile Web)
CometChatCalls.switchCamera(); // toggle front ↔ back (mobile devices)
Get Available Video Devices
const videoInputs = CometChatCalls.getVideoInputDevices();
Get Current Video Device
const currentCamera = CometChatCalls.getCurrentVideoInputDevice();
Switch Video Input Device
const devices = CometChatCalls.getVideoInputDevices();
CometChatCalls.setVideoInputDevice(devices[1].deviceId);
Listen for Video Events
CometChatCalls.addEventListener('onVideoPaused', () => {
// Update video button to "off" state, show avatar
});
CometChatCalls.addEventListener('onVideoResumed', () => {
// Update video button to "on" state, show video
});
CometChatCalls.addEventListener('onVideoInputDeviceChanged', (device) => {
console.log('Camera switched to:', device.label);
});
CometChatCalls.addEventListener('onVideoInputDevicesChanged', (devices) => {
// Device list changed — rebuild camera selector UI
});
Pre-select Device (Before Joining)
const sessionSettings: SessionSettings = {
sessionType: 'VIDEO',
videoInputDeviceId: 'specific-camera-id',
startVideoPaused: false,
};
Gotchas
pauseVideo()/resumeVideo()only work during an active sessionswitchCamera()is primarily for mobile web (front/back toggle) — on desktop, usesetVideoInputDevice()- Device lists return
MediaDeviceInfoobjects withdeviceId,label,kind,groupId - Device labels may be empty strings until the user grants camera permission
- For voice calls (
sessionType: 'VOICE'), setstartVideoPaused: true - Camera permissions must be granted before joining — the SDK requests them automatically