Skip to content

Commit 3b63bbb

Browse files
Android: implement Twilio 3.0 API
- add hold() call - add ringing state - remove state for callInvite - handle internal CANCEL_CALL notification - add ConnectOptions - remove blocks of code for callInvite PENDING
1 parent 97afcb0 commit 3b63bbb

File tree

8 files changed

+236
-158
lines changed

8 files changed

+236
-158
lines changed

CHANGELOG.md

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3,14 +3,20 @@
33
## 4.0.0
44

55
- Android
6+
- implement new autolinking react native API
67
- update Firebase Messaging to 17.3.4 which simplifies how to obtain the FCM token
78
- Android X migration
89
- use gradle 5.4.1
910
- use API 28
10-
- upgrade com.twilio:voice-android to 2.1.0
11+
- upgrade com.twilio:voice-android to 3.3.0
12+
- implement hold call Twilio API
13+
- implement call ringing Twilio event
14+
- remove `call_state` from CallInvite
1115
- iOS
12-
- convert params for connectionDidConnect to => call_to, from => call_from
13-
- convert params for connectionDidDisconnect to => call_to, from => call_from, error => err
16+
- convert params for `connectionDidConnect` to => `call_to`, from => `call_from`
17+
- convert params for `connectionDidDisconnect` to => `call_to`, from => `call_from`, `error` => `err`
18+
19+
- throw an error when listening to events that do not exist
1420

1521
## 3.21.3
1622

README.md

Lines changed: 12 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ This is a React Native wrapper for Twilio Programmable Voice SDK that lets you m
33

44
# Twilio Programmable Voice SDK
55

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

