CometChat Pro Documentation

You'll find comprehensive guides and documentation to help you start working with CometChat as quickly as possible. Let's jump right in!

Calling Overview


For example, Let us assume Alex to be the call initiator and Bob is the receiver.

  1. Alex initiates the call to Bob using the initiateCall() method.
  2. Bob now has two choices:
    -> Accept the call from Alex using the acceptCall() method.
    -> Reject the call from Alex using the rejectCall("rejected") method passing the status as rejected.
  3. In the meantime, Alex has the option to cancel the call he initiated to Bob using the
    rejectCall("cancelled") method passing the status as cancelled.
  4. If Bob accepts the call from Alex, both Alex and Bob need to call the startCall() method. Alex in the onIncomingCallReceived() method of the CallListener and Bob in the success obtained from the call to acceptCall() method and both will be connected to each other.

For advanced use cases, refer to the Calling Workflows section.

Initiate Call

The initiateCall() method sends a call request to a user or a group.

let receiverID = "UID"
let receiverType:CometChat.receiverType = .user
let callType: CometChat.callType = .audio OR .video

let newCall = Call(receiverId: receiverID, callType: callType, receiverType: receiverType);

CometChat.initiateCall(call: newCall, onSuccess: { (ongoing_call) in

  print("Call initiated successfully " + ongoing_call!.stringValue());

}) { (error) in

  print("Call initialization failed with error:  " + error!.errorDescription);

NSString *receiverID = @"UID";

Call *newCall = [[Call alloc]initWithReceiverId:receiverID callType:CallTypeVideo receiverType:ReceiverTypeUser];

[CometChat initiateCallWithCall:newCall onSuccess:^(Call * ongoing_call) {
    NSLog(@"Call initiated successfully. %@",[ongoing_call stringValue]);
} onError:^(CometChatException * error) {
    NSLog(@"Call initialization failed with error: %@",[error ErrorDescription]);

This method takes an object of the Call class. The constructor for Call class takes the following parameters:



The UID or GUID of the recipient


The type of the receiver viz.

  • user
  • group


The type of the receiver viz.

  • audio
  • video

Receive Calls

In order to receive all call events, you must add protocol conformance CometChatCallDelegate as Shown Below :

extension ViewController: CometChatCallDelegate {

  func onIncomingCallReceived(incomingCall: Call ? , error : CometChatException ? ) {
    print(" Incoming call " + incomingCall!.stringValue());

  func onOutgoingCallAccepted(acceptedCall: Call ? , error : CometChatException ? ) {
    print("Outgoing call " + acceptedCall!.stringValue());

  func onOutgoingCallRejected(rejectedCall: Call ? , error : CometChatException ? ) {
    print("Rejected call " + rejectedCall!.stringValue());
  func onIncomingCallCanceled(canceledCall: Call ? , error : CometChatException ? ) {
    print("Cancelled call " + canceledCall!.stringValue());
@interface ViewController ()<CometChatCallDelegate>


@implementation ViewController

- (void)viewDidLoad {
    [super viewDidLoad];
    [CometChat setCalldelegate:self];

- (void)onIncomingCallCanceledWithCanceledCall:(Call * _Nullable)canceledCall error:(CometChatException * _Nullable)error {
    NSLog(@"Incoming call cancelled %@",[canceledCall stringValue]);

- (void)onIncomingCallReceivedWithIncomingCall:(Call * _Nullable)incomingCall error:(CometChatException * _Nullable)error {
    NSLog(@"Incoming call %@",[incomingCall stringValue]);

- (void)onOutgoingCallAcceptedWithAcceptedCall:(Call * _Nullable)acceptedCall error:(CometChatException * _Nullable)error {
    NSLog(@"Outgoing call accepted %@",[acceptedCall stringValue]);

- (void)onOutgoingCallRejectedWithRejectedCall:(Call * _Nullable)rejectedCall error:(CometChatException * _Nullable)error {
    NSLog(@"Outgoing call rejected %@",[rejectedCall stringValue]);


Do not forget to set your view controller as a CometChat delegate probably in viewDidLoad() as CometChat.calldelegate = self

Accept Call

Once you have received an incoming call from a user or in any group in onIncomingCallReceived(incomingCall:, error:), you need to accept the call using the acceptCall() method.

CometChat.acceptCall(sessionID: incomingCall!.sessionID, onSuccess: { (ongoing_call) in
  print("Accepted Call. " + call!.stringValue());

}) { (error) in

  print("Call accepting failed with error:  " + error!.errorDescription);
[CometChat acceptCallWithSessionID:incomingCall.sessionID onSuccess:^(Call * ongoing_call) {
    NSLog(@"Accepted call. %@",[ongoing_call stringValue]);
} onError:^(CometChatException * error) {
    NSLog(@"Call accepting failed with error: %@",[error ErrorDescription]);

Start the Call

Once the call request is sent and the receiver has accepted the call, both the initiator and the receiver need to call the startCall() method.

You need to call this method for two scenarios:

  1. After you accept an incoming call i.e. in the onSuccess() callback of the acceptCall() method.
  2. After the recipient accepts an outgoing call i.e. in the onOutgoingCallAccepted() method of the CometChatCallDelegate.
func onIncomingCallReceived(incomingCall: Call?, error : CometChatException?) {

  	CometChat.acceptCall(sessionID: incomingCall!.sessionId, onSuccess: { (ongoing_call) in

    let callView = // a UIView you want to show the calling view in

    CometChat.startCall(sessionID: (ongoing_call.sessionID), inView: callView, userJoined: { (joined_user) in

        print("Joined User: " + joined_user.stringValue())

    }, userLeft: { (left_user) in

        print("Left User: " + left_user.stringValue())

    }, onError: { (error) in

        print("Connection error with error: " + error.errorDescription);

    }, callEnded: { (ended_call) in

        print("Call ended successfully. " + ended_call!.stringValue());
  }) { (error) in

    print("Accepting call failed with error:" + error.ErrorDescription);
- (void)onIncomingCallReceivedWithIncomingCall:(Call * _Nullable)incomingCall error:(CometChatException * _Nullable)error {
    [CometChat acceptCallWithSessionID:incomingCall.sessionID onSuccess:^(Call * ongoing_call) {
         // Call accepted successfully
        UIView *callView = [UIView new]; //// a UIView you want to show the calling view in
        [CometChat startCallWithSessionID:ongoing_call.sessionID inView:callView userJoined:^(User * joined_user) {
            NSLog(@"Joined user: %@",[joined_user stringValue]);
        } userLeft:^(User * left_user) {
            NSLog(@"Left user %@",[left_user stringValue]);
        } onError:^(CometChatException * error) {
            NSLog(@"Error: %@",[error ErrorDescription]);
        } callEnded:^(Call * call_ended) {
            NSLog(@"Ended call: %@",[call_ended stringValue]);
    } onError:^(CometChatException * error) {
        // Error
        NSLog(@" error %@",[error ErrorDescription]);

End Call

End Call is handled internally by CometChat using the default UI provided. Once the user presses the end call button, CometChat internally triggers the action to end the call.

Reject Call

You can also choose to reject the incoming call once it is received using the rejectCall() method.

let status: CometChatConstants.callStatus = .rejected;

CometChat.rejectCall(sessionID: (incomingCall?.sessionID)!, status: status, onSuccess: { (rejeceted_call) in
  print("Call rejected successfully. " + rejeceted_call!.stringValue());
}) { (error) in

  print("Call rejection failed with error:  " + error!.errorDescription);
[CometChat rejectCallWithSessionID:incomingCall.sessionID status:callStatusRejected onSuccess:^(Call * rejeceted_call) {
    // Success
    NSLog("Call rejected successfully %@ " , [rejeceted_call stringValue]);
} onError:^(CometChatException * error) {
    // Error
    NSLog("Call rejection failed with exception:  %@" + [error ErrorDescription]);


Reason for rejection of the call

  • initiated
  • ongoing
  • unanswered
  • rejected
  • busy
  • canceled
  • ended

The possible values for the status can be one of the below:

Enum available


The receiver rejects the call as it is received without accepting the call



The initiator ends the call without the receiver accepting the call



The receiver rejects the call, as he/she is busy on another call



Call is cancelled by the initiator:

Call rejected by the receiver:

Call to a user that is busy on another call :

What's Next



Suggested Edits are limited on API Reference Pages

You can only suggest edits to Markdown body content, but not to the API spec.