Skip to content

Commit

Permalink
Android: implement Twilio Programmable Voice Android SDK 3.3.0
Browse files Browse the repository at this point in the history
- new feature call hold
- new feature call ringing state
- new feature ConnectOptions
- remove state for callInvite
- handle internal CANCEL_CALL notification
- remove blocks of code for callInvite PENDING
  • Loading branch information
fabriziomoscon committed Oct 23, 2020
1 parent ff7b690 commit f5da63b
Show file tree
Hide file tree
Showing 9 changed files with 294 additions and 205 deletions.
15 changes: 12 additions & 3 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,14 +3,23 @@
## 4.0.0

- Android
- implement new autolinking react native API
- update Firebase Messaging to 17.3.4 which simplifies how to obtain the FCM token
- Android X migration
- use gradle 5.4.1
- use API 28
- upgrade com.twilio:voice-android to 2.1.0
- upgrade com.twilio:voice-android to 3.3.0
- implement `hold` to hold a call
- new event `callInviteCancelled`
- new event `callStateRinging`
- new method `getCallInvite`
- implement call ringing Twilio event
- remove `call_state` from CallInvite
- iOS
- convert params for connectionDidConnect to => call_to, from => call_from
- convert params for connectionDidDisconnect to => call_to, from => call_from, error => err
- convert params for `connectionDidConnect` to => `call_to`, from => `call_from`
- convert params for `connectionDidDisconnect` to => `call_to`, from => `call_from`, `error` => `err`

- throw an error when listening to events that do not exist

## 3.21.3

Expand Down
76 changes: 47 additions & 29 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ This is a React Native wrapper for Twilio Programmable Voice SDK that lets you m

# Twilio Programmable Voice SDK

