Requirements
- Have a portal account
- Configure your portal account for voice
- Have 2 SIP Connections: To learn how to setup a SIP connection, please visit our Quick Start Guide. We are going to use one SIP connection for the caller and another for the callee.
- Have configured your push notification credentials into the portal. Visit our Push Notifications Setup Guide for more information.
Build the iOS app
Configure the project
- Setup the TelnyxRTC iOS SDK into your project.
-
Enable the following capabillities into your app:
- Background mode: Audio, Airplay and Picture in picture
- Background mode: Voice over IP
- Push Notifications
Setup the Telnyx client
- Import the SDK into your ViewController
- Create and instance of the SDK
- Setup the delegate
Setup CallKit
Use CallKit to integrate your calling services with other call-related apps on the system. CallKit provides the calling interface, and you handle the back-end communication with your VoIP service. For incoming and outgoing calls, CallKit displays the same interfaces as the Phone app, giving your app a more native look and feel. CallKit also responds appropriately to system-level behaviors such as Do Not Disturb. For more information check the CallKit official documentation.- Setup the CallKit provider and Controller
- Implement the CXProviderDelegate
Setup PushKit
If your app provides Voice-over-IP (VoIP) phone services, you may use PushKit to handle incoming calls on user devices. PushKit provides an efficient way to manage calls that doesn’t require your app to be running to receive calls. Upon receiving the notification, the device wakes up your app and gives it time to notify the user and connect to your call service. For more information check the PushKit official documentation.- Init PushKit to receive VoIP push notifications:
- Implement the PKPushRegistryDelegate. Inside this delegate you will receive updates from APNS of the device Push Token and the
- Inside the
didUpdate credentialsdelegate method it’s required to:- Store your APNS token
- Register the APNS device token into our backend by connecting the TelnyxClient as follows:
- Process the incoming push notification. In this step we need to:
- Decode the push payload
- Send the push notificaiton payload to the SDK to get the call
- Register the call into the system using CallKit.
Code flow summarized
- Initialize push kit to get an APNS token
- Send the APNS token to register the device into Telnyx backend by login in through the SDK using the user’s
SIP credentials. - When a PN is received through PushKit, two main actions must be executed: a. Warn the
Telnyx SDKabout the incoming push notification by callingprocessVoIPNotificationin order to get the call connected. b. Register the incoming call intoCallKit. This will trigger the Incoming call system notification to be displayed. - The SDK will fire the delegate method
onPushCallwith the new instance of the call that can be answered or rejected.
Build the Android app
Configure the project
- Setup the TelnyxRTC Android SDK into your project. The SDK is delivered through Jitpack.
- Add the following permissions into your project manifest:
Setup the Telnyx client
- Initialize the client: To initialize the TelnyxClient you will have to provide the application context. Once an instance is created, you can call the
.connect()method to connect to the socket. An error will appear as a socket response if there is no network available:
- Logging into Telnyx Client: To log into the Telnyx WebRTC client, you’ll need to authenticate using a Telnyx
SIP Connection. Follow this guide to create JWTs (JSON Web Tokens) to authenticate. To log in with a token we use thetokinLogin()method. You can also authenticate directly with the SIP Connectionusernameandpasswordwith thecredentialLogin()method:
tokenConfig and credentialConfig are data classes that represent login settings for the client to use. They look like this:
- Creating a call invitation: In order to make a call invitation, you need to provide your callerName, callerNumber, the destinationNumber (or SIP credential), and your clientState (any String value).
- Accepting a call: In order to be able to accept a call, we first need to listen for invitations. We do this by getting the Telnyx Socket Response as LiveData: