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 Session IDMost use cases - simple and straightforwardLow - One method call
Join with TokenCustom token management, pre-generation, cachingMedium - Two-step process
Both approaches require a container view in your layout and properly configured SessionSettings.

Container Setup

Add a container view to your layout where the call interface will be rendered:
<RelativeLayout
    android:id="@+id/call_view_container"
    android:layout_width="match_parent"
    android:layout_height="match_parent" />
The call UI will be dynamically added to this container when you join the session.

Join with Session ID

The simplest way to join a session. Pass a session ID and the SDK automatically generates the token and joins the call.
val sessionId = "SESSION_ID"
val callViewContainer = findViewById<RelativeLayout>(R.id.call_view_container)

val sessionSettings = CometChatCalls.SessionSettingsBuilder()
    .setDisplayName("John Doe")
    .setType(SessionType.VIDEO)
    .build()

CometChatCalls.joinSession(sessionId, sessionSettings, callViewContainer, 
    object : CometChatCalls.CallbackListener<CallSession>() {
        override fun onSuccess(callSession: CallSession) {
            Log.d(TAG, "Joined session successfully")
        }

        override fun onError(e: CometChatException) {
            Log.e(TAG, "Failed: ${e.message}")
        }
    }
)
ParameterTypeDescription
sessionIdStringUnique identifier for the call session
sessionSettingsSessionSettingsConfiguration for the session
callViewContainerRelativeLayoutContainer view for the call UI
listenerCallbackListenerCallback for success/error handling
All participants joining the same call must use the same session ID.

Join with Token

For scenarios requiring more control over token generation, such as pre-generating tokens, implementing custom caching strategies, or managing token lifecycle separately. Step 1: Generate Token Generate a call token for the session. Each token is unique to a specific session and user combination.
val sessionId = "SESSION_ID"

CometChatCalls.generateToken(sessionId, object : CometChatCalls.CallbackListener<GenerateToken>() {
    override fun onSuccess(token: GenerateToken) {
        Log.d(TAG, "Token generated: ${token.token}")
        // Store or use the token
    }

    override fun onError(e: CometChatException) {
        Log.e(TAG, "Token generation failed: ${e.message}")
    }
})
ParameterTypeDescription
sessionIdStringUnique identifier for the call session
listenerCallbackListenerCallback returning the generated token
Step 2: Join with Token Use the generated token to join the session. This gives you control over when and how the token is used.
val callViewContainer = findViewById<RelativeLayout>(R.id.call_view_container)

val sessionSettings = CometChatCalls.SessionSettingsBuilder()
    .setDisplayName("John Doe")
    .setType(SessionType.VIDEO)
    .build()

// Use the previously generated token
CometChatCalls.joinSession(generatedToken, sessionSettings, callViewContainer, 
    object : CometChatCalls.CallbackListener<CallSession>() {
        override fun onSuccess(callSession: CallSession) {
            Log.d(TAG, "Joined session successfully")
        }

        override fun onError(e: CometChatException) {
            Log.e(TAG, "Failed: ${e.message}")
        }
    }
)
ParameterTypeDescription
callTokenGenerateTokenPreviously generated token object
sessionSettingsSessionSettingsConfiguration for the session
callViewContainerRelativeLayoutContainer view for the call UI
listenerCallbackListenerCallback for success/error handling
Complete Example
val sessionId = "SESSION_ID"
val callViewContainer = findViewById<RelativeLayout>(R.id.call_view_container)

// Step 1: Generate token
CometChatCalls.generateToken(sessionId, object : CometChatCalls.CallbackListener<GenerateToken>() {
    override fun onSuccess(token: GenerateToken) {
        // Step 2: Join with token
        val sessionSettings = CometChatCalls.SessionSettingsBuilder()
            .setDisplayName("John Doe")
            .setType(SessionType.VIDEO)
            .build()

        CometChatCalls.joinSession(token, sessionSettings, callViewContainer, 
            object : CometChatCalls.CallbackListener<CallSession>() {
                override fun onSuccess(callSession: CallSession) {
                    Log.d(TAG, "Joined session successfully")
                }

                override fun onError(e: CometChatException) {
                    Log.e(TAG, "Failed to join: ${e.message}")
                }
            }
        )
    }

    override fun onError(e: CometChatException) {
        Log.e(TAG, "Token generation failed: ${e.message}")
    }
})

Error Handling

Common errors when joining a session:
Error CodeDescription
ERROR_COMETCHAT_CALLS_SDK_INITSDK not initialized - call init() first
ERROR_AUTH_TOKENUser not logged in or auth token invalid
ERROR_CALL_SESSION_IDSession ID is null or empty
ERROR_CALL_TOKENInvalid or missing call token
ERROR_CALLING_VIEW_REF_NULLContainer view is null
ERROR_JSON_EXCEPTIONInvalid session settings or response parsing error