Skip to main content
This section will provide information on how a complete calling workflow can be set up using CometChat. We’ve built the complete workflow to help your users make calls, receive calls as well as accept/reject calls. 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:
    1. Accept the call from Alex using the acceptCall() method.
    2. Reject the call from Alex using the rejectCall() 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() 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 onOutgoingCallAccepted() method of the CallListener and Bob in the success obtained from the **acceptCall()** method and both will be connected to each other.

Initiate Call

The initiateCall() method sends a call request to a user or a group.
This method takes an object of the Call class. The constructor for Call class takes the following parameters: On successful initialization, a Call object is returned with the details of the call including a unique session ID for the call.

Receive Calls

Wherever you wish to receive the call events in, you need to register the CallListener listener using the addCallListener() method.
We recommend you remove the listener once the activity or fragment is not in use.
As mentioned in the Overview section, Once the call is initiated, there are three options that can be possible:
  1. The receiver of the call accepts the call.
  2. The receiver of the call rejects the call.
  3. The initiator of the call cancels the call.
Please find below how these three scenarios can be implemented:

Accept the Incoming Call

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

Reject the Incoming Call

To reject the incoming call once it is received using the rejectCall() method.
Here the status needs to be set as CometChat.CALL_STATUS.REJECTED as the call is being rejected by the receiver of the call.

Cancel the Outgoing Call

In the case where the initiator wishes to cancel the call, use the same above rejectCall() method and just pass the status to the rejectCall() method as CometChat.CALL_STATUS.CANCELLED

Start a 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() callback of the CallListener listener.
The OngoingCallListener listener provides you with the below callback methods:

Settings

The CallSettings class is the most important class when it comes to the implementation of the Calling feature. This is the class that allows you to customize the overall calling experience. The properties for the call/conference can be set using the CallSettingsBuilder class. This will eventually give you an object of the CallSettings class which you can pass to the startCall() method to start the call. The mandatory parameters that are required to be present for any call/conference to work are:
  1. sessionId - The unique session Id for the call/conference session.
The options available for customization of calls are:

Active Call

CometChat provides a method to get the details of the call that is currently active. The CometChat.getActiveCall() will return an object of the Call class containing the details of the ongoing call. If there is no ongoing call this method will return null.
The getActiveCall() method will only return the details of the active call for the ongoing session in which the call has been started. If the app is restarted, the data will be lost.

Call Participant Count

In order to get the number of participants in any call, you can use the getCallParticipantCount() method. This method takes the session id for the call and returns the number of participants that are active in the call.