Skip to content

Commit f9d9c70

Browse files
committed
Introduce hasOutgoingCall for Android background mode
1 parent 8eaacd4 commit f9d9c70

File tree

4 files changed

+28
-1
lines changed

4 files changed

+28
-1
lines changed

README.md

+14
Original file line numberDiff line numberDiff line change
@@ -325,6 +325,20 @@ _This feature is available only on Android._
325325
await RNCallKeep.hasPhoneAccount();
326326
```
327327

328+
### hasOutgoingCall (async)
329+
330+
_This feature is available only on Android, useful when waking up the application for an outgoing call._
331+
332+
When waking up the Android application in background mode (eg: when the application is killed and the user make a call from the native Phone application).
333+
The user can hang up the call before your application has been started in background mode, and you can lost the `RNCallKeepPerformEndCallAction` event.
334+
335+
To be sure that the outgoing call is still here, you can call `hasOutgoingCall` when you app waken up.
336+
337+
338+
```js
339+
const hasOutgoingCall = await RNCallKeep.hasOutgoingCall();
340+
```
341+
328342
### hasDefaultPhoneAccount
329343

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

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

+5
Original file line numberDiff line numberDiff line change
@@ -340,6 +340,11 @@ public void hasPhoneAccount(Promise promise) {
340340
promise.resolve(hasPhoneAccount());
341341
}
342342

343+
@ReactMethod
344+
public void hasOutgoingCall(Promise promise) {
345+
promise.resolve(VoiceConnectionService.hasOutgoingCall);
346+
}
347+
343348
@ReactMethod
344349
public void hasPermissions(Promise promise) {
345350
promise.resolve(this.hasPermissions());

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

+5
Original file line numberDiff line numberDiff line change
@@ -73,6 +73,7 @@ public class VoiceConnectionService extends ConnectionService {
7373
private static Boolean isAvailable = false;
7474
private static String TAG = "RNCK:VoiceConnectionService";
7575
public static Map<String, VoiceConnection> currentConnections = new HashMap<>();
76+
public static Boolean hasOutgoingCall = false;
7677

7778
public static Connection getConnection(String connectionId) {
7879
if (currentConnections.containsKey(connectionId)) {
@@ -93,6 +94,8 @@ public static void setAvailable(Boolean value) {
9394

9495
public static void deinitConnection(String connectionId) {
9596
Log.d(TAG, "deinitConnection:" + connectionId);
97+
VoiceConnectionService.hasOutgoingCall = false;
98+
9699
if (currentConnections.containsKey(connectionId)) {
97100
currentConnections.remove(connectionId);
98101
}
@@ -112,6 +115,8 @@ public Connection onCreateIncomingConnection(PhoneAccountHandle connectionManage
112115

113116
@Override
114117
public Connection onCreateOutgoingConnection(PhoneAccountHandle connectionManagerPhoneAccount, ConnectionRequest request) {
118+
VoiceConnectionService.hasOutgoingCall = true;
119+
115120
Bundle extras = request.getExtras();
116121
Connection outgoingCallConnection = null;
117122
String number = request.getAddress().getSchemeSpecificPart();

index.js

+4-1
Original file line numberDiff line numberDiff line change
@@ -112,13 +112,16 @@ class RNCallKeep {
112112
hasPhoneAccount = async () =>
113113
isIOS ? true : await RNCallKeepModule.hasPhoneAccount();
114114

115+
hasOutgoingCall = async () =>
116+
isIOS ? null : await RNCallKeepModule.hasOutgoingCall();
117+
115118
setMutedCall = (uuid, shouldMute) => {
116119
RNCallKeepModule.setMutedCall(uuid, shouldMute);
117120
};
118121

119122
sendDTMF = (uuid, key) => {
120123
RNCallKeepModule.sendDTMF(uuid, key);
121-
}
124+
};
122125

123126
checkIfBusy = () =>
124127
isIOS

0 commit comments

Comments
 (0)