react-native-twilio-voice
This is a React Native wrapper for Twilio Programmable Voice SDK that lets you make and receive calls from your ReactNatvie App. This module is not curated nor maintained, but inspired by Twilio.
Twilio Programmable Voice SDK
- Android 2.0.0-beta15 (bundled within this library)
- iOS 2.0.0-beta13 (specified by the app's own podfile)
Installation
Before starting, we recommend you get familiar with Twilio Programmable Voice SDK. It's easier to integrate this module into your react-native app if you follow the Quick start tutorial from Twilio, because it makes very clear which setup steps are required.
npm install react-native-twilio-voice --save
react-native link react-native-twilio-voice
iOS Installation
After you have linked the library with react-native link react-native-twilio-voice
check that libRNTwilioVoice.a
is present under YOUR_TARGET > Build Phases > Link Binaries With Libraries. If it is not present you can add it using the + sign at the bottom of that list.
Edit your Podfile
to include TwilioVoice framework
source 'https://github.com/cocoapods/specs'
source 'https://github.com/twilio/cocoapod-specs'
# min version for TwilioVoice to work
platform :ios, '8.1'
target <YOUR_TARGET> do
...
pod 'TwilioVoice', '=2.0.0-beta13'
...
end
run pod install
from inside your project ios
directory
CallKit
The current iOS part of this library works through CallKit. Because of this the call flow is much simpler than on Android as CallKit handles the inbound calls answering, ignoring, or rejecting. Because of CallKit, the only event listeners present are "deviceReady", "connectionDidConnect", "connectionDidDisconnect", and "callRejected".
VoIP Service Certificate
Twilio Programmable Voice for iOS utilizes Apple's VoIP Services and VoIP "Push Notifications" instead of FCM. You will need a VoIP Service Certificate from Apple to receive calls.
Android Installation
Setup FCM
You must download the file google-services.json
from the Firebase console.
It contains keys and settings for all your applications under Firebase. This library obtains the resource senderID
for registering for remote GCM from that file.
NOTE: To use a specific play-service-gcm
version, update the compile
instruction in your App's android/app/build.gradle
(replace 10.2.0
with the version you prefer):
... buildscript { ... dependencies { classpath 'com.google.gms:google-services:3.0.0' }} ... dependencies { ... compile project(':react-native-twilio-voice') compile ('com.google.android.gms:play-services-gcm:10.2.0') { force = true; }} // this plugin looks for google-services.json in your projectapply plugin: 'com.google.gms.google-services'
In your AndroidManifest.xml
..... .... <!-- Twilio Voice --> <!-- [START fcm_listener] --> <!-- [END fcm_listener] --> <!-- [START instanceId_listener] --> <!-- [END instanceId_listener] --> <!-- Twilio Voice --> .....
In android/settings.gradle
... include ':react-native-twilio-voice'project(':react-native-twilio-voice').projectDir = file('../node_modules/react-native-twilio-voice/android')
Register module (in MainApplication.java
)
// <--- Import Package
Usage
... // initialize the Programmable Voice SDK passing an access token obtained from the server. { try const accessToken = await const success = await TwilioVoice catch err console } // iOS Only { TwilioVoice try TwilioVoice catch err console } // add listenersTwilioVoiceTwilioVoice // Android OnlyTwilioVoice // Android OnlyTwilioVoiceTwilioVoiceTwilioVoice // iOS Only ... // start a callTwilioVoice // hangupTwilioVoice // accept an incoming call (Android only)TwilioVoiceaccept // reject an incoming call (Android only)TwilioVoice // ignore an incoming call (Android only)TwilioVoice // mute or un-mute the call// mutedValue must be a booleanTwilioVoice TwilioVoice // should be called after the app is initialized// to catch incoming call when the app was in the backgroundTwilioVoice
Credits
react-native-push-notification
License
MIT