Skip to content

Commit

Permalink
Add new canMakeMultipleCalls method
Browse files Browse the repository at this point in the history
  • Loading branch information
manuquentin committed Oct 8, 2020
1 parent c257086 commit 5677bc0
Show file tree
Hide file tree
Showing 6 changed files with 36 additions and 0 deletions.
9 changes: 9 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
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
Expand Up @@ -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";
}
5 changes: 5 additions & 0 deletions android/src/main/java/io/wazo/callkeep/RNCallKeepModule.java
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand Down
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
Expand Up @@ -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;
Expand Down Expand Up @@ -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;
Expand Down Expand Up @@ -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);
Expand Down
2 changes: 2 additions & 0 deletions index.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -136,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
Expand Down
8 changes: 8 additions & 0 deletions index.js
Original file line number Diff line number Diff line change
Expand Up @@ -184,6 +184,14 @@ class RNCallKeep {
RNCallKeepModule.setAvailable(state);
};

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

RNCallKeepModule.canMakeMultipleCalls(state);
};

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

0 comments on commit 5677bc0

Please sign in to comment.