Skip to content

Commit

Permalink
Merge pull request #524 from react-native-webrtc/add_android_set_state
Browse files Browse the repository at this point in the history
Add setConnectionState method for Android
  • Loading branch information
manuquentin authored Feb 16, 2022
2 parents 24fa3c2 + 2ce3a3f commit b3ea2a8
Show file tree
Hide file tree
Showing 5 changed files with 58 additions and 1 deletion.
15 changes: 15 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -207,6 +207,7 @@ Self Managed calling apps are an advanced topic, and there are many steps involv
| [reportEndCallWithUUID()](#reportEndCallWithUUID) | `Promise<void>` | ✅ | ✅ |
| [setMutedCall()](#setMutedCall) | `Promise<void>` | ✅ | ✅ |
| [setOnHold()](#setOnHold) | `Promise<void>` | ✅ | ✅ |
| [setConnectionState()](#setConnectionState) | `Promise<void>` | ❌ | ✅ |
| [checkIfBusy()](#checkIfBusy) | `Promise<Boolean>` | ✅ | ❌ |
| [checkSpeaker()](#checkSpeaker) | `Promise<Boolean>` | ✅ | ❌ |
| [toggleAudioRouteSpeaker()](#toggleAudioRouteSpeaker) | `Promise<void>` | ❌ | ✅ |
Expand Down Expand Up @@ -492,6 +493,20 @@ RNCallKeep.setOnHold(uuid, true)
- uuid of the current call.
- `hold`: boolean

### setConnectionState

_This feature is available only on Android._

Change the state of the call

```js
RNCallKeep.setConnectionState(uuid, state)
```

- `uuid`: string
- uuid of the current call.
- `state`: [See Connection.STATE_*](https://developer.android.com/reference/android/telecom/Connection#STATE_ACTIVE) documentation

### checkIfBusy

_This feature is available only on IOS._
Expand Down
13 changes: 12 additions & 1 deletion android/src/main/java/io/wazo/callkeep/RNCallKeepModule.java
Original file line number Diff line number Diff line change
Expand Up @@ -558,7 +558,7 @@ public void reportEndCallWithUUID(String uuid, int reason) {
public void rejectCall(String uuid) {
Log.d(TAG, "[VoiceConnection] rejectCall, uuid: " + uuid);
if (!isConnectionServiceAvailable() || !hasPhoneAccount()) {
Log.w(TAG, "[VoiceConnection] endAllCalls ignored due to no ConnectionService or no phone account");
Log.w(TAG, "[RNCallKeepModule] rejectCall ignored due to no ConnectionService or no phone account");
return;
}

Expand All @@ -571,6 +571,17 @@ public void rejectCall(String uuid) {
conn.onReject();
}

@ReactMethod
public void setConnectionState(String uuid, int state) {
Log.d(TAG, "[RNCallKeepModule] setConnectionState, uuid: " + uuid + ", state :" + state);
if (!isConnectionServiceAvailable() || !hasPhoneAccount()) {
Log.w(TAG, "[RNCallKeepModule] String ignored due to no ConnectionService or no phone account");
return;
}

VoiceConnectionService.setState(uuid, state);
}

@ReactMethod
public void setMutedCall(String uuid, boolean shouldMute) {
Log.d(TAG, "[VoiceConnection] setMutedCall, uuid: " + uuid + ", shouldMute: " + (shouldMute ? "true" : "false"));
Expand Down
26 changes: 26 additions & 0 deletions android/src/main/java/io/wazo/callkeep/VoiceConnectionService.java
Original file line number Diff line number Diff line change
Expand Up @@ -150,6 +150,32 @@ public static void deinitConnection(String connectionId) {
}
}

public static void setState(String uuid, int state) {
Connection conn = VoiceConnectionService.getConnection(uuid);
if (conn == null) {
Log.w(TAG, "[VoiceConnectionService] setState ignored because no connection found, uuid: " + uuid);
return;
}

switch (state) {
case Connection.STATE_ACTIVE:
conn.setActive();
break;
case Connection.STATE_DIALING:
conn.setDialing();
break;
case Connection.STATE_HOLDING:
conn.setOnHold();
break;
case Connection.STATE_INITIALIZING:
conn.setInitializing();
break;
case Connection.STATE_RINGING:
conn.setRinging();
break;
}
}

@Override
public Connection onCreateIncomingConnection(PhoneAccountHandle connectionManagerPhoneAccount, ConnectionRequest request) {
Bundle extra = request.getExtras();
Expand Down
3 changes: 3 additions & 0 deletions index.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -169,8 +169,11 @@ declare module 'react-native-callkeep' {
* @param routeSpeaker
*/
static toggleAudioRouteSpeaker(uuid: string, routeSpeaker: boolean): void

static setOnHold(uuid: string, held: boolean): void

static setConnectionState(uuid: string, state: number): void

/**
* @descriptions sendDTMF is used to send DTMF tones to the PBX.
*/
Expand Down
2 changes: 2 additions & 0 deletions index.js
Original file line number Diff line number Diff line change
Expand Up @@ -257,6 +257,8 @@ class RNCallKeep {

setOnHold = (uuid, shouldHold) => RNCallKeepModule.setOnHold(uuid, shouldHold);

setConnectionState = (uuid, state) => isIOS ? null : RNCallKeepModule.setConnectionState(uuid, state);

setReachable = () => RNCallKeepModule.setReachable();

// @deprecated
Expand Down

0 comments on commit b3ea2a8

Please sign in to comment.