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

# Ongoing Call

> Display CometChat iOS UI Kit ongoing calls with video, call controls, participant management, recording, screen sharing, and callbacks.

The `CometChatOngoingCall` component provides users with a dedicated interface for managing real-time voice or video conversations. It includes features like a video display area for video calls, call controls for mic and camera management, participant information, call status indicators, and options for call recording and screen-sharing.

<Frame>
  <img src="https://mintcdn.com/cometchat-22654f5b-docs-audit-mechanical-fixes/OYyzjEKX00dVTAyy/images/bfdfe4af-ongoin_call_overview_screens-e2f70b57cc2dcbc5197e62828fccec1d.png?fit=max&auto=format&n=OYyzjEKX00dVTAyy&q=85&s=eb45ab32c27ea600922c1accfef5416d" width="4948" height="3120" data-path="images/bfdfe4af-ongoin_call_overview_screens-e2f70b57cc2dcbc5197e62828fccec1d.png" />
</Frame>

<Accordion title="AI Integration Quick Reference">
  ```json theme={null}
  {
    "component": "CometChatOngoingCall",
    "package": "CometChatUIKitSwift",
    "import": "import CometChatUIKitSwift\nimport CometChatCallsSDK",
    "description": "Displays active call interface with video, controls, and participant management",
    "inherits": "UIViewController",
    "primaryOutput": {
      "callback": "onCallEnded",
      "type": "(Call) -> Void"
    },
    "props": {
      "data": {
        "sessionID": { "type": "String", "required": true },
        "callSettingsBuilder": { "type": "CallSettingsBuilder?", "default": "nil" }
      },
      "callbacks": {
        "onCallEnded": "(Call) -> Void",
        "onError": "(CometChatException) -> Void"
      }
    },
    "events": [
      { "name": "onCallEnded", "payload": "Call", "description": "Fires when call ends" }
    ],
    "sdkListeners": [],
    "compositionExample": {
      "description": "OngoingCall is presented during an active call",
      "components": ["CometChatIncomingCall", "CometChatOutgoingCall", "CometChatOngoingCall"],
      "flow": "Call accepted → OngoingCall shown → Call ends → Returns to previous screen"
    }
  }
  ```
</Accordion>

| Field     | Value                  |
| --------- | ---------------------- |
| Component | `CometChatOngoingCall` |
| Package   | `CometChatUIKitSwift`  |
| Inherits  | `UIViewController`     |

***

## Usage

### Integration

`CometChatOngoingCall` is a custom view controller that offers versatility in its integration. It can be seamlessly launched via button clicks or any user-triggered action, enhancing the overall user experience and facilitating smoother interactions within the application.

<Tabs>
  <Tab title="Swift">
    ```swift lines theme={null}
    // The sessionID should be received from CometChat SDK when the call was initiated or received
    let sessionID = "your_session_id"

    let cometChatOngoingCall = CometChatOngoingCall()
    cometChatOngoingCall.set(sessionID: sessionID)
    cometChatOngoingCall.modalPresentationStyle = .fullScreen
    self.present(cometChatOngoingCall, animated: true)
    ```
  </Tab>
</Tabs>

<Note>
  If you are already using a navigation controller, you can use the `pushViewController` function instead of presenting the view controller.
</Note>

### Actions

