Voice Calling
Voice Calling Setup
Configure your Xcode project for outgoing calls.
In your app's
info.plist, add theNSMicrophoneUsageDescriptionkey. This is required to request microphone permission.In your app's capabilities, add the background mode capabilities
Audio, Airplay, and Picture in Picture,Voice over IP, andRemote NotificationsAdd the
Push Notificationscapability.
Configure your Android application for outgoing calls.
Add the following to your
Android Manifestfile:<uses-permission android:name="android.permission.RECORD_AUDIO"/>Request microphone permissions from within your application code:
ActivityCompat.requestPermissions( this, arrayOf(Manifest.permission.RECORD_AUDIO), MIC_PERMISSION_REQUEST_CODE // a code you set for monitoring whether or not the permission was granted )
Configure your Android application for incoming calls.
Incoming calls take advantage of Firebase Cloud Messaging. To get started with Cloud Messaging follow the Firebase set up instructions here. **
Making an Outgoing Call
Outgoing calls are made using the createVoiceCall method. The active call is returned to the provided delegate or listener once it connects. During this time the call can be considered to be in progress.
let localNumber: PhoneNumber!
let remoteNumber = "2024561414"
let delegate: ActiveCallDelegate
try! telephonyClient.createVoiceCall(localNumber: localNumber, remoteNumber: remoteNumber, delegate: delegate)val localNumber: PhoneNumber
val remoteNumber = "2024561414"
val listener: ActiveCallListener
telephonyClient.createVoiceCall(localNumber, remoteNumber, listener)Interacting With an Active Call
The active call delegate (iOS) / listener (Android) must be provided when a call is created and is used to communicate active call events such as when the call connects, disconnects, or fails.
If a call connects successfully, the delegate/listener will be provided with anActiveVoiceCall object via the activeVoiceCallDidConnect method. This object provides functions for manipulating the call such as muting the microphone, ending the call, or switching the audio to speakerphone.
public protocol ActiveCallDelegate {
/// Notifies the delegate that the call has connected
/// - Parameters:
/// - call: The `ActiveVoiceCall`
func activeVoiceCallDidConnect(_ call: ActiveVoiceCall)
/// Notifies the delegate that the call failed to connect
/// - Parameters:
/// - error: `CallingError` that occurred.
func activeVoiceCallDidFailToConnect(withError error: CallingError)
/// Notifies the delegate that the call has been disconnected
/// - Parameters:
/// - call: The `ActiveVoiceCall`
/// - error: Error that caused the call to disconnect if one occurred.
func activeVoiceCall(_ call: ActiveVoiceCall, didDisconnectWithError error: Error?)
/// Notifies the delegate that the call has been muted or un-muted
/// - Parameters:
/// - call: The `ActiveVoiceCall`
/// - isMuted: Whether outgoing call audio is muted
func activeVoiceCall(_ call: ActiveVoiceCall, didChangeMuteState isMuted: Bool)
/// Called when the system audio route has changed.
/// Use `call.isOnSpeaker` to determine if the call is on speaker.
///
/// - Parameter call: The `ActiveVoiceCall`
func activeVoiceCallAudioRouteDidChange(_ call: ActiveVoiceCall)
}Receiving an Incoming Call
Subscribe to Incoming Calls
In AppDelegate.swift import PushKit and add a PKPushRegistry variable:
In the applicationDidFinishLaunchingWithOptions function set up the push registry:
Implement the PKPushRegistryDelegate methods to register, deregister and handle incoming call push notifications. When a push notification comes in, pass the payload from the voip push on to the SudoTelephonyClient along with an IncomingCallNotificationDelegate:
IncomingCallNotificationDelegate:
When the incomingCallReceived() function is called, you can take the IncomingCall object and either accept the call or decline the call. The accept method takes an ActiveCallDelegate instance which will then handle all of the call events.
IncomingCall:
Subscribe to Incoming Calls
In order to receive calls you must first set up Firebase Cloud Messaging in your app. Instructions can be found here.
_**_Subscribe to incoming calls using the fcmToken provided by Firebase. The following code will fail if Google Play Services are not enabled on the device.
Handle Incoming Firebase Messages
When a message comes in from Firebase, pass it on to the SudoTelephonyClient along with an IncomingCallNotificationListener:
IncomingCallNotificationListener:
When the incomingCallReceived() function is called, you can take the IncomingCall object and either accept the call or decline the call. The accept method takes an ActiveCallListener instance which will then handle all of the call events.
IncomingCall:
Manage Call Records
A call record is generated for each call made and received. The SDK provides three methods for accessing that data and one for deleting call records.
Get Call Records
Retrieve a list of call records with a provided PhoneNumber and an optional limit and token for pagination:
Get Call Record
Get a CallRecord providing its ID.
Subscribe To Call Records
Subscribe to CallRecord events and state changes. On iOS the subscribeToCallRecords() function returns a SubscriptionToken which can be used to cancel the subscription. On Android the function takes a CallRecordSubscriber instance which will receive CallRecord updates.
Delete Call Record
Delete a CallRecord providing its ID.
Call Record
A CallRecord contains all the information for a voice call made or received.
Voicemail
When an incoming call is rejected or times out, the caller is sent to voicemail. After hearing a recorded greeting, the caller can record up to 3 minutes of voicemail. The SDK provides several methods to manage these stored voicemail recordings.
Get Voicemails
Retrieve a list of voicemail records with a provided PhoneNumber and an optional limit and token for pagination:
Get Voicemail
Get a Voicemail by its ID.
Subscribe To Voicemails
Subscribe to Voicemail create events, update events, and delete events. On iOS the subscribeToVoicemails() function returns a SubscriptionToken which can be used to cancel the subscription. On Android the function takes a VoicemailSubscriber instance which will receive Voicemail events.
Delete Voicemail
Delete a Voicemail by its ID.
Voicemail Record
A Voicemail contains all the information for a voicemail recording.
Downloading Voicemail Audio Data
When voicemail records are retrieved, the audio data is not automatically downloaded. This gives you control over performance when retrieving voicemail records, particularly those with long recordings.
To download voicemail audio data, use the downloadData() method, passing it a MediaObject which can be retrieved from the media property of a Voicemail. This method returns the raw audio data.
Associating Voicemail Records with Call Records
Voicemail records and call records can be managed independently. However, a call record that has a corresponding voicemail has an additional voicemail property containing a copy of the voicemail data. When said voicemail is deleted this copy is also deleted.
The Voicemailrecord also has an optional callRecordId property which relates the voicemail to its call record if the call record has not been deleted.
Last updated