Skip to main content
Quick Reference for AI Agents & Developers
  • Auth token: Obtain via CometChat REST API (no Chat SDK required)
  • Generate call token: CometChatCalls.generateToken(authToken:sessionID:onSuccess:onError:)
  • Start session: CometChatCalls.startSession(callToken:callSettings:onSuccess:onError:)
  • Use case: Apps needing calling without full chat infrastructure
  • Related: Calling Setup · Call Session · Calling Overview

Overview

This section demonstrates how to implement calling functionality using only the CometChat Calls SDK, without requiring the Chat SDK. This is ideal for applications that need video/audio calling capabilities without the full chat infrastructure.
Before you begin, ensure you have completed the Calls SDK setup.

User Authentication

To start a call session, you need a user auth token. Since this implementation doesn’t use the Chat SDK, you’ll need to obtain the auth token via the CometChat REST API.
To understand user authentication in CometChat, see the User Auth documentation.

Option 1: Create Auth Token (REST API)

Creates a new auth token for a user. Endpoint:
POST https://{appid}.api-{region}.cometchat.io/v3/users/{uid}/auth_tokens
Request Headers:
PropertyTypeValue
apiKeyStringYOUR_API_KEY
Content-TypeStringapplication/json
Success Response:
PropertyTypeDescription
data.uidStringUser’s unique identifier
data.authTokenStringThe auth token for API calls
data.createdAtDoubleUnix timestamp when created

Option 2: Get Auth Token (REST API)

Retrieves an existing auth token for a user. Endpoint:
GET https://{appid}.api-{region}.cometchat.io/v3/users/{uid}/auth_tokens
Request Headers:
PropertyTypeValue
apiKeyStringYOUR_API_KEY

Option 3: Dashboard (Testing/POC)

For testing or POC purposes:
  1. Go to CometChat Dashboard
  2. Navigate to Users & Groups → Users
  3. Select a user
  4. Click + Create Auth Token
  5. Copy the generated token
Store the auth token securely in your application for use when generating call tokens.

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. Use the generateToken() method to create a call token:
var callToken: GenerateToken?

let sessionId = "UNIQUE_SESSION_ID" // Generate a unique session ID
let userAuthToken = "USER_AUTH_TOKEN" // Obtained from REST API

CometChatCalls.generateToken(authToken: userAuthToken as NSString, sessionID: sessionId) { token in
    self.callToken = token
} onError: { error in
    print("Token generation failed: \(String(describing: error?.errorDescription))")
}
Request Parameters:
PropertyTypeValue
authTokenNSString”user_auth_token_from_rest_api”
sessionIDNSString”unique_session_id_123”
Success Response:
PropertyTypeValue
tokenString”eyJhbGciOiJIUzI1NiIsInR5cCI6…”
Error Response (CometChatCallException):
PropertyTypeDescription
errorCodeStringError code identifier
errorDescriptionStringError description message

Start Call Session

Use the startSession() method to join a call session. This method requires a call token and a CallSettings object.
guard let callToken = self.callToken else { return }

let callSettings = CometChatCalls.CallSettingsBuilder
    .setDefaultLayout(true)
    .setIsAudioOnly(false)
    .setDelegate(self)
    .build()

CometChatCalls.startSession(callToken: callToken, callSetting: callSettings, view: callView) { success in
    print("Call session started successfully")
} onError: { error in
    print("Start session failed: \(String(describing: error?.errorDescription))")
}
Request Parameters:
PropertyTypeValue
callTokenString”eyJhbGciOiJIUzI1NiIsInR5cCI6…“
callSettingCallSettingsConfigured settings object
viewUIViewView to render call UI
Success Response:
PropertyTypeValue
successString/BoolSuccess confirmation
Error Response (CometChatCallException):
PropertyTypeDescription
errorCodeStringError code identifier
errorDescriptionStringError description message

Call Settings Builder

Configure the call experience using the following CallSettingsBuilder methods:
PropertyTypeDefaultDescription
defaultLayoutBooltrueEnable default call UI
isAudioOnlyBoolfalseAudio-only or audio+video
isSingleModeBoolfalseSingle participant mode
showSwitchToVideoBoolfalseShow switch to video button
enableVideoTileClickBooltrueEnable video tile clicks
enableDraggableTileBooltrueEnable draggable tiles
endCallButtonDisableBoolfalseHide end call button
showRecordingButtonBoolfalseShow recording button
switchCameraDisableBoolfalseHide switch camera button
muteAudioDisableBoolfalseHide mute audio button
pauseVideoDisableBoolfalseHide pause video button
audioModeDisableBoolfalseHide audio mode button
startAudioMutedBoolfalseStart with mic muted
startVideoMutedBoolfalseStart with camera off
modeDisplayModes.default.default/.single/.spotlight
avatarModeAvatarMode.circle.circle/.square/.fullscreen
defaultAudioModeAudioModeSPEAKERSPEAKER/EARPIECE/BLUETOOTH
idleTimeoutPeriodInt180Idle timeout in seconds
delegateCallsEventsDelegatenilEvent delegate

