Skip to content

Commit cbdb005

Browse files
authored
Merge pull request #298 from react-native-webrtc/add_phone_acount_methods
Add new methods to improve calls and phone account
2 parents adbef6c + 5677bc0 commit cbdb005

File tree

6 files changed

+89
-1
lines changed

6 files changed

+89
-1
lines changed

README.md

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -124,6 +124,15 @@ Eg: When your used log out (or the connection to your server is broken, etc..),
124124
RNCallKeep.setAvailable(true);
125125
```
126126

127+
### canMakeMultipleCalls
128+
_This feature is available only on Android._
129+
130+
Disable the "Add call" button in ConnectionService UI.
131+
132+
```js
133+
RNCallKeep.canMakeMultipleCalls(false); // Enabled by default
134+
```
135+
127136
- `active`: boolean
128137
- Tell whether the app is ready or not
129138

@@ -388,6 +397,29 @@ const options = {
388397
RNCallKeep.hasDefaultPhoneAccount(options);
389398
```
390399

400+
### checkPhoneAccountEnabled
401+
402+
Checks if the user has set a default [phone account](https://developer.android.com/reference/android/telecom/PhoneAccount) and it's enabled.
403+
404+
It's useful for custom permission prompts. It should be used in pair with `registerPhoneAccount`
405+
Similar to `hasDefaultPhoneAccount` but without trigering a prompt if the user doesn't have a phone account.
406+
407+
_This feature is available only on Android._
408+
409+
```js
410+
RNCallKeep.checkPhoneAccountEnabled();
411+
```
412+
413+
### isConnectionServiceAvailable
414+
415+
Check if the device support ConnectionService.
416+
417+
_This feature is available only on Android._
418+
419+
```js
420+
RNCallKeep.checkPhoneAccountEnabled();
421+
```
422+
391423
### backToForeground
392424
_This feature is available only on Android._
393425

android/src/main/java/io/wazo/callkeep/Constants.java

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,4 +16,6 @@ public class Constants {
1616
public static final String EXTRA_CALL_NUMBER = "EXTRA_CALL_NUMBER";
1717
public static final String EXTRA_CALL_UUID = "EXTRA_CALL_UUID";
1818
public static final String EXTRA_CALLER_NAME = "EXTRA_CALLER_NAME";
19+
// Can't use telecom.EXTRA_DISABLE_ADD_CALL ...
20+
public static final String EXTRA_DISABLE_ADD_CALL = "android.telecom.extra.DISABLE_ADD_CALL";
1921
}

android/src/main/java/io/wazo/callkeep/RNCallKeepModule.java

Lines changed: 15 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -386,6 +386,11 @@ public void setAvailable(Boolean active) {
386386
VoiceConnectionService.setAvailable(active);
387387
}
388388

389+
@ReactMethod
390+
public void canMakeMultipleCalls(Boolean allow) {
391+
VoiceConnectionService.setCanMakeMultipleCalls(allow);
392+
}
393+
389394
@ReactMethod
390395
public void setReachable() {
391396
VoiceConnectionService.setReachable();
@@ -432,12 +437,21 @@ public void openPhoneAccountSettings() {
432437
this.getAppContext().startActivity(intent);
433438
}
434439

435-
@ReactMethod
436440
public static Boolean isConnectionServiceAvailable() {
437441
// PhoneAccount is available since api level 23
438442
return Build.VERSION.SDK_INT >= 23;
439443
}
440444

445+
@ReactMethod
446+
public void isConnectionServiceAvailable(Promise promise) {
447+
promise.resolve(isConnectionServiceAvailable());
448+
}
449+
450+
@ReactMethod
451+
public void checkPhoneAccountEnabled(Promise promise) {
452+
promise.resolve(hasPhoneAccount());
453+
}
454+
441455
@ReactMethod
442456
public void backToForeground() {
443457
Context context = getAppContext();

android/src/main/java/io/wazo/callkeep/VoiceConnectionService.java

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -58,13 +58,15 @@
5858
import static io.wazo.callkeep.Constants.EXTRA_CALLER_NAME;
5959
import static io.wazo.callkeep.Constants.EXTRA_CALL_NUMBER;
6060
import static io.wazo.callkeep.Constants.EXTRA_CALL_UUID;
61+
import static io.wazo.callkeep.Constants.EXTRA_DISABLE_ADD_CALL;
6162

6263
// @see https://github.com/kbagchiGWC/voice-quickstart-android/blob/9a2aff7fbe0d0a5ae9457b48e9ad408740dfb968/exampleConnectionService/src/main/java/com/twilio/voice/examples/connectionservice/VoiceConnectionService.java
6364
@TargetApi(Build.VERSION_CODES.M)
6465
public class VoiceConnectionService extends ConnectionService {
6566
private static Boolean isAvailable;
6667
private static Boolean isInitialized;
6768
private static Boolean isReachable;
69+
private static Boolean canMakeMultipleCalls = true;
6870
private static String notReachableCallUuid;
6971
private static ConnectionRequest currentConnectionRequest;
7072
private static PhoneAccountHandle phoneAccountHandle;
@@ -103,6 +105,10 @@ public static void setAvailable(Boolean value) {
103105
isAvailable = value;
104106
}
105107

108+
public static void setCanMakeMultipleCalls(Boolean allow) {
109+
VoiceConnectionService.canMakeMultipleCalls = allow;
110+
}
111+
106112
public static void setReachable() {
107113
Log.d(TAG, "setReachable");
108114
isReachable = true;
@@ -170,6 +176,10 @@ private Connection makeOutgoingCall(ConnectionRequest request, String uuid, Bool
170176
extras.putString(EXTRA_CALL_NUMBER, number);
171177
}
172178

179+
if (!canMakeMultipleCalls) {
180+
extras.putBoolean(EXTRA_DISABLE_ADD_CALL, true);
181+
}
182+
173183
outgoingCallConnection = createConnection(request);
174184
outgoingCallConnection.setDialing();
175185
outgoingCallConnection.setAudioModeIsVoip(true);

index.d.ts

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -77,6 +77,10 @@ declare module 'react-native-callkeep' {
7777
handle: string,
7878
): void
7979

80+
static checkPhoneAccountEnabled(): Promise<boolean>;
81+
82+
static isConnectionServiceAvailable(): Promise<boolean>;
83+
8084
/**
8185
* @description reportConnectedOutgoingCallWithUUID method is available only on iOS.
8286
*/
@@ -132,6 +136,8 @@ declare module 'react-native-callkeep' {
132136
*/
133137
static setAvailable(active: boolean): void
134138

139+
static canMakeMultipleCalls(allow: boolean): void
140+
135141
static setCurrentCallActive(callUUID: string): void
136142

137143
static backToForeground(): void

index.js

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -101,6 +101,22 @@ class RNCallKeep {
101101
RNCallKeepModule.startCall(uuid, handle, contactIdentifier, handleType, hasVideo);
102102
};
103103

104+
checkPhoneAccountEnabled = async () => {
105+
if (isIOS) {
106+
return;
107+
}
108+
109+
return RNCallKeepModule.checkPhoneAccountEnabled();
110+
}
111+
112+
isConnectionServiceAvailable = async () => {
113+
if (isIOS) {
114+
return true;
115+
}
116+
117+
return RNCallKeepModule.isConnectionServiceAvailable();
118+
}
119+
104120
reportConnectingOutgoingCallWithUUID = (uuid) => {
105121
//only available on iOS
106122
if (isIOS) {
@@ -168,6 +184,14 @@ class RNCallKeep {
168184
RNCallKeepModule.setAvailable(state);
169185
};
170186

187+
canMakeMultipleCalls = (state) => {
188+
if (isIOS) {
189+
return;
190+
}
191+
192+
RNCallKeepModule.canMakeMultipleCalls(state);
193+
};
194+
171195
setCurrentCallActive = (callUUID) => {
172196
if (isIOS) {
173197
return;

0 commit comments

Comments
 (0)