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

Create a container view where the call interface will be rendered. This can be done in your storyboard or programmatically:
// Programmatically
let callViewContainer = UIView()
callViewContainer.translatesAutoresizingMaskIntoConstraints = false
view.addSubview(callViewContainer)

NSLayoutConstraint.activate([
    callViewContainer.topAnchor.constraint(equalTo: view.topAnchor),
    callViewContainer.bottomAnchor.constraint(equalTo: view.bottomAnchor),
    callViewContainer.leadingAnchor.constraint(equalTo: view.leadingAnchor),
    callViewContainer.trailingAnchor.constraint(equalTo: view.trailingAnchor)
])
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.
let sessionId = "SESSION_ID"

let sessionSettings = CometChatCalls.sessionSettingsBuilder
    .setDisplayName("John Doe")
    .setType(.video)
    .build()

CometChatCalls.joinSession(
    sessionID: sessionId,
    callSetting: sessionSettings,
    container: callViewContainer,
    onSuccess: { message in
        print("Joined session successfully")
    },
    onError: { error in
        print("Failed: \(error?.errorDescription ?? "")")
    }
)
ParameterTypeDescription
sessionIDStringUnique identifier for the call session
callSettingSessionSettingsConfiguration for the session
containerUIViewContainer view for the call UI
onSuccessClosureClosure called on successful join
onErrorClosureClosure called on failure
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.
let sessionId = "SESSION_ID"

CometChatCalls.generateToken(sessionID: sessionId, onSuccess: { token in
    print("Token generated: \(token ?? "")")
    // Store or use the token
}, onError: { error in
    print("Token generation failed: \(error?.errorDescription ?? "")")
})
ParameterTypeDescription
sessionIDStringUnique identifier for the call session
onSuccessClosureClosure returning the generated token string
onErrorClosureClosure called on failure
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.
let sessionSettings = CometChatCalls.sessionSettingsBuilder
    .setDisplayName("John Doe")
    .setType(.video)
    .build()

// Use the previously generated token
CometChatCalls.joinSession(
    callToken: generatedToken,
    callSetting: sessionSettings,
    container: callViewContainer,
    onSuccess: { message in
        print("Joined session successfully")
    },
    onError: { error in
        print("Failed: \(error?.errorDescription ?? "")")
    }
)
ParameterTypeDescription
callTokenStringPreviously generated token string
callSettingSessionSettingsConfiguration for the session
containerUIViewContainer view for the call UI
onSuccessClosureClosure called on successful join
onErrorClosureClosure called on failure
Complete Example
let sessionId = "SESSION_ID"

// Step 1: Generate token
CometChatCalls.generateToken(sessionID: sessionId, onSuccess: { [weak self] token in
    guard let self = self, let token = token else { return }
    
    // Step 2: Join with token
    let sessionSettings = CometChatCalls.sessionSettingsBuilder
        .setDisplayName("John Doe")
        .setType(.video)
        .build()

    CometChatCalls.joinSession(
        callToken: token,
        callSetting: sessionSettings,
        container: self.callViewContainer,
        onSuccess: { message in
            print("Joined session successfully")
        },
        onError: { error in
            print("Failed to join: \(error?.errorDescription ?? "")")
        }
    )
}, onError: { error in
    print("Token generation failed: \(error?.errorDescription ?? "")")
})

Error Handling

Common errors when joining a session:
Error CodeDescription
INIT ERRORSDK not initialized - call init() first
AUTH TOKEN ERRORUser not logged in or auth token invalid
SESSION ID ERRORSession ID is null or empty
API ERRORInvalid call token or API error