React Native wrapper for Twilio Programmable Voice SDK
npm install react-native-twilio-voice- Android 2.0.0-beta15 (bundled within this library)
- iOS 2.0.0-beta13 (specified by the app's own podfile)
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
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 do
...
pod 'TwilioVoice', '=2.0.0-beta13'
...
end
`run
pod install from inside your project ios directory
$3
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".
$3
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):`gradle
...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 project
apply plugin: 'com.google.gms.google-services'
`In your
AndroidManifest.xml`xml
.....
....
android:name="com.hoxfon.react.RNTwilioVoice.fcm.VoiceFirebaseMessagingService">
android:name="com.hoxfon.react.RNTwilioVoice.fcm.VoiceFirebaseInstanceIDService"
android:exported="false">
.....
`In
android/settings.gradle`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)`java
import com.hoxfon.react.RNTwilioVoice.TwilioVoicePackage; // <--- Import Packagepublic class MainApplication extends Application implements ReactApplication {
private final ReactNativeHost mReactNativeHost = new ReactNativeHost(this) {
@Override
protected boolean getUseDeveloperSupport() {
return BuildConfig.DEBUG;
}
@Override
protected List getPackages() {
return Arrays.asList(
new MainReactPackage(),
new TwilioVoicePackage() // <---- Add the Package
);
}
};
....
}
`Usage
`javascript
import TwilioVoice from 'react-native-twilio-voice'
...// initialize the Programmable Voice SDK passing an access token obtained from the server.
async function initTelephony() {
try {
const accessToken = await getAccessTokenFromServer()
const success = await TwilioVoice.initWithToken(accessToken)
} catch (err) {
console.err(err)
}
}
// iOS Only
function initTelephonyWithUrl(url) {
TwilioVoice.initWithTokenUrl(url)
try {
TwilioVoice.configureCallKit({
appName: 'TwilioVoiceExample', // Required param
imageName: 'my_image_name_in_bundle', // OPTIONAL
ringtoneSound: 'my_ringtone_sound_filename_in_bundle' // OPTIONAL
})
} catch (err) {
console.err(err)
}
}
// add listeners
TwilioVoice.addEventListener('deviceReady', deviceReadyHandler)
TwilioVoice.addEventListener('deviceNotReady', deviceNotReadyHandler) // Android Only
TwilioVoice.addEventListener('deviceDidReceiveIncoming', deviceDidReceiveIncomingHandler) // Android Only
TwilioVoice.addEventListener('connectionDidConnect', connectionDidConnectHandler)
TwilioVoice.addEventListener('connectionDidDisconnect', connectionDidDisconnectHandler)
TwilioVoice.addEventListener('callRejected', callRejected) // iOS Only
...
// start a call
TwilioVoice.connect({To: '+61234567890'})
// hangup
TwilioVoice.disconnect()
// accept an incoming call (Android only)
TwilioVoice.accept()
// reject an incoming call (Android only)
TwilioVoice.reject()
// ignore an incoming call (Android only)
TwilioVoice.ignore()
// mute or un-mute the call
// mutedValue must be a boolean
TwilioVoice.setMuted(mutedValue)
TwilioVoice.sendDigits(digits)
// should be called after the app is initialized
// to catch incoming call when the app was in the background
TwilioVoice.getActiveCall()
.then(incomingCall => {
if (incomingCall){
_deviceDidReceiveIncoming(incomingCall)
}
})
``react-native-push-notification
MIT