diff --git a/README.md b/README.md index 8d6e8066..4a55c1e7 100644 --- a/README.md +++ b/README.md @@ -207,6 +207,7 @@ Self Managed calling apps are an advanced topic, and there are many steps involv | [reportEndCallWithUUID()](#reportEndCallWithUUID) | `Promise` | ✅ | ✅ | | [setMutedCall()](#setMutedCall) | `Promise` | ✅ | ✅ | | [setOnHold()](#setOnHold) | `Promise` | ✅ | ✅ | +| [setConnectionState()](#setConnectionState) | `Promise` | ❌ | ✅ | | [checkIfBusy()](#checkIfBusy) | `Promise` | ✅ | ❌ | | [checkSpeaker()](#checkSpeaker) | `Promise` | ✅ | ❌ | | [toggleAudioRouteSpeaker()](#toggleAudioRouteSpeaker) | `Promise` | ❌ | ✅ | @@ -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._ diff --git a/android/src/main/java/io/wazo/callkeep/RNCallKeepModule.java b/android/src/main/java/io/wazo/callkeep/RNCallKeepModule.java index d6aeb686..fb275d38 100644 --- a/android/src/main/java/io/wazo/callkeep/RNCallKeepModule.java +++ b/android/src/main/java/io/wazo/callkeep/RNCallKeepModule.java @@ -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; } @@ -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")); diff --git a/android/src/main/java/io/wazo/callkeep/VoiceConnectionService.java b/android/src/main/java/io/wazo/callkeep/VoiceConnectionService.java index c373eaba..c2443308 100644 --- a/android/src/main/java/io/wazo/callkeep/VoiceConnectionService.java +++ b/android/src/main/java/io/wazo/callkeep/VoiceConnectionService.java @@ -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(); diff --git a/index.d.ts b/index.d.ts index 18b93293..0e1c5e52 100644 --- a/index.d.ts +++ b/index.d.ts @@ -168,8 +168,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. */ diff --git a/index.js b/index.js index 356d6571..d1736012 100644 --- a/index.js +++ b/index.js @@ -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