- Android 2.1.0 (bundled within this library)
- Android 3.3.0 (bundled within this library)
- iOS 2.1.0 (specified by the app's own podfile)

## Breaking changes in v4.0.0
Expand All @@ -21,12 +21,24 @@ This is a React Native wrapper for Twilio Programmable Voice SDK that lets you m
<!-- [END instanceId_listener] -->
```

Data passed to the event `deviceDidReceiveIncoming` does not contain the key `call_state`, because state of Call Invites was removed in Twilio Android v3.0.0

- iOS: params changes for `connectionDidConnect` and `connectionDidDisconnect`

to => call_to
from => call_from
error => err

New features

Twilio Programmable Voice SDK v3.0.0 handles call invites directly and makes it easy to distinguish a call invites from an active call, which previously was confusing.
To ensure that an active call is displayed when the app comes to foreground you should use the promise `getActiveCall()`.
To ensure that a call invite is displayed when the app comes to foreground use the promise `getCallInvite()`. Please note that call invites don't have a `call_state` field.

You should use `hold()` to put a call on hold.

You can be notified when a call is `ringing` by listening for `callStateRinging` events.

## Breaking changes in v3.0.0

- initWitToken returns an object with a property `initialized` instead of `initilized`
Expand Down Expand Up @@ -251,44 +263,40 @@ TwilioVoice.addEventListener('deviceNotReady', function(data) {
// }
})
TwilioVoice.addEventListener('connectionDidConnect', function(data) {
// Android
// {
// call_sid: string, // Twilio call sid
// call_state: 'PENDING' | 'CONNECTED' | 'ACCEPTED' | 'CONNECTING' 'DISCONNECTED' | 'CANCELLED',
// call_state: 'PENDING' | 'CONNECTED' | 'ACCEPTED' | 'CONNECTING' | 'RINGING' | 'DISCONNECTED' | 'CANCELLED',
// call_from: string, // "+441234567890"
// call_to: string, // "client:bob"
// }
// iOS
// {
// call_sid: string, // Twilio call sid
// call_state: 'PENDING' | 'CONNECTED' | 'ACCEPTED' | 'CONNECTING' 'DISCONNECTED' | 'CANCELLED',
// from: string, // "+441234567890" // issue 44 (https://github.com/hoxfon/react-native-twilio-programmable-voice/issues/44)
// to: string, // "client:bob" // issue 44 (https://github.com/hoxfon/react-native-twilio-programmable-voice/issues/44)
// }
})
TwilioVoice.addEventListener('connectionDidDisconnect', function(data: mixed) {
// | null
// | {
// err: string
// }
// | Android
// {
// | {
// call_sid: string, // Twilio call sid
// call_state: 'PENDING' | 'CONNECTED' | 'ACCEPTED' | 'CONNECTING' 'DISCONNECTED' | 'CANCELLED',
// call_state: 'PENDING' | 'CONNECTED' | 'ACCEPTED' | 'CONNECTING' | 'RINGING' | 'DISCONNECTED' | 'CANCELLED',
// call_from: string, // "+441234567890"
// call_to: string, // "client:bob"
// err?: string,
// }
// | iOS
// {
// call_sid: string, // Twilio call sid
// call_state: 'PENDING' | 'CONNECTED' | 'ACCEPTED' | 'CONNECTING' 'DISCONNECTED' | 'CANCELLED',
// call_from?: string, // "+441234567890"
// call_to?: string, // "client:bob"
// from?: string, // "+441234567890" // issue 44 (https://github.com/hoxfon/react-native-twilio-programmable-voice/issues/44)
// to?: string, // "client:bob" // issue 44 (https://github.com/hoxfon/react-native-twilio-programmable-voice/issues/44)
// error?: string, // issue 44 (https://github.com/hoxfon/react-native-twilio-programmable-voice/issues/44)
// }
})
TwilioVoice.addEventListener('callStateRinging', function(data: mixed) {
// {
// call_sid: string, // Twilio call sid
// call_state: 'PENDING' | 'CONNECTED' | 'ACCEPTED' | 'CONNECTING' | 'RINGING' | 'DISCONNECTED' | 'CANCELLED',
// call_from: string, // "+441234567890"
// call_to: string, // "client:bob"
// }
})
TwilioVoice.addEventListener('callInviteCancelled', function(data: mixed) {
// {
// call_sid: string, // Twilio call sid
// call_from: string, // "+441234567890"
// call_to: string, // "client:bob"
// }
})

// iOS Only
Expand All @@ -298,7 +306,6 @@ TwilioVoice.addEventListener('callRejected', function(value: 'callRejected') {})
TwilioVoice.addEventListener('deviceDidReceiveIncoming', function(data) {
// {
// call_sid: string, // Twilio call sid
// call_state: 'PENDING' | 'CONNECTED' | 'ACCEPTED' | 'CONNECTING' 'DISCONNECTED' | 'CANCELLED',
// call_from: string, // "+441234567890"
// call_to: string, // "client:bob"
// }
Expand Down Expand Up @@ -339,14 +346,25 @@ TwilioVoice.ignore()
// mutedValue must be a boolean
TwilioVoice.setMuted(mutedValue)

// put a call on hold
TwilioVoice.setOnHold(holdValue)

// send digits
TwilioVoice.sendDigits(digits)

// should be called after the app is initialized
// to catch incoming call when the app was in the background
// Ensure that an active call is displayed when the app comes to foreground
TwilioVoice.getActiveCall()
.then(incomingCall => {
if (incomingCall){
_deviceDidReceiveIncoming(incomingCall)
.then(activeCall => {
if (activeCall){
_displayActiveCall(activeCall)
}
})

// Ensure that call invites are displayed when the app comes to foreground
TwilioVoice.getCallInvite()
.then(callInvite => {
if (callInvite){
_handleCallInvite(callInvite)
}
})

Expand Down
8 changes: 6 additions & 2 deletions android/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -26,11 +26,15 @@ apply plugin: 'com.android.library'
def DEFAULT_COMPILE_SDK_VERSION = 28
def DEFAULT_BUILD_TOOLS_VERSION = "28.0.3"
def DEFAULT_TARGET_SDK_VERSION = 28
def DEFAULT_SUPPORT_LIB_VERSION = "28.0.0"
def DEFAULT_SUPPORT_LIB_VERSION = "28.0.3"

android {
compileSdkVersion rootProject.hasProperty('compileSdkVersion') ? rootProject.compileSdkVersion : DEFAULT_COMPILE_SDK_VERSION
buildToolsVersion rootProject.hasProperty('buildToolsVersion') ? rootProject.buildToolsVersion : DEFAULT_BUILD_TOOLS_VERSION
compileOptions {
sourceCompatibility 1.8
targetCompatibility 1.8
}
defaultConfig {
minSdkVersion 16
targetSdkVersion rootProject.hasProperty('targetSdkVersion') ? rootProject.targetSdkVersion : DEFAULT_TARGET_SDK_VERSION
Expand All @@ -50,7 +54,7 @@ dependencies {
def supportLibVersion = rootProject.hasProperty('supportLibVersion') ? rootProject.supportLibVersion : DEFAULT_SUPPORT_LIB_VERSION

implementation fileTree(include: ['*.jar'], dir: 'libs')
implementation 'com.twilio:voice-android:2.1.0'
implementation 'com.twilio:voice-android:3.3.0'
implementation "com.android.support:appcompat-v7:$supportLibVersion"
implementation 'com.facebook.react:react-native:+'
implementation 'com.google.firebase:firebase-messaging:17.+'
Expand Down
2 changes: 2 additions & 0 deletions android/gradle.properties
Original file line number Diff line number Diff line change
Expand Up @@ -15,3 +15,5 @@ org.gradle.jvmargs=-Xmx1536m
# This option should only be used with decoupled projects. More details, visit
# http://www.gradle.org/docs/current/userguide/multi_project_builds.html#sec:decoupled_projects
# org.gradle.parallel=true
android.useAndroidX=true
android.enableJetifier=true
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@

import com.facebook.react.bridge.ReactApplicationContext;
import com.twilio.voice.CallInvite;
import com.twilio.voice.CancelledCallInvite;

import java.util.List;

Expand Down Expand Up @@ -307,12 +308,18 @@ public void createHangupLocalNotification(ReactApplicationContext context, Strin
}

public void removeIncomingCallNotification(ReactApplicationContext context,
CallInvite callInvite,
CancelledCallInvite callInvite,
int notificationId) {
Log.d(TAG, "removeIncomingCallNotification");
if (BuildConfig.DEBUG) {
Log.d(TAG, "removeIncomingCallNotification");
}
if (context == null) {
Log.e(TAG, "Context is null");
return;
}
NotificationManager notificationManager = (NotificationManager) context.getSystemService(Context.NOTIFICATION_SERVICE);
if (android.os.Build.VERSION.SDK_INT >= android.os.Build.VERSION_CODES.M) {
if (callInvite != null && callInvite.getState() == CallInvite.State.PENDING) {
if (callInvite != null) {
/*
* If the incoming call message was cancelled then remove the notification by matching
* it with the call sid from the list of notifications in the notification drawer.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,9 @@ public class EventManager {
public static final String EVENT_CONNECTION_DID_CONNECT = "connectionDidConnect";
public static final String EVENT_CONNECTION_DID_DISCONNECT = "connectionDidDisconnect";
public static final String EVENT_DEVICE_DID_RECEIVE_INCOMING = "deviceDidReceiveIncoming";
public static final String EVENT_CALL_STATE_RINGING = "callStateRinging";
public static final String EVENT_CALL_INVITE_CANCELLED = "callInviteCancelled";


public EventManager(ReactApplicationContext context) {
mContext = context;
Expand Down
Loading

0 comments on commit f5da63b

Please sign in to comment.