Skip to content

Add new methods to improve calls and phone account #298

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 3 commits into from
Nov 11, 2020
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
32 changes: 32 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -124,6 +124,15 @@ Eg: When your used log out (or the connection to your server is broken, etc..),
RNCallKeep.setAvailable(true);
```

### canMakeMultipleCalls
_This feature is available only on Android._

Disable the "Add call" button in ConnectionService UI.

```js
RNCallKeep.canMakeMultipleCalls(false); // Enabled by default
```

- `active`: boolean
- Tell whether the app is ready or not

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

### checkPhoneAccountEnabled

Checks if the user has set a default [phone account](https://developer.android.com/reference/android/telecom/PhoneAccount) and it's enabled.

It's useful for custom permission prompts. It should be used in pair with `registerPhoneAccount`
Similar to `hasDefaultPhoneAccount` but without trigering a prompt if the user doesn't have a phone account.

_This feature is available only on Android._

```js
RNCallKeep.checkPhoneAccountEnabled();
```

### isConnectionServiceAvailable

Check if the device support ConnectionService.

_This feature is available only on Android._

```js
RNCallKeep.checkPhoneAccountEnabled();
```

### backToForeground
_This feature is available only on Android._

2 changes: 2 additions & 0 deletions android/src/main/java/io/wazo/callkeep/Constants.java
Original file line number Diff line number Diff line change
@@ -16,4 +16,6 @@ public class Constants {
public static final String EXTRA_CALL_NUMBER = "EXTRA_CALL_NUMBER";
public static final String EXTRA_CALL_UUID = "EXTRA_CALL_UUID";
public static final String EXTRA_CALLER_NAME = "EXTRA_CALLER_NAME";
// Can't use telecom.EXTRA_DISABLE_ADD_CALL ...
public static final String EXTRA_DISABLE_ADD_CALL = "android.telecom.extra.DISABLE_ADD_CALL";
}
16 changes: 15 additions & 1 deletion android/src/main/java/io/wazo/callkeep/RNCallKeepModule.java
Original file line number Diff line number Diff line change
@@ -386,6 +386,11 @@ public void setAvailable(Boolean active) {
VoiceConnectionService.setAvailable(active);
}

@ReactMethod
public void canMakeMultipleCalls(Boolean allow) {
VoiceConnectionService.setCanMakeMultipleCalls(allow);
}

@ReactMethod
public void setReachable() {
VoiceConnectionService.setReachable();
@@ -432,12 +437,21 @@ public void openPhoneAccountSettings() {
this.getAppContext().startActivity(intent);
}

@ReactMethod
public static Boolean isConnectionServiceAvailable() {
// PhoneAccount is available since api level 23
return Build.VERSION.SDK_INT >= 23;
}

@ReactMethod
public void isConnectionServiceAvailable(Promise promise) {
promise.resolve(isConnectionServiceAvailable());
}

@ReactMethod
public void checkPhoneAccountEnabled(Promise promise) {
promise.resolve(hasPhoneAccount());
}

@ReactMethod
public void backToForeground() {
Context context = getAppContext();
10 changes: 10 additions & 0 deletions android/src/main/java/io/wazo/callkeep/VoiceConnectionService.java
Original file line number Diff line number Diff line change
@@ -58,13 +58,15 @@
import static io.wazo.callkeep.Constants.EXTRA_CALLER_NAME;
import static io.wazo.callkeep.Constants.EXTRA_CALL_NUMBER;
import static io.wazo.callkeep.Constants.EXTRA_CALL_UUID;
import static io.wazo.callkeep.Constants.EXTRA_DISABLE_ADD_CALL;

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

public static void setCanMakeMultipleCalls(Boolean allow) {
VoiceConnectionService.canMakeMultipleCalls = allow;
}

public static void setReachable() {
Log.d(TAG, "setReachable");
isReachable = true;
@@ -170,6 +176,10 @@ private Connection makeOutgoingCall(ConnectionRequest request, String uuid, Bool
extras.putString(EXTRA_CALL_NUMBER, number);
}

if (!canMakeMultipleCalls) {
extras.putBoolean(EXTRA_DISABLE_ADD_CALL, true);
}

outgoingCallConnection = createConnection(request);
outgoingCallConnection.setDialing();
outgoingCallConnection.setAudioModeIsVoip(true);
6 changes: 6 additions & 0 deletions index.d.ts
Original file line number Diff line number Diff line change
@@ -77,6 +77,10 @@ declare module 'react-native-callkeep' {
handle: string,
): void

static checkPhoneAccountEnabled(): Promise<boolean>;

static isConnectionServiceAvailable(): Promise<boolean>;

/**
* @description reportConnectedOutgoingCallWithUUID method is available only on iOS.
*/
@@ -132,6 +136,8 @@ declare module 'react-native-callkeep' {
*/
static setAvailable(active: boolean): void

static canMakeMultipleCalls(allow: boolean): void

static setCurrentCallActive(callUUID: string): void

static backToForeground(): void
24 changes: 24 additions & 0 deletions index.js
Original file line number Diff line number Diff line change
@@ -101,6 +101,22 @@ class RNCallKeep {
RNCallKeepModule.startCall(uuid, handle, contactIdentifier, handleType, hasVideo);
};

checkPhoneAccountEnabled = async () => {
if (isIOS) {
return;
}

return RNCallKeepModule.checkPhoneAccountEnabled();
}

isConnectionServiceAvailable = async () => {
if (isIOS) {
return true;
}

return RNCallKeepModule.isConnectionServiceAvailable();
}

reportConnectingOutgoingCallWithUUID = (uuid) => {
//only available on iOS
if (isIOS) {
@@ -168,6 +184,14 @@ class RNCallKeep {
RNCallKeepModule.setAvailable(state);
};

canMakeMultipleCalls = (state) => {
if (isIOS) {
return;
}

RNCallKeepModule.canMakeMultipleCalls(state);
};

setCurrentCallActive = (callUUID) => {
if (isIOS) {
return;