Learn how to generate call tokens, start and manage call sessions, configure call settings, and handle call events using the CometChat JavaScript Calls SDK.
A call session is the active media connection between participants — camera, microphone, screen sharing, and the call UI. Whether you arrive here from the Ringing flow, your own custom UI, or Standalone Calling, this page covers how to manage the session itself.Before you begin, make sure you’ve completed the Calls SDK Setup.
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.
In the Ringing flow, the session ID comes from the Call object after the call is accepted.
For direct sessions, generate your own unique session ID.
TypeScript
JavaScript
const loggedInUser = await CometChat.getLoggedinUser();const authToken = loggedInUser.getAuthToken();const sessionId: string = "SESSION_ID"; // Random or from Call object in ringing flowCometChatCalls.generateToken(sessionId, authToken).then( (callToken: any) => { console.log("Call token generated:", callToken.token); // Use callToken to start the session }, (error: CometChat.CometChatException) => { console.log("Token generation failed:", error); });
const loggedInUser = await CometChat.getLoggedinUser();const authToken = loggedInUser.getAuthToken();const sessionId = "SESSION_ID"; // Random or from Call object in ringing flowCometChatCalls.generateToken(sessionId, authToken).then( (callToken) => { console.log("Call token generated:", callToken.token); // Use callToken to start the session }, (error) => { console.log("Token generation failed:", error); });
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()
The Promise resolves with an object containing a token property (string) that you pass to startSession().
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.
User who initiates the end call:When the user clicks the end call button in the UI, the 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.
Remote participant (receives the onCallEnded() callback):Call CometChat.clearActiveCall() to clear the local call state, then call CometChatCalls.endSession() to release media resources.
TypeScript
JavaScript
onCallEnded: () => { CometChat.clearActiveCall(); CometChatCalls.endSession(); // Close the calling screen}
onCallEnded: () => { CometChat.clearActiveCall(); CometChatCalls.endSession(); // Close the calling screen}
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.
TypeScript
JavaScript
onCallEndButtonPressed: () => { CometChatCalls.endSession(); // Close the calling screen}
onCallEndButtonPressed: () => { CometChatCalls.endSession(); // Close the calling screen}
The OngoingCallListener 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
Each listener requires a unique 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
Always remove call event listeners when they’re no longer needed (e.g., on component unmount or when the call screen is closed). Failing to remove listeners can cause memory leaks and duplicate event handling.
For the full list of callbacks, their descriptions, and parameter shapes, see the OngoingCallListener reference.The ringing flow methods (initiateCall(), acceptCall(), rejectCall(), endCall()) return Call objects.
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.
Upgrades an ongoing audio call to a video call. This enables the camera and starts transmitting video to other participants. The remote participant receives the onCallSwitchedToVideo() callback.
Terminates the current call session and releases all media resources (camera, microphone, network connections). After calling this method, the call view should be closed.