Quick Reference - Generate token and start a standalone call session:
Available via: SDK | UI Kits
Overview
This section demonstrates how to implement calling functionality using only the CometChat Calls SDK, without requiring the Chat SDK. This is ideal for applications that need video/audio calling capabilities without the full chat infrastructure.Before you begin, ensure you have completed the Calls SDK setup.
User Authentication
To start a call session, you need a user auth token. Since this implementation doesn’t use the Chat SDK, you’ll need to obtain the auth token via the CometChat REST API.To understand user authentication in CometChat, see the User Auth documentation.
- Create Auth Token — Creates a new auth token for a user
- Get Auth Token — Retrieves an existing auth token
For testing or POC purposes, you can create an auth token directly from the CometChat Dashboard. Navigate to Users & Groups → Users, select a user, and click + Create Auth Token.
Generate Call Token
A call token is required for secure access to a call session. Each token is unique to a specific session and user combination, ensuring that only authorized users can join the call. You can generate the token just before starting the call, or generate and store it ahead of time based on your use case. Use thegenerateToken() method to create a call token:
- JavaScript
- TypeScript
| Parameter | Description |
|---|---|
sessionId | A unique session ID for the call. Generate this yourself or use a shared ID for participants to join the same call. |
userAuthToken | The user auth token obtained from the CometChat REST API. |
Start Call Session
Use theCometChatCalls.Component to render the call UI. This component requires a call token (generated in the previous step) and a CallSettings object that configures the call UI and behavior.
- JavaScript
- TypeScript
| Parameter | Description |
|---|---|
callToken | The GenerateToken object received from generateToken() onSuccess |
callSettings | Object of CallSettings class configured via CallSettingsBuilder |
Call Settings
Configure the call experience using the followingCallSettingsBuilder methods:
| Method | Description |
|---|---|
enableDefaultLayout(boolean) | Enables or disables the default call UI layout with built-in controls. true shows the default layout with end call, mute, video toggle buttons. false hides the button layout. Default: true |
setIsAudioOnlyCall(boolean) | Sets whether the call is audio-only or audio-video. true for audio-only, false for audio-video. Default: false |
setCallEventListener(OngoingCallListener) | Sets the listener to receive call events. See Call Listeners for available callbacks. |
setMode(string) | Sets the call UI layout mode. Available: CometChat.CALL_MODE.DEFAULT (grid), CometChat.CALL_MODE.SPOTLIGHT (active speaker), CometChat.CALL_MODE.SINGLE (one participant). Default: DEFAULT |
setAvatarMode(string) | Sets how avatars are displayed when video is off. Available: circle, square, fullscreen. Default: circle |
setDefaultAudioMode(string) | Sets the initial audio output device. Available: SPEAKER, EARPIECE, BLUETOOTH, HEADPHONES |
startWithAudioMuted(boolean) | Starts the call with the microphone muted. Default: false |
startWithVideoMuted(boolean) | Starts the call with the camera turned off. Default: false |
showEndCallButton(boolean) | Shows or hides the end call button in the default layout. Default: true |
showSwitchCameraButton(boolean) | Shows or hides the switch camera button (front/back). Default: true |
showMuteAudioButton(boolean) | Shows or hides the mute audio button. Default: true |
showPauseVideoButton(boolean) | Shows or hides the pause video button. Default: true |
showAudioModeButton(boolean) | Shows or hides the audio mode selection button. Default: true |
showSwitchToVideoCallButton(boolean) | Shows or hides the button to upgrade an audio call to video. Default: true |
setMainVideoContainerSetting(MainVideoContainerSetting) | Customizes the main video container. See Video View Customization. |
enableVideoTileClick(boolean) | Enables or disables click interactions on video tiles in Spotlight mode. Default: true |
enableVideoTileDrag(boolean) | Enables or disables drag functionality for video tiles in Spotlight mode. Default: true |
setIdleTimeoutPeriod(number) | Sets idle timeout in seconds. Warning appears 60 seconds before auto-termination. Default: 180 seconds. v4.2.0+ |
Call Listeners
TheOngoingCallListener provides real-time callbacks for call session events, including participant changes, call state updates, and error conditions.
You can register listeners in two ways:
- Via CallSettingsBuilder: Use
.setCallEventListener(listener)when building call settings - Via addCallEventListener: Use
CometChatCalls.addCallEventListener(listenerId, listener)to add multiple listeners
listenerId string. This ID is used to:
- Prevent duplicate registrations — Re-registering with the same ID replaces the existing listener
- Enable targeted removal — Remove specific listeners without affecting others
- JavaScript
- TypeScript
Events
| Event | Description |
|---|---|
onCallEnded() | Invoked when the call session terminates for a 1:1 call. Both participants receive this callback. Only fires for calls with exactly 2 participants. |
onSessionTimeout() | Invoked when the call is auto-terminated due to inactivity (default: 180 seconds). Warning appears 60 seconds before. v4.2.0+ |
onCallEndButtonPressed() | Invoked when the local user taps the end call button. Call CometChatCalls.endSession() to leave the session. |
onUserJoined(user) | Invoked when a remote participant joins. The user contains UID, name, and avatar. |
onUserLeft(user) | Invoked when a remote participant leaves the call session. |
onUserListUpdated(userList) | Invoked whenever the participant list changes (join or leave events). |
onAudioModesUpdated(audioModes) | Invoked when available audio devices change (e.g., Bluetooth connected). |
onCallSwitchedToVideo(event) | Invoked when an audio call is upgraded to a video call. |
onUserMuted(event) | Invoked when a participant’s mute state changes. |
onScreenShareStarted() | Invoked when the local user starts sharing a screen. |
onScreenShareStopped() | Invoked when the local user stops sharing a screen. |
onError(error) | Invoked when an error occurs during the call session. |
End Call Session
To end the call session and release all media resources (camera, microphone, network connections), callCometChatCalls.endSession() in the onCallEndButtonPressed() callback.
- JavaScript
- TypeScript
Methods
These methods are available for performing custom actions during an active call session. Use them to build custom UI controls or implement specific behaviors based on your use case.These methods can only be called when a call session is active.
Switch Camera
Toggles between the front and rear camera during a video call. Useful for allowing users to switch their camera view without leaving the call.- JavaScript
- TypeScript
Mute Audio
Controls the local audio stream transmission. When muted, other participants cannot hear the local user.true— Mutes the microphone, stops transmitting audiofalse— Unmutes the microphone, resumes audio transmission
- JavaScript
- TypeScript
Pause Video
Controls the local video stream transmission. When paused, other participants see a frozen frame or avatar instead of live video.true— Pauses the camera, stops transmitting videofalse— Resumes the camera, continues video transmission
- JavaScript
- TypeScript
Set Audio Mode
Routes the audio output to a specific device. Use this to let users choose between speaker, earpiece, or connected audio devices. Available modes:CometChat.AUDIO_MODE.SPEAKER— Device speaker (loudspeaker)CometChat.AUDIO_MODE.EARPIECE— Phone earpieceCometChat.AUDIO_MODE.BLUETOOTH— Connected Bluetooth deviceCometChat.AUDIO_MODE.HEADPHONES— Wired headphones
- JavaScript
- TypeScript
Switch To Video Call
Upgrades an ongoing audio call to a video call. This enables the camera and starts transmitting video to other participants. The remote participant receives theonCallSwitchedToVideo() callback.
- JavaScript
- TypeScript
Get Audio Output Modes
Returns the list of available audio output devices. Use this to display audio options to the user and then set the selected mode usingsetAudioMode().
- JavaScript
- TypeScript
End Call
Terminates the current call session and releases all media resources (camera, microphone, network connections). After calling this method, the call view should be closed.- JavaScript
- TypeScript
Best Practices
Generate call tokens just before use
Generate call tokens just before use
Call tokens are session-specific and time-limited. Generate them right before starting the call session rather than caching them for extended periods. This ensures the token is fresh and reduces the chance of token expiry errors.
Use a shared session ID for participants
Use a shared session ID for participants
Secure your auth tokens
Secure your auth tokens
Since standalone calling uses REST API auth tokens instead of the Chat SDK login flow, ensure tokens are generated server-side and delivered securely to the client. Never hardcode auth tokens in your app bundle.
Clean up listeners on component unmount
Clean up listeners on component unmount
Always remove call event listeners in your component’s cleanup function (e.g., the return function of
useEffect). Orphaned listeners can cause memory leaks, duplicate event handling, and unexpected behavior when navigating between screens.Wrap the call component in a full-screen container
Wrap the call component in a full-screen container
The
CometChatCalls.Component should be rendered inside a View with height: '100%', width: '100%', and position: 'relative'. This ensures the call UI fills the screen correctly and overlays render in the right position.Troubleshooting
Call token generation fails
Call token generation fails
Verify the auth token is valid and hasn’t expired. Auth tokens obtained from the REST API or Dashboard have an expiry — generate a fresh one if needed. Also confirm the
sessionId is a non-empty string.Call UI does not render
Call UI does not render
Ensure the
CometChatCalls.Component is wrapped in a View with explicit dimensions (height: '100%', width: '100%'). Also confirm that both callSettings and callToken props are provided and not null or undefined.Participants can't join the same call
Participants can't join the same call
Both participants must use the exact same
sessionId when generating their call tokens. Double-check that the session ID is being shared correctly between devices.Listeners not firing
Listeners not firing
Check that the listener is registered before the call session starts. If using
addCallEventListener, ensure the listenerId is unique and hasn’t been overwritten by another registration. Also verify that the Calls SDK has been initialized via CometChatCalls.init().Audio or video not working after call starts
Audio or video not working after call starts
Check device permissions for camera and microphone. On React Native, request
CAMERA and RECORD_AUDIO permissions on Android, and add NSCameraUsageDescription and NSMicrophoneUsageDescription to Info.plist on iOS.