Call Listeners

The CallsEventsDelegate protocol provides real-time callbacks for call session events.
extension ViewController: CallsEventsDelegate {
    
    func onCallEnded() {
        // Call ended, close the calling screen
    }
    
    func onSessionTimeout() {
        // Session timed out due to inactivity
    }
    
    func onCallEndButtonPressed() {
        // User pressed end call button
        CometChatCalls.endSession()
        // Close the calling screen
    }
    
    func onUserJoined(rtcUser: RTCUser) {
        // A participant joined the call
    }
    
    func onUserLeft(rtcUser: RTCUser) {
        // A participant left the call
    }
    
    func onUserListChanged(rtcUsers: [RTCUser]) {
        // Participant list updated
    }
    
    func onAudioModeChanged(mode: [AudioMode]) {
        // Available audio devices changed
    }
    
    func onCallSwitchedToVideo(callSwitchedInfo: CallSwitchRequestInfo) {
        // Call upgraded from audio to video
    }
    
    func onUserMuted(rtcMutedUser: RTCMutedUser) {
        // A participant's mute state changed
    }
    
    func onRecordingToggled(recordingInfo: RTCRecordingInfo) {
        // Recording started or stopped
    }
}

onCallEnded

Invoked when the call session terminates for a 1:1 call. Both participants receive this callback. Payload: None Action: Close the calling screen

onSessionTimeout

Invoked when the call is auto-terminated due to inactivity (default: 180 seconds). v4.1.1+ Payload: None

onCallEndButtonPressed

Invoked when the local user taps the end call button. Payload: None Action: Call CometChatCalls.endSession() and close screen

onUserJoined

Invoked when a remote participant joins the call. Payload (RTCUser):
PropertyTypeDescription
rtcUserRTCUserUser object containing participant details

onUserLeft

Invoked when a remote participant leaves the call. Payload (RTCUser):
PropertyTypeDescription
rtcUserRTCUserUser object containing participant details

onUserListChanged

Invoked whenever the participant list changes. Payload:
PropertyTypeDescription
rtcUsers[RTCUser]Array of RTCUser objects

onAudioModeChanged

Invoked when available audio devices change. Payload:
PropertyTypeDescription
mode[AudioMode]Array of available modes: SPEAKER, EARPIECE, BLUETOOTH, HEADPHONES

onCallSwitchedToVideo

Invoked when an audio call is upgraded to video. Payload (CallSwitchRequestInfo):
PropertyTypeDescription
callSwitchedInfoCallSwitchRequestInfoCall switch request information

onUserMuted

Invoked when a participant’s mute state changes. Payload (RTCMutedUser):
PropertyTypeDescription
rtcMutedUserRTCMutedUserMuted user information

onRecordingToggled

Invoked when call recording starts or stops. Payload (RTCRecordingInfo):
PropertyTypeDescription
recordingInfoRTCRecordingInfoRecording state information

End Call Session

To end the call session and release all media resources, call CometChatCalls.endSession() in the onCallEndButtonPressed() callback.
func onCallEndButtonPressed() {
    CometChatCalls.endSession()
    // Close the calling screen
}
When to Call endSession():
ScenarioAction
User taps end call buttonCall in onCallEndButtonPressed()
Call ended by remote userCalled automatically (onCallEnded)
Session timeoutCalled automatically (onSessionTimeout)
Resources Released:
ResourceDescription
CameraVideo capture stopped
MicrophoneAudio capture stopped
NetworkWebRTC connection closed
UICall view can be dismissed

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.
CometChatCalls.switchCamera()

Mute Audio

Controls the local audio stream transmission.
// Mute audio
CometChatCalls.audioMuted(true)

// Unmute audio
CometChatCalls.audioMuted(false)

Pause Video

Controls the local video stream transmission.
// Pause video
CometChatCalls.videoPaused(true)

// Resume video
CometChatCalls.videoPaused(false)

Set Audio Mode

Routes the audio output to a specific device.
CometChatCalls.setAudioMode(AudioMode(mode: "SPEAKER"))
Available Modes:
ModeDescription
SPEAKERPhone speaker
EARPIECEPhone earpiece
BLUETOOTHBluetooth device
HEADPHONESWired headphones

Enter PIP Mode

Enters Picture-in-Picture mode.
CometChatCalls.enterPIPMode()

Exit PIP Mode

Exits Picture-in-Picture mode.
CometChatCalls.exitPIPMode()

Switch To Video Call

Upgrades an ongoing audio call to a video call.
CometChatCalls.switchToVideoCall()

Start Recording

Starts recording the call session.
CometChatCalls.startRecording()

Stop Recording

Stops an ongoing call recording.
CometChatCalls.stopRecording()

End Session

Terminates the current call session and releases all media resources.
CometChatCalls.endSession()