> ## Documentation Index
> Fetch the complete documentation index at: https://cometchat-22654f5b-docs-ios-ui-kit-sdk-fixes.mintlify.site/llms.txt
> Use this file to discover all available pages before exploring further.

# Standalone Calling

> Guide to implementing voice and video calling using only the CometChat Calls SDK without the Chat SDK.

<Info>
  **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](/sdk/ios/calling-setup) · [Call Session](/sdk/ios/direct-calling) · [Calling Overview](/sdk/ios/calling-overview)
</Info>

## 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.

<Note>
  Before you begin, ensure you have completed the [Calls SDK setup](/sdk/ios/calling-setup).
</Note>

## 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.

<Note>
  To understand user authentication in CometChat, see the [User Auth](/fundamentals/user-auth) documentation.
</Note>

### 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:**

| Property     | Type   | Value            |
| ------------ | ------ | ---------------- |
| apiKey       | String | YOUR\_API\_KEY   |
| Content-Type | String | application/json |

**Success Response:**

| Property       | Type   | Description                  |
| -------------- | ------ | ---------------------------- |
| data.uid       | String | User's unique identifier     |
| data.authToken | String | The auth token for API calls |
| data.createdAt | Double | Unix 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:**

| Property | Type   | Value          |
| -------- | ------ | -------------- |
| apiKey   | String | YOUR\_API\_KEY |

### Option 3: Dashboard (Testing/POC)

For testing or POC purposes:

