Skip to main content
Join a call session using one of two approaches: the quick start method with a session ID, or the advanced flow with manual token generation for more control.

Overview

The CometChat Calls SDK provides two ways to join a session:
ApproachBest ForComplexity
Join with TokenMost use cases - recommended approachLow - Two-step process
Generate Token SeparatelyCustom token management, pre-generation, cachingMedium - Separate token handling
Both approaches require a container element in your HTML where the call interface will be rendered.

Container Setup

Add a container element to your HTML where the call interface will be rendered:
<div id="call-container" style="width: 100%; height: 100vh;"></div>
The call UI will be dynamically rendered inside this container when you join the session.

Generate Token

Generate a call token for the session. Each token is unique to a specific session and user combination.
const sessionId = "SESSION_ID";

try {
  const result = await CometChatCalls.generateToken(sessionId);
  console.log("Token generated:", result.token);
  // Use the token to join the session
} catch (error) {
  console.error("Token generation failed:", error.errorDescription);
}
ParameterTypeDescription
sessionIdStringUnique identifier for the call session
The method returns an object with:
PropertyTypeDescription
tokenStringThe generated call token
The generateToken() method uses the auth token of the currently logged-in user. Ensure a user is logged in before calling this method.

Join Session

Use the generated token to join the session along with your call settings and container element.
const container = document.getElementById("call-container");

const callSettings = {
  sessionType: "VIDEO",
  layout: "TILE",
  startAudioMuted: false,
  startVideoPaused: false,
};

const result = await CometChatCalls.joinSession(callToken, callSettings, container);

if (result.error) {
  console.error("Failed to join session:", result.error);
} else {
  console.log("Joined session successfully");
}
ParameterTypeDescription
callTokenStringPreviously generated call token
callSettingsObjectConfiguration for the session (see Session Settings)
containerHTMLElementContainer element for the call UI
The method returns an object with:
PropertyTypeDescription
dataundefinedUndefined on success
errorObject | nullError details if join failed

Complete Example

const sessionId = "SESSION_ID";
const container = document.getElementById("call-container");

// Step 1: Generate token
try {
  const tokenResult = await CometChatCalls.generateToken(sessionId);
  
  // Step 2: Configure session settings
  const callSettings = {
    sessionType: "VIDEO",
    layout: "TILE",
    startAudioMuted: false,
    startVideoPaused: false,
  };

  // Step 3: Join session
  const joinResult = await CometChatCalls.joinSession(
    tokenResult.token, 
    callSettings, 
    container
  );

  if (joinResult.error) {
    console.error("Failed to join session:", joinResult.error);
  } else {
    console.log("Joined session successfully");
  }
} catch (error) {
  console.error("Error:", error);
}
All participants joining the same call must use the same session ID.

Error Handling

Common errors when joining a session:
Error CodeDescription
ERROR_SDK_NOT_INITIALIZEDSDK not initialized - call init() first
ERROR_AUTH_TOKEN_MISSINGUser not logged in or auth token invalid
ERROR_SESSION_ID_MISSINGSession ID is null or empty
VALIDATION_ERRORInvalid call settings