Overview
This section demonstrates how to start a call session in a web application. Previously known as Direct Calling. Before you begin, we strongly recommend you read the calling setup guide.If you want to implement a complete calling experience with ringing functionality (incoming/outgoing call UI), follow the Ringing guide first. Once the call is accepted, return here to start the call session.
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 | The unique random session ID. In case you are using the ringing flow, the session ID is available in the Call object. |
authToken | The user auth token is the logged-in user auth token which you can get by calling CometChat.getLoggedinUser().getAuthToken() |
Start Call Session
Use thestartSession() method to join a call session. This method requires:
- A call token (generated in the previous step)
- A
CallSettingsobject that configures the call UI and behavior - An HTML element where the call UI will be rendered
- JavaScript
- TypeScript
| Parameter | Description |
|---|---|
callToken | The token received from generateToken() onSuccess |
callSettings | Object of CallSettings class configured via CallSettingsBuilder |
htmlElement | DOM element where the call UI will be rendered |
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. 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 |
setCallListener(OngoingCallListener) | Sets the listener to receive call events. See Call Listeners. |
setMode(string) | Sets the call UI layout mode. Available: CometChat.CALL_MODE.DEFAULT, CometChat.CALL_MODE.SPOTLIGHT. Default: DEFAULT |
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 |
showMuteAudioButton(boolean) | Shows or hides the mute audio button. Default: true |
showPauseVideoButton(boolean) | Shows or hides the pause video button. Default: true |
showScreenShareButton(boolean) | Shows or hides the screen share button. Default: true |
showModeButton(boolean) | Shows or hides the mode toggle button (switch between DEFAULT and SPOTLIGHT). 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. |
setIdleTimeoutPeriod(number) | Sets idle timeout in seconds. Warning appears 60 seconds before auto-termination. Default: 180 seconds. v4.1.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
.setCallListener(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.1.0+ |
onCallEndButtonPressed() | Invoked when the local user clicks the end call button. For ringing flow, call CometChat.endCall(). For standalone, call CometChatCalls.endSession(). |
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). |
onMediaDeviceListUpdated(deviceList) | Invoked when available audio/video devices change (e.g., new microphone connected). |
onUserMuted(event) | Invoked when a participant’s mute state changes. Contains muted and mutedBy properties. |
onScreenShareStarted() | Invoked when the local user starts sharing their screen. |
onScreenShareStopped() | Invoked when the local user stops sharing their screen. |
onCallSwitchedToVideo(event) | Invoked when an audio call is upgraded to a video call. Contains sessionId, initiator, and responder. |
onError(error) | Invoked when an error occurs during the call session. |
End Call Session
Ending a call session properly is essential to release media resources (camera, microphone, network connections) and update call state across all participants. The termination process differs based on whether you’re using the Ringing flow or Session Only flow.Ringing Flow
When using the Ringing flow, you must coordinate between the CometChat Chat SDK and the Calls SDK to properly terminate the call and notify all participants.The Ringing flow requires calling methods from both the Chat SDK (
CometChat.endCall()) and the Calls SDK (CometChatCalls.endSession()) to ensure proper call termination and participant notification.
onCallEndButtonPressed() callback is triggered. You must call CometChat.endCall() inside this callback to properly terminate the call and notify other participants. On success, call CometChat.clearActiveCall() and CometChatCalls.endSession() to release resources.
- JavaScript
- TypeScript
onCallEnded() callback):
Call CometChat.clearActiveCall() to clear the local call state, then call CometChatCalls.endSession() to release media resources.
- JavaScript
- TypeScript
Session Only Flow
When using the Session Only flow (direct call without ringing), you only need to call the Calls SDK method to end the session. There’s no need to notify the Chat SDK since no call signaling was involved. CallCometChatCalls.endSession() in the onCallEndButtonPressed() callback to release all media resources and disconnect from the call session.
- 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. Only supported on mobile browsers.- JavaScript
- TypeScript
This method is only supported on mobile browsers. It has no effect on desktop browsers. Available since v4.2.0
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 placeholder instead of live video.true— Pauses the camera, stops transmitting videofalse— Resumes the camera, continues video transmission
- JavaScript
- TypeScript
Start Screen Share
Starts sharing your screen or a specific application window with other participants.- JavaScript
- TypeScript
Stop Screen Share
Stops the current screen sharing session.- JavaScript
- TypeScript
Set Mode
Changes the call UI layout mode dynamically during the call. Available modes:CometChat.CALL_MODE.DEFAULT— Grid layout showing all participantsCometChat.CALL_MODE.SPOTLIGHT— Focus on the active speaker
- JavaScript
- TypeScript
Get Audio Input Devices
Returns a list of available audio input devices (microphones).- JavaScript
- TypeScript
Get Audio Output Devices
Returns a list of available audio output devices (speakers/headphones).- JavaScript
- TypeScript
Get Video Input Devices
Returns a list of available video input devices (cameras).- JavaScript
- TypeScript
Set Audio Input Device
Sets the active audio input device (microphone) by device ID.- JavaScript
- TypeScript
Set Audio Output Device
Sets the active audio output device (speaker/headphones) by device ID.- JavaScript
- TypeScript
Set Video Input Device
Sets the active video input device (camera) by device ID.- 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
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