1. Go to [CometChat Dashboard](https://app.cometchat.com)
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:

<Tabs>
  <Tab title="Swift">
    ```swift theme={null}
    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))")
    }
    ```
  </Tab>
</Tabs>

**Request Parameters:**

| Property  | Type     | Value                                |
| --------- | -------- | ------------------------------------ |
| authToken | NSString | "user\_auth\_token\_from\_rest\_api" |
| sessionID | NSString | "unique\_session\_id\_123"           |

**Success Response:**

| Property | Type   | Value                             |
| -------- | ------ | --------------------------------- |
| token    | String | "eyJhbGciOiJIUzI1NiIsInR5cCI6..." |

**Error Response (CometChatCallException):**

| Property         | Type   | Description               |
| ---------------- | ------ | ------------------------- |
| errorCode        | String | Error code identifier     |
| errorDescription | String | Error description message |

## Start Call Session

Use the `startSession()` method to join a call session. This method requires a call token and a `CallSettings` object.

<Tabs>
  <Tab title="Swift">
    ```swift theme={null}
    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))")
    }
    ```
  </Tab>
</Tabs>

**Request Parameters:**

| Property    | Type         | Value                             |
| ----------- | ------------ | --------------------------------- |
| callToken   | String       | "eyJhbGciOiJIUzI1NiIsInR5cCI6..." |
| callSetting | CallSettings | Configured settings object        |
| view        | UIView       | View to render call UI            |

**Success Response:**

| Property | Type        | Value                |
| -------- | ----------- | -------------------- |
| success  | String/Bool | Success confirmation |

**Error Response (CometChatCallException):**

| Property         | Type   | Description               |
| ---------------- | ------ | ------------------------- |
| errorCode        | String | Error code identifier     |
| errorDescription | String | Error description message |

### Call Settings Builder

Configure the call experience using the following `CallSettingsBuilder` methods:

| Property             | Type                | Default  | Description                 |
| -------------------- | ------------------- | -------- | --------------------------- |
| defaultLayout        | Bool                | true     | Enable default call UI      |
| isAudioOnly          | Bool                | false    | Audio-only or audio+video   |
| isSingleMode         | Bool                | false    | Single participant mode     |
| showSwitchToVideo    | Bool                | false    | Show switch to video button |
| enableVideoTileClick | Bool                | true     | Enable video tile clicks    |
| enableDraggableTile  | Bool                | true     | Enable draggable tiles      |
| endCallButtonDisable | Bool                | false    | Hide end call button        |
| showRecordingButton  | Bool                | false    | Show recording button       |
| switchCameraDisable  | Bool                | false    | Hide switch camera button   |
| muteAudioDisable     | Bool                | false    | Hide mute audio button      |
| pauseVideoDisable    | Bool                | false    | Hide pause video button     |
| audioModeDisable     | Bool                | false    | Hide audio mode button      |
| startAudioMuted      | Bool                | false    | Start with mic muted        |
| startVideoMuted      | Bool                | false    | Start with camera off       |
| mode                 | DisplayModes        | .default | .default/.single/.spotlight |
| avatarMode           | AvatarMode          | .circle  | .circle/.square/.fullscreen |
| defaultAudioMode     | AudioMode           | SPEAKER  | SPEAKER/EARPIECE/BLUETOOTH  |
| idleTimeoutPeriod    | Int                 | 180      | Idle timeout in seconds     |
| delegate             | CallsEventsDelegate | nil      | Event delegate              |

## Call Listeners

The `CallsEventsDelegate` protocol provides real-time callbacks for call session events.

<Tabs>
  <Tab title="Swift">
    ```swift theme={null}
    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
        }
    }
    ```
  </Tab>
</Tabs>

### 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):**

| Property | Type    | Description                                |
| -------- | ------- | ------------------------------------------ |
| rtcUser  | RTCUser | User object containing participant details |

### onUserLeft

Invoked when a remote participant leaves the call.

**Payload (RTCUser):**

| Property | Type    | Description                                |
| -------- | ------- | ------------------------------------------ |
| rtcUser  | RTCUser | User object containing participant details |

### onUserListChanged

Invoked whenever the participant list changes.

**Payload:**

| Property | Type       | Description              |
| -------- | ---------- | ------------------------ |
| rtcUsers | \[RTCUser] | Array of RTCUser objects |

### onAudioModeChanged

Invoked when available audio devices change.

**Payload:**

| Property | Type         | Description                                                        |
| -------- | ------------ | ------------------------------------------------------------------ |
| mode     | \[AudioMode] | Array of available modes: SPEAKER, EARPIECE, BLUETOOTH, HEADPHONES |

### onCallSwitchedToVideo

Invoked when an audio call is upgraded to video.

**Payload (CallSwitchRequestInfo):**

| Property         | Type                  | Description                     |
| ---------------- | --------------------- | ------------------------------- |
| callSwitchedInfo | CallSwitchRequestInfo | Call switch request information |

### onUserMuted

Invoked when a participant's mute state changes.

**Payload (RTCMutedUser):**

| Property     | Type         | Description            |
| ------------ | ------------ | ---------------------- |
| rtcMutedUser | RTCMutedUser | Muted user information |

### onRecordingToggled

Invoked when call recording starts or stops.

**Payload (RTCRecordingInfo):**

| Property      | Type             | Description                 |
| ------------- | ---------------- | --------------------------- |
| recordingInfo | RTCRecordingInfo | Recording state information |

## End Call Session

To end the call session and release all media resources, call `CometChatCalls.endSession()` in the `onCallEndButtonPressed()` callback.

<Tabs>
  <Tab title="Swift">
    ```swift theme={null}
    func onCallEndButtonPressed() {
        CometChatCalls.endSession()
        // Close the calling screen
    }
    ```
  </Tab>
</Tabs>

**When to Call endSession():**

| Scenario                  | Action                                    |
| ------------------------- | ----------------------------------------- |
| User taps end call button | Call in `onCallEndButtonPressed()`        |
| Call ended by remote user | Called automatically (`onCallEnded`)      |
| Session timeout           | Called automatically (`onSessionTimeout`) |

**Resources Released:**

| Resource   | Description                |
| ---------- | -------------------------- |
| Camera     | Video capture stopped      |
| Microphone | Audio capture stopped      |
| Network    | WebRTC connection closed   |
| UI         | Call 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.

<Note>
  These methods can only be called when a call session is active.
</Note>

### Switch Camera

Toggles between the front and rear camera during a video call.

<Tabs>
  <Tab title="Swift">
    ```swift theme={null}
    CometChatCalls.switchCamera()
    ```
  </Tab>

  <Tab title="Objective-C">
    ```objc theme={null}
    [CometChatCalls switchCamera];
    ```
  </Tab>
</Tabs>

### Mute Audio

Controls the local audio stream transmission.

<Tabs>
  <Tab title="Swift">
    ```swift theme={null}
    // Mute audio
    CometChatCalls.audioMuted(true)

    // Unmute audio
    CometChatCalls.audioMuted(false)
    ```
  </Tab>

  <Tab title="Objective-C">
    ```objc theme={null}
    // Mute audio
    [CometChatCalls audioMuted:YES];

    // Unmute audio
    [CometChatCalls audioMuted:NO];
    ```
  </Tab>
</Tabs>

### Pause Video

Controls the local video stream transmission.

<Tabs>
  <Tab title="Swift">
    ```swift theme={null}
    // Pause video
    CometChatCalls.videoPaused(true)

    // Resume video
    CometChatCalls.videoPaused(false)
    ```
  </Tab>

  <Tab title="Objective-C">
    ```objc theme={null}
    // Pause video
    [CometChatCalls videoPaused:YES];

    // Resume video
    [CometChatCalls videoPaused:NO];
    ```
  </Tab>
</Tabs>

### Set Audio Mode

Routes the audio output to a specific device.

<Tabs>
  <Tab title="Swift">
    ```swift theme={null}
    CometChatCalls.setAudioMode(AudioMode(mode: "SPEAKER"))
    ```
  </Tab>

  <Tab title="Objective-C">
    ```objc theme={null}
    [CometChatCalls setAudioModeWithMode:@"SPEAKER"];
    ```
  </Tab>
</Tabs>

**Available Modes:**

| Mode       | Description      |
| ---------- | ---------------- |
| SPEAKER    | Phone speaker    |
| EARPIECE   | Phone earpiece   |
| BLUETOOTH  | Bluetooth device |
| HEADPHONES | Wired headphones |

### Enter PIP Mode

Enters Picture-in-Picture mode.

<Tabs>
  <Tab title="Swift">
    ```swift theme={null}
    CometChatCalls.enterPIPMode()
    ```
  </Tab>

  <Tab title="Objective-C">
    ```objc theme={null}
    [CometChatCalls enterPIPMode];
    ```
  </Tab>
</Tabs>

### Exit PIP Mode

Exits Picture-in-Picture mode.

<Tabs>
  <Tab title="Swift">
    ```swift theme={null}
    CometChatCalls.exitPIPMode()
    ```
  </Tab>

  <Tab title="Objective-C">
    ```objc theme={null}
    [CometChatCalls exitPIPMode];
    ```
  </Tab>
</Tabs>

### Switch To Video Call

Upgrades an ongoing audio call to a video call.

<Tabs>
  <Tab title="Swift">
    ```swift theme={null}
    CometChatCalls.switchToVideoCall()
    ```
  </Tab>

  <Tab title="Objective-C">
    ```objc theme={null}
    [CometChatCalls switchToVideoCall];
    ```
  </Tab>
</Tabs>

### Start Recording

Starts recording the call session.

<Tabs>
  <Tab title="Swift">
    ```swift theme={null}
    CometChatCalls.startRecording()
    ```
  </Tab>

  <Tab title="Objective-C">
    ```objc theme={null}
    [CometChatCalls startRecording];
    ```
  </Tab>
</Tabs>

### Stop Recording

Stops an ongoing call recording.

<Tabs>
  <Tab title="Swift">
    ```swift theme={null}
    CometChatCalls.stopRecording()
    ```
  </Tab>

  <Tab title="Objective-C">
    ```objc theme={null}
    [CometChatCalls stopRecording];
    ```
  </Tab>
</Tabs>

### End Session

Terminates the current call session and releases all media resources.

<Tabs>
  <Tab title="Swift">
    ```swift theme={null}
    CometChatCalls.endSession()
    ```
  </Tab>

  <Tab title="Objective-C">
    ```objc theme={null}
    [CometChatCalls endSession];
    ```
  </Tab>
</Tabs>
