Skip to content

Commit 2ce3a3f

Browse files
committed
Add setConnectionState method for Android
1 parent 0f04cb0 commit 2ce3a3f

File tree

5 files changed

+58
-1
lines changed

5 files changed

+58
-1
lines changed

README.md

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -207,6 +207,7 @@ Self Managed calling apps are an advanced topic, and there are many steps involv
207207
| [reportEndCallWithUUID()](#reportEndCallWithUUID) | `Promise<void>` | ✅ | ✅ |
208208
| [setMutedCall()](#setMutedCall) | `Promise<void>` | ✅ | ✅ |
209209
| [setOnHold()](#setOnHold) | `Promise<void>` | ✅ | ✅ |
210+
| [setConnectionState()](#setConnectionState) | `Promise<void>` | ❌ | ✅ |
210211
| [checkIfBusy()](#checkIfBusy) | `Promise<Boolean>` | ✅ | ❌ |
211212
| [checkSpeaker()](#checkSpeaker) | `Promise<Boolean>` | ✅ | ❌ |
212213
| [toggleAudioRouteSpeaker()](#toggleAudioRouteSpeaker) | `Promise<void>` | ❌ | ✅ |
@@ -492,6 +493,20 @@ RNCallKeep.setOnHold(uuid, true)
492493
- uuid of the current call.
493494
- `hold`: boolean
494495

496+
### setConnectionState
497+
498+
_This feature is available only on Android._
499+
500+
Change the state of the call
501+
502+
```js
503+
RNCallKeep.setConnectionState(uuid, state)
504+
```
505+
506+
- `uuid`: string
507+
- uuid of the current call.
508+
- `state`: [See Connection.STATE_*](https://developer.android.com/reference/android/telecom/Connection#STATE_ACTIVE) documentation
509+
495510
### checkIfBusy
496511

497512
_This feature is available only on IOS._

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

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -558,7 +558,7 @@ public void reportEndCallWithUUID(String uuid, int reason) {
558558
public void rejectCall(String uuid) {
559559
Log.d(TAG, "[VoiceConnection] rejectCall, uuid: " + uuid);
560560
if (!isConnectionServiceAvailable() || !hasPhoneAccount()) {
561-
Log.w(TAG, "[VoiceConnection] endAllCalls ignored due to no ConnectionService or no phone account");
561+
Log.w(TAG, "[RNCallKeepModule] rejectCall ignored due to no ConnectionService or no phone account");
562562
return;
563563
}
564564

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

574+
@ReactMethod
575+
public void setConnectionState(String uuid, int state) {
576+
Log.d(TAG, "[RNCallKeepModule] setConnectionState, uuid: " + uuid + ", state :" + state);
577+
if (!isConnectionServiceAvailable() || !hasPhoneAccount()) {
578+
Log.w(TAG, "[RNCallKeepModule] String ignored due to no ConnectionService or no phone account");
579+
return;
580+
}
581+
582+
VoiceConnectionService.setState(uuid, state);
583+
}
584+
574585
@ReactMethod
575586
public void setMutedCall(String uuid, boolean shouldMute) {
576587
Log.d(TAG, "[VoiceConnection] setMutedCall, uuid: " + uuid + ", shouldMute: " + (shouldMute ? "true" : "false"));

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

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -150,6 +150,32 @@ public static void deinitConnection(String connectionId) {
150150
}
151151
}
152152

153+
public static void setState(String uuid, int state) {
154+
Connection conn = VoiceConnectionService.getConnection(uuid);
155+
if (conn == null) {
156+
Log.w(TAG, "[VoiceConnectionService] setState ignored because no connection found, uuid: " + uuid);
157+
return;
158+
}
159+
160+
switch (state) {
161+
case Connection.STATE_ACTIVE:
162+
conn.setActive();
163+
break;
164+
case Connection.STATE_DIALING:
165+
conn.setDialing();
166+
break;
167+
case Connection.STATE_HOLDING:
168+
conn.setOnHold();
169+
break;
170+
case Connection.STATE_INITIALIZING:
171+
conn.setInitializing();
172+
break;
173+
case Connection.STATE_RINGING:
174+
conn.setRinging();
175+
break;
176+
}
177+
}
178+
153179
@Override
154180
public Connection onCreateIncomingConnection(PhoneAccountHandle connectionManagerPhoneAccount, ConnectionRequest request) {
155181
Bundle extra = request.getExtras();

index.d.ts

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -168,8 +168,11 @@ declare module 'react-native-callkeep' {
168168
* @param routeSpeaker
169169
*/
170170
static toggleAudioRouteSpeaker(uuid: string, routeSpeaker: boolean): void
171+
171172
static setOnHold(uuid: string, held: boolean): void
172173

174+
static setConnectionState(uuid: string, state: number): void
175+
173176
/**
174177
* @descriptions sendDTMF is used to send DTMF tones to the PBX.
175178
*/

index.js

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -257,6 +257,8 @@ class RNCallKeep {
257257

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

260+
setConnectionState = (uuid, state) => isIOS ? null : RNCallKeepModule.setConnectionState(uuid, state);
261+
260262
setReachable = () => RNCallKeepModule.setReachable();
261263

262264
// @deprecated

0 commit comments

Comments
 (0)