99
## Breaking changes in v4.0.0
@@ -21,6 +21,8 @@ This is a React Native wrapper for Twilio Programmable Voice SDK that lets you m
2121
<!-- [END instanceId_listener] -->
2222
```
2323

24+
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
25+
2426
- iOS: params changes for `connectionDidConnect` and `connectionDidDisconnect`
2527

2628
to => call_to
@@ -254,14 +256,14 @@ TwilioVoice.addEventListener('connectionDidConnect', function(data) {
254256
// Android
255257
// {
256258
// call_sid: string, // Twilio call sid
257-
// call_state: 'PENDING' | 'CONNECTED' | 'ACCEPTED' | 'CONNECTING' 'DISCONNECTED' | 'CANCELLED',
259+
// call_state: 'PENDING' | 'CONNECTED' | 'ACCEPTED' | 'CONNECTING' | 'RINGING' | 'DISCONNECTED' | 'CANCELLED',
258260
// call_from: string, // "+441234567890"
259261
// call_to: string, // "client:bob"
260262
// }
261263
// iOS
262264
// {
263265
// call_sid: string, // Twilio call sid
264-
// call_state: 'PENDING' | 'CONNECTED' | 'ACCEPTED' | 'CONNECTING' 'DISCONNECTED' | 'CANCELLED',
266+
// call_state: 'PENDING' | 'CONNECTED' | 'ACCEPTED' | 'CONNECTING' | 'DISCONNECTED' | 'CANCELLED',
265267
// from: string, // "+441234567890" // issue 44 (https://github.com/hoxfon/react-native-twilio-programmable-voice/issues/44)
266268
// to: string, // "client:bob" // issue 44 (https://github.com/hoxfon/react-native-twilio-programmable-voice/issues/44)
267269
// }
@@ -274,15 +276,15 @@ TwilioVoice.addEventListener('connectionDidDisconnect', function(data: mixed) {
274276
// | Android
275277
// {
276278
// call_sid: string, // Twilio call sid
277-
// call_state: 'PENDING' | 'CONNECTED' | 'ACCEPTED' | 'CONNECTING' 'DISCONNECTED' | 'CANCELLED',
279+
// call_state: 'PENDING' | 'CONNECTED' | 'ACCEPTED' | 'CONNECTING' | 'RINGING' | 'DISCONNECTED' | 'CANCELLED',
278280
// call_from: string, // "+441234567890"
279281
// call_to: string, // "client:bob"
280282
// err?: string,
281283
// }
282284
// | iOS
283285
// {
284286
// call_sid: string, // Twilio call sid
285-
// call_state: 'PENDING' | 'CONNECTED' | 'ACCEPTED' | 'CONNECTING' 'DISCONNECTED' | 'CANCELLED',
287+
// call_state: 'PENDING' | 'CONNECTED' | 'ACCEPTED' | 'CONNECTING' |'DISCONNECTED' | 'CANCELLED',
286288
// call_from?: string, // "+441234567890"
287289
// call_to?: string, // "client:bob"
288290
// from?: string, // "+441234567890" // issue 44 (https://github.com/hoxfon/react-native-twilio-programmable-voice/issues/44)
@@ -298,7 +300,7 @@ TwilioVoice.addEventListener('callRejected', function(value: 'callRejected') {})
298300
TwilioVoice.addEventListener('deviceDidReceiveIncoming', function(data) {
299301
// {
300302
// call_sid: string, // Twilio call sid
301-
// call_state: 'PENDING' | 'CONNECTED' | 'ACCEPTED' | 'CONNECTING' 'DISCONNECTED' | 'CANCELLED',
303+
// call_state: 'PENDING' | 'CONNECTED' | 'ACCEPTED' | 'CONNECTING' | 'RINGING' | 'DISCONNECTED' | 'CANCELLED', ==> this is removed in v4
302304
// call_from: string, // "+441234567890"
303305
// call_to: string, // "client:bob"
304306
// }
@@ -339,6 +341,10 @@ TwilioVoice.ignore()
339341
// mutedValue must be a boolean
340342
TwilioVoice.setMuted(mutedValue)
341343

344+
// put a call on hold
345+
TwilioVoice.setOnHold(holdValue)
346+
347+
// send digits
342348
TwilioVoice.sendDigits(digits)
343349

344350
// should be called after the app is initialized

android/build.gradle

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ buildscript {
44
repositories {
55
google()
66
jcenter()
7+
google()
78
}
89
dependencies {
910
classpath 'com.android.tools.build:gradle:3.5.2'
@@ -26,7 +27,7 @@ apply plugin: 'com.android.library'
2627
def DEFAULT_COMPILE_SDK_VERSION = 28
2728
def DEFAULT_BUILD_TOOLS_VERSION = "28.0.3"
2829
def DEFAULT_TARGET_SDK_VERSION = 28
29-
def DEFAULT_SUPPORT_LIB_VERSION = "28.0.0"
30+
def DEFAULT_SUPPORT_LIB_VERSION = "28.0.3"
3031

3132
android {
3233
compileSdkVersion rootProject.hasProperty('compileSdkVersion') ? rootProject.compileSdkVersion : DEFAULT_COMPILE_SDK_VERSION
@@ -50,7 +51,7 @@ dependencies {
5051
def supportLibVersion = rootProject.hasProperty('supportLibVersion') ? rootProject.supportLibVersion : DEFAULT_SUPPORT_LIB_VERSION
5152

5253
implementation fileTree(include: ['*.jar'], dir: 'libs')
53-
implementation 'com.twilio:voice-android:2.1.0'
54+
implementation 'com.twilio:voice-android:3.3.0'
5455
implementation "com.android.support:appcompat-v7:$supportLibVersion"
5556
implementation 'com.facebook.react:react-native:+'
5657
implementation 'com.google.firebase:firebase-messaging:17.+'

android/src/main/java/com/hoxfon/react/RNTwilioVoice/CallNotificationManager.java

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@
2121

2222
import com.facebook.react.bridge.ReactApplicationContext;
2323
import com.twilio.voice.CallInvite;
24+
import com.twilio.voice.CancelledCallInvite;
2425

2526
import java.util.List;
2627

@@ -307,12 +308,18 @@ public void createHangupLocalNotification(ReactApplicationContext context, Strin
307308
}
308309

309310
public void removeIncomingCallNotification(ReactApplicationContext context,
310-
CallInvite callInvite,
311+
CancelledCallInvite callInvite,
311312
int notificationId) {
312-
Log.d(TAG, "removeIncomingCallNotification");
313+
if (BuildConfig.DEBUG) {
314+
Log.d(TAG, "removeIncomingCallNotification");
315+
}
316+
if (context == null) {
317+
Log.e(TAG, "Context is null");
318+
return;
319+
}
313320
NotificationManager notificationManager = (NotificationManager) context.getSystemService(Context.NOTIFICATION_SERVICE);
314321
if (android.os.Build.VERSION.SDK_INT >= android.os.Build.VERSION_CODES.M) {
315-
if (callInvite != null && callInvite.getState() == CallInvite.State.PENDING) {
322+
if (callInvite != null) {
316323
/*
317324
* If the incoming call message was cancelled then remove the notification by matching
318325
* it with the call sid from the list of notifications in the notification drawer.

android/src/main/java/com/hoxfon/react/RNTwilioVoice/EventManager.java

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,9 @@ public class EventManager {
2121
public static final String EVENT_CONNECTION_DID_CONNECT = "connectionDidConnect";
2222
public static final String EVENT_CONNECTION_DID_DISCONNECT = "connectionDidDisconnect";
2323
public static final String EVENT_DEVICE_DID_RECEIVE_INCOMING = "deviceDidReceiveIncoming";
24+
public static final String EVENT_CALL_STATE_RINGING = "callStateRinging";
25+
26+
2427

2528
public EventManager(ReactApplicationContext context) {
2629
mContext = context;

0 commit comments

Comments
 (0)