Skip to main content
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.
{
  "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"
  }
}

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.
// 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)
If you are already using a navigation controller, you can use the pushViewController function instead of presenting the view controller.

Actions

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:
let cometChatOngoingCall = CometChatOngoingCall()
.setOnCallEnded { call in
  // Perform your action
}

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.

1. CallSettingsBuilder

The CallSettingsBuilder 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.
MethodsDescriptionCode
setAudioModeButtonDisableDisable the audio mode button.setAudioModeButtonDisable(Bool)
setAvatarModeSet the avatar mode.setAvatarMode("")
setDefaultAudioModeSet the default audio mode.setDefaultAudioMode("")
setDefaultLayoutSet the default layout.setDefaultLayout(Bool)
setDelegateSet the calls events delegate.setDelegate(CallsEventsDelegate)
setEnableDraggableVideoTileEnable draggable video tile.setEnableDraggableVideoTile(Bool)
setEnableVideoTileClickEnable click actions on video tile.setEnableVideoTileClick(Bool)
setEndCallButtonDisableDisable the end call button.setEndCallButtonDisable(Bool)
setIsAudioOnlySet the call as audio only.setIsAudioOnly(Bool)
setIsSingleModeSet the call as single mode.setIsSingleMode(Bool)
setModeSet the mode.setMode("NSString")
setMuteAudioButtonDisableDisable the mute audio button.setMuteAudioButtonDisable(Bool)
setPauseVideoButtonDisableDisable the pause video button.setPauseVideoButtonDisable(Bool)
setShowRecordingButtonShow or hide the recording button.setShowRecordingButton(Bool)
setShowSwitchToVideoCallShow or hide the switch to video call button.setShowSwitchToVideoCall(Bool)
setStartAudioMutedStart with audio muted.setStartAudioMuted(Bool)
setStartRecordingOnCallStartStart recording when the call starts.setStartRecordingOnCallStart(Bool)
setStartVideoMutedStart with video muted.setStartVideoMuted(Bool)
setSwitchCameraButtonDisableDisable the switch camera button.setSwitchCameraButtonDisable(Bool)
setVideoContainerSet the video container.setVideoContainer(NSMutableDictionary)
setVideoSettingsSet the video settings.setVideoSettings(NSMutableDictionary)

Example

In the example below, we are applying a filter to the calls:
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)
Ensure to include an NSMicrophoneUsageDescription key with a descriptive string value in the app’s Info.plist.

Events

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.
EventDescription
onCallEndedTriggers when the ongoing or outgoing call ends.
// 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
    }
}
Emitting Call Events
// Emit this when logged in user ends a call
CometChatCallEvents.emitOnCallEnded(call: Call)
public override func viewWillDisappear(_ animated: Bool) {
      // Unsubscribe from the listener
      CometChatCallEvents.removeListener("LISTENER_ID_USED_FOR_ADDING_THIS_LISTENER")
}

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.
let cometChatOngoingCall = CometChatOngoingCall()
.set(sessionId: "Your Session ID")
.set(callWorkFlow: .defaultCalling)

cometChatOngoingCall.modalPresentationStyle = .fullScreen
self.present(cometChatOngoingCall, animated: true)
If you are already using a navigation controller, you can use the pushViewController function instead of presenting the view controller.
PropertyDescriptionCode
CallWorkFlowSets the call type to default or direct.CallWorkFlow
Session IdSets 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.