[Actions](/ui-kit/ios/components-overview#actions) dictate how a component functions. They are divided into two types: Predefined and User-defined. You can override either type, allowing you to tailor the behavior of the component to fit your specific needs.

#### 1. SetOnCallEnded

The `setOnCallEnded` action is typically triggered when the call ends, carrying out default actions. You can customize or override this default behavior using the following code snippet:

<Tabs>
  <Tab title="Swift">
    ```swift lines theme={null}
    let cometChatOngoingCall = CometChatOngoingCall()
    .setOnCallEnded { call in
      // Perform your action
    }
    ```
  </Tab>
</Tabs>

***

### Filters

Filters allow you to customize the data displayed in a list within a Component. You can filter the list based on your specific criteria for a more customized experience. Filters can be applied using RequestBuilders of the Chat SDK.

You can adjust the `callSettingsBuilder` in the OnGoing Call Component to customize the call. Numerous options are available to alter the builder to meet your specific needs. For additional details on `CallSettingsBuilder`, visit [CallSettingsBuilder](/sdk/ios/direct-calling).

#### 1. CallSettingsBuilder

The [CallSettingsBuilder](/sdk/ios/direct-calling) enables you to filter and customize the call list based on available parameters. This feature allows you to create more specific and targeted queries during the call.

| Methods                          | Description                                  | Code                                      |
| -------------------------------- | -------------------------------------------- | ----------------------------------------- |
| **setAudioModeButtonDisable**    | Disable the audio mode button                | `.setAudioModeButtonDisable(Bool)`        |
| **setAvatarMode**                | Set the avatar mode                          | `.setAvatarMode("")`                      |
| **setDefaultAudioMode**          | Set the default audio mode                   | `.setDefaultAudioMode("")`                |
| **setDefaultLayout**             | Set the default layout                       | `.setDefaultLayout(Bool)`                 |
| **setDelegate**                  | Set the calls events delegate                | `.setDelegate(CallsEventsDelegate)`       |
| **setEnableDraggableVideoTile**  | Enable draggable video tile                  | `.setEnableDraggableVideoTile(Bool)`      |
| **setEnableVideoTileClick**      | Enable click actions on video tile           | `.setEnableVideoTileClick(Bool)`          |
| **setEndCallButtonDisable**      | Disable the end call button                  | `.setEndCallButtonDisable(Bool)`          |
| **setIsAudioOnly**               | Set the call as audio only                   | `.setIsAudioOnly(Bool)`                   |
| **setIsSingleMode**              | Set the call as single mode                  | `.setIsSingleMode(Bool)`                  |
| **setMode**                      | Set the mode                                 | `.setMode("NSString")`                    |
| **setMuteAudioButtonDisable**    | Disable the mute audio button                | `.setMuteAudioButtonDisable(Bool)`        |
| **setPauseVideoButtonDisable**   | Disable the pause video button               | `.setPauseVideoButtonDisable(Bool)`       |
| **setShowRecordingButton**       | Show or hide the recording button            | `.setShowRecordingButton(Bool)`           |
| **setShowSwitchToVideoCall**     | Show or hide the switch to video call button | `.setShowSwitchToVideoCall(Bool)`         |
| **setStartAudioMuted**           | Start with audio muted                       | `.setStartAudioMuted(Bool)`               |
| **setStartRecordingOnCallStart** | Start recording when the call starts         | `.setStartRecordingOnCallStart(Bool)`     |
| **setStartVideoMuted**           | Start with video muted                       | `.setStartVideoMuted(Bool)`               |
| **setSwitchCameraButtonDisable** | Disable the switch camera button             | `.setSwitchCameraButtonDisable(Bool)`     |
| **setVideoContainer**            | Set the video container                      | `.setVideoContainer(NSMutableDictionary)` |
| **setVideoSettings**             | Set the video settings                       | `.setVideoSettings(NSMutableDictionary)`  |

#### Example

In the example below, we are applying a filter to the calls:

<Tabs>
  <Tab title="Swift">
    ```swift lines theme={null}
    let callBuilder = CallSettingsBuilder()
    .setAudioModeButtonDisable(true)
    .setEndCallButtonDisable(false)

    let cometChatOngoingCall = CometChatOngoingCall()
    .set(sessionId: "Your Session ID")
    .set(callSettingsBuilder: callBuilder)

    cometChatOngoingCall.modalPresentationStyle = .fullScreen
    self.present(cometChatOngoingCall, animated: true)
    ```
  </Tab>
</Tabs>

<Warning>
  Ensure to include an `NSMicrophoneUsageDescription` key with a descriptive string value in the app's Info.plist.
</Warning>

***

### Events

[Events](/ui-kit/ios/components-overview#events) are emitted by a Component. By using events, you can extend existing functionality. Being global events, they can be applied in multiple locations and can be added or removed as needed.

| Event           | Description                                      |
| --------------- | ------------------------------------------------ |
| **onCallEnded** | Triggers when the ongoing or outgoing call ends. |

<Tabs>
  <Tab title="Add Listener">
    ```swift lines theme={null}
    // View controller from your project where you want to listen to events
    public class ViewController: UIViewController {

       public override func viewDidLoad() {
            super.viewDidLoad()

           // Subscribe to the listener for call events
            CometChatCallEvents.addListener("UNIQUE_ID", self as CometChatCallEventListener)
        }
    }

    // Listener for call events
    extension ViewController: CometChatCallEventListener {

        func onCallEnded(call: Call) {
            // Handle call ended
        }
    }
    ```

    ```swift Emitting Call Events theme={null}
    // Emit this when logged in user ends a call
    CometChatCallEvents.emitOnCallEnded(call: Call)
    ```
  </Tab>
</Tabs>

<Tabs>
  <Tab title="Remove Listener">
    ```swift lines theme={null}
    public override func viewWillDisappear(_ animated: Bool) {
          // Unsubscribe from the listener
          CometChatCallEvents.removeListener("LISTENER_ID_USED_FOR_ADDING_THIS_LISTENER")
    }
    ```
  </Tab>
</Tabs>

***

## Customization

To fit your app's design requirements, you can customize the appearance of the component. We provide exposed methods that allow you to modify the experience and behavior according to your specific needs.

### Style

Using Style, you can customize the look and feel of the component in your app. These parameters typically control elements such as the color, size, shape, and fonts used within the component.

The OngoingCall component does not have any exposed Styles.

***

### Functionality

These are small functional customizations that allow you to fine-tune the overall experience of the component. With these, you can change text, set custom icons, and toggle the visibility of UI elements.

<Tabs>
  <Tab title="Swift">
    ```swift lines theme={null}
    let cometChatOngoingCall = CometChatOngoingCall()
    .set(sessionId: "Your Session ID")
    .set(callWorkFlow: .defaultCalling)

    cometChatOngoingCall.modalPresentationStyle = .fullScreen
    self.present(cometChatOngoingCall, animated: true)
    ```
  </Tab>
</Tabs>

<Note>
  If you are already using a navigation controller, you can use the `pushViewController` function instead of presenting the view controller.
</Note>

| Property         | Description                                   | Code                      |
| ---------------- | --------------------------------------------- | ------------------------- |
| **CallWorkFlow** | Sets the call type to default or direct.      | `CallWorkFlow`            |
| **Session Id**   | Sets the session ID for CometChatOngoingCall. | `.set(sessionId: String)` |

### Advanced

For advanced-level customization, you can set custom views to the component. This lets you tailor each aspect of the component to fit your exact needs and application aesthetics. You can create and define your own views, layouts, and UI elements and then incorporate those into the component.

The `OngoingCall` component does not provide additional functionalities beyond this level of customization.

***

## Common Patterns

### Present Ongoing Call After Acceptance

Show the ongoing call screen after a call is accepted:

<Tabs>
  <Tab title="Swift">
    ```swift lines theme={null}
    func presentOngoingCall(sessionId: String) {
        let ongoingCall = CometChatOngoingCall()
        ongoingCall.set(sessionId: sessionId)
        ongoingCall.modalPresentationStyle = .fullScreen
        
        self.present(ongoingCall, animated: true)
    }
    ```
  </Tab>
</Tabs>

### Configure Call Settings for Video Call

Customize video call settings before starting:

<Tabs>
  <Tab title="Swift">
    ```swift lines theme={null}
    let callSettingsBuilder = CallSettingsBuilder()
        .setIsAudioOnly(false)
        .setDefaultAudioMode("SPEAKER")
        .setShowSwitchToVideoCall(false)
        .setShowRecordingButton(true)
        .setStartVideoMuted(false)
        .setStartAudioMuted(false)

    let ongoingCall = CometChatOngoingCall()
    ongoingCall.set(sessionId: sessionId)
    ongoingCall.set(callSettingsBuilder: callSettingsBuilder)
    ```
  </Tab>
</Tabs>

### Audio-Only Call Configuration

Set up an audio-only call with speaker mode:

<Tabs>
  <Tab title="Swift">
    ```swift lines theme={null}
    let audioCallSettings = CallSettingsBuilder()
        .setIsAudioOnly(true)
        .setDefaultAudioMode("SPEAKER")
        .setMuteAudioButtonDisable(false)
        .setEndCallButtonDisable(false)

    let ongoingCall = CometChatOngoingCall()
    ongoingCall.set(sessionId: sessionId)
    ongoingCall.set(callSettingsBuilder: audioCallSettings)
    ongoingCall.modalPresentationStyle = .fullScreen
    self.present(ongoingCall, animated: true)
    ```
  </Tab>
</Tabs>

### Listen for Call End Events

Use CometChatCallEvents to handle call end:

<Tabs>
  <Tab title="Swift">
    ```swift lines theme={null}
    // Subscribe to call events
    CometChatCallEvents.addListener("ongoing_call_listener", self as CometChatCallEventListener)

    // In CometChatCallEventListener extension
    func onCallEnded(call: Call) {
        DispatchQueue.main.async { [weak self] in
            self?.dismiss(animated: true) {
                // Show call summary
                let duration = call.duration ?? 0
                let minutes = duration / 60
                let seconds = duration % 60
                
                let alert = UIAlertController(
                    title: "Call Ended",
                    message: "Duration: \(minutes)m \(seconds)s",
                    preferredStyle: .alert
                )
                alert.addAction(UIAlertAction(title: "OK", style: .default))
                self?.present(alert, animated: true)
            }
        }
    }
    ```
  </Tab>
</Tabs>

***
