- Alex initiates the call to Bob using the
initiateCall()method. - 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 asrejected.
- In the meantime, Alex has the option to cancel the call he initiated to Bob using the
rejectCall("cancelled")method passing the status ascancelled. - If Bob accepts the call from Alex, both Alex and Bob need to call the
startCall()method. Alex in theonIncomingCallReceived()method of theCallListenerand Bob in the success obtained from the call toacceptCall()method and both will be connected to each other.
Initiate Call
TheinitiateCall() method sends a call request to a user or a group.
- Swift
- Objective C
Call class. The constructor for Call class takes the following parameters:
Receive Calls
In order to receive allcall events, you must add protocol conformance CometChatCallDelegate as Shown Below :
- Swift
- Objective C
viewDidLoad() as CometChat.calldelegate = self
As mentioned in the Overview section, Once the call is initiated, there are three options that can be possible:
- The receiver of the call accepts the call.
- The receiver of the call rejects the call.
- The initiator of the call cancels the call.
Accept the incoming Call
Once you have received an incoming call from auser or in any group in onIncomingCallReceived(incomingCall:, error:), you need to accept the call using the acceptCall() method.
- Swift
- Objective C
Reject the incoming Call
You can also choose to reject the incoming call once it is received using therejectCall() method.
- Swift
- Objective C
Here the status needs to be set as
CometChatConstants.callStatus.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 aboverejectCall() method and just pass the status to the rejectCall() method as CometChatConstants.callStatus.cancelled
The possible values for the status can be one of the below:
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 thestartCall() method.
You need to call this method for two scenarios:
- After you accept an incoming call i.e. in the
onSuccess()callback of theacceptCall()method. - After the recipient accepts an outgoing call i.e. in the
onOutgoingCallAccepted()method of theCometChatCallDelegate.
- Swift
- Objective C
The current
startCall() method which takes the callView, sessionId, to load the call viewparameters directly, is deprecated and will be replaced in the future versions. It will continue to work on this version but we suggest moving to the new method as shown above using the object of theCallSettings` class as the parameter.
The
OngoingCallListener listener provides you with the below callback methods:
Settings
TheCallSettings 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 and 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:
- View - A View object in which the calling UI is loaded.
- sessionId - The unique session Id for the call/conference session.
In case you wish to achieve a completely customised UI for the Calling experience, you can do so by embedding default UI buttons to the screen as per your requirement and then use the below methods to achieve different functionalities for the embedded buttons.
For the use case where you wish to align your own custom buttons and not use the default layout provided by CometChat, you can embed the buttons in your layout and use the below methods to perform the corresponding operations:
Switch Camera
You can callswitchCamera() Method to toggle between camera sources.
- Swift
Mute Audio
You can callmuteAudio() Method to mute your Audio Stream to the end-user.
- Swift
true the Audio Stream is muted and if set tofalse Audio Stream is transmitted.
Pause Video
You can callpauseVideo() Method to pause Video Stream to the end-user.
- Swift
true the Video Stream is muted and if set tofalse Video Stream is transmitted.
Set Audio Mode
You can callsetAudioMode() to set the output of the audio stream.
- Swift
- SPEAKER
- EARPIECE
- BLUETOOTH
- HEADPHONES
End Call
End Call is handled internally by CometChat when using the default UI provided. Once the user presses the end call button, CometChat internally triggers the action to end the call.- Swift
Get list of available audio modes
This method will return the list of available audio modes. Based on the list received, you can set the audio mode for the ongoing call using thesetAudioMode() method.
- Swift
- mode - The mode can be either one of the below values:
- SPEAKER
- EARPIECE
- BLUETOOTH
- HEADPHONES
- isSelected - This is a boolean value that indicates if the audio mode is the active mode.
Active Call
CometChat provides a method to get the details of the call that is currently active. TheCometChat.getActiveCall() will return an object of the Call containing the details of the ongoing call. If there is no ongoing call this method will return nil.
- Swift
Call Participant Count
In order to get the number of participants in any call, you can use thegetCallParticipantCount() method. This method takes the session id of the call and returns the number of participants that are active in the call.
- Swift