Skip to content

Commit ff52e5f

Browse files
author
saif
committed
Changes requested from manuquentin
1 parent 71ae82e commit ff52e5f

File tree

2 files changed

+44
-24
lines changed

2 files changed

+44
-24
lines changed

README.md

+25
Original file line numberDiff line numberDiff line change
@@ -219,6 +219,7 @@ Self Managed calling apps are an advanced topic, and there are many steps involv
219219
| [setForegroundServiceSettings()](#setForegroundServiceSettings) | `Promise<void>` | ❌ | ✅ |
220220
| [canMakeMultipleCalls()](#canMakeMultipleCalls) | `Promise<void>` | ❌ | ✅ |
221221
| [setCurrentCallActive()](#setCurrentCallActive) | `Promise<void>` | ❌ | ✅ |
222+
| [checkIsInManagedCall()](#setAvailable) | `Promise<Boolean>` | ❌ | ✅ |
222223
| [isCallActive()](#isCallActive) | `Promise<Boolean>` | ✅ | ❌ |
223224
| [getCalls()](#getCalls) | `Promise<Object[]>` | ✅ | ❌ |
224225
| [displayIncomingCall()](#displayIncomingCall) | `Promise<void>` | ✅ | ✅ |
@@ -316,6 +317,16 @@ RNCallKeep.setCurrentCallActive(uuid);
316317
- `uuid`: string
317318
- The `uuid` used for `startCall` or `displayIncomingCall`
318319

320+
### checkIsInManagedCall
321+
_This feature is available only on Android._
322+
323+
Returns true if there is an active native call
324+
325+
```js
326+
RNCallKeep.checkIsInManagedCall();
327+
```
328+
329+
319330
### isCallActive
320331
_This feature is available only on IOS._
321332

@@ -741,6 +752,7 @@ RNCallKeep.registerAndroidEvents();
741752
| [silenceIncomingCall](#silenceIncomingCall) |||
742753
| [checkReachability](#checkReachability) |||
743754
| [didChangeAudioRoute](#didChangeAudioRoute) |||
755+
| [onHasActiveCall](#onHasActiveCall) |||
744756

745757
### didReceiveStartCallAction
746758

@@ -993,6 +1005,19 @@ RNCallKeep.addEventListener('checkReachability', () => {
9931005

9941006
```
9951007

1008+
### onHasActiveCall
1009+
1010+
_Android only._
1011+
1012+
A listener to tells the JS side if a native call has been answered while there is active self managed call
1013+
1014+
```js
1015+
RNCallKeep.addEventListener('onHasActiveCall', () => {
1016+
// eg: End active app call if native call is answered
1017+
});
1018+
1019+
```
1020+
9961021
## Example
9971022

9981023
A full example is available in the [example](https://github.com/react-native-webrtc/react-native-callkeep/tree/master/example) folder.

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

+19-24
Original file line numberDiff line numberDiff line change
@@ -236,7 +236,6 @@ public void onCallStateChanged(int state, String incomingNumber) {
236236
switch (state) {
237237
case TelephonyManager.CALL_STATE_RINGING:
238238
// Incoming call is ringing (not used for outgoing call).
239-
Log.i("onCallStateChanged", "CALL_STATE_RINGING");
240239
break;
241240
case TelephonyManager.CALL_STATE_OFFHOOK:
242241
// Phone call is active -- off the hook.
@@ -245,22 +244,19 @@ public void onCallStateChanged(int state, String incomingNumber) {
245244

246245
// Only let the JS side know if there is active app call & active native call
247246
if(RNCallKeepModule.this.hasActiveCall && isInManagedCall){
248-
WritableMap args = Arguments.createMap();
249-
RNCallKeepModule.this.sendEventToJS("RNCallKeepHasActiveCall",args);
247+
WritableMap args = Arguments.createMap();
248+
RNCallKeepModule.this.sendEventToJS("RNCallKeepHasActiveCall",args);
250249
}else if(VoiceConnectionService.currentConnections.size() > 0){
251250
// Will enter here for the first time to mark the app has active call
252-
RNCallKeepModule.this.hasActiveCall = true;
251+
RNCallKeepModule.this.hasActiveCall = true;
253252
}
254-
Log.i("onCallStateChanged", "CALL_STATE_OFFHOOK");
255253
break;
256254
case TelephonyManager.CALL_STATE_IDLE:
257255
// Phone is idle before and after phone call.
258256
// If running on version older than 19 (KitKat),
259257
// restart activity when phone call ends.
260-
Log.i("onCallStateChanged", "CALL_STATE_IDLE");
261258
break;
262259
default:
263-
Log.i("onCallStateChanged", "default");
264260
break;
265261
}
266262
}
@@ -273,7 +269,6 @@ public void onCallStateChanged(int state) {
273269
switch (state) {
274270
case TelephonyManager.CALL_STATE_RINGING:
275271
// Incoming call is ringing (not used for outgoing call).
276-
Log.i("onCallStateChanged", "CALL_STATE_RINGING");
277272
break;
278273
case TelephonyManager.CALL_STATE_OFFHOOK:
279274
// Phone call is active -- off the hook.
@@ -289,35 +284,34 @@ public void onCallStateChanged(int state) {
289284
// Will enter here for the first time to mark the app has active call
290285
RNCallKeepModule.this.hasActiveCall = true;
291286
}
292-
Log.i("onCallStateChanged", "CALL_STATE_OFFHOOK");
293287
break;
294288
case TelephonyManager.CALL_STATE_IDLE:
295289
// Phone is idle before and after phone call.
296290
// If running on version older than 19 (KitKat),
297291
// restart activity when phone call ends.
298-
Log.i("onCallStateChanged", "CALL_STATE_IDLE");
299292
break;
300293
default:
301-
Log.i("onCallStateChanged", "default");
302294
break;
303295
}
304296
}
305297
}
306298

307299
public void stopListenToNativeCallsState() {
308-
if(Build.VERSION.SDK_INT >= Build.VERSION_CODES.S && callStateListener !=null){
309-
Log.d(TAG, "[RNCallKeepModule] stopListenToNativeCallsState");
300+
Log.d(TAG, "[RNCallKeepModule] stopListenToNativeCallsState");
301+
302+
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.S && callStateListener !=null){
310303
telephonyManager.unregisterTelephonyCallback(callStateListener);
311-
}else if(Build.VERSION.SDK_INT < Build.VERSION_CODES.S && legacyCallStateListener != null){
304+
} else if (Build.VERSION.SDK_INT < Build.VERSION_CODES.S && legacyCallStateListener != null){
312305
telephonyManager.listen(legacyCallStateListener, PhoneStateListener.LISTEN_NONE);
313306
}
314307
}
315308

316309
public void listenToNativeCallsState() {
310+
Log.d(TAG, "[RNCallKeepModule] listenToNativeCallsState");
317311
Context context = this.getAppContext();
318312
int permissionCheck = ContextCompat.checkSelfPermission(context, Manifest.permission.READ_PHONE_STATE);
313+
319314
if (permissionCheck == PackageManager.PERMISSION_GRANTED) {
320-
Log.d(TAG, "[RNCallKeepModule] listenToNativeCallsState");
321315
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.S) {
322316
callStateListener = new CallStateListener();
323317
telephonyManager.registerTelephonyCallback(context.getMainExecutor(),callStateListener);
@@ -331,14 +325,15 @@ public void listenToNativeCallsState() {
331325
public boolean checkIsInManagedCall() {
332326
Context context = this.getAppContext();
333327
int permissionCheck = ContextCompat.checkSelfPermission(context, Manifest.permission.READ_PHONE_STATE);
328+
334329
if (permissionCheck == PackageManager.PERMISSION_GRANTED) {
335330
return telecomManager.isInManagedCall();
336331
}
337-
return false;
332+
return false;
338333
}
339334

340335
@ReactMethod
341-
public void checkIsInManagedCall(Promise promise) {
336+
public void checkIsInManagedCall(Promise promise) {
342337
boolean isInManagedCall = this.checkIsInManagedCall();
343338
promise.resolve(isInManagedCall);
344339
}
@@ -727,20 +722,20 @@ public void reportEndCallWithUUID(String uuid, int reason) {
727722

728723
@Override
729724
public void onHostResume() {
730-
Log.d(TAG, "onResume()");
725+
731726
}
732727

733728
@Override
734729
public void onHostPause() {
735-
Log.d(TAG, "onPause()");
730+
736731
}
737732

738733
@Override
739734
public void onHostDestroy() {
740-
// when activity destroyed end all calls
741-
Log.d(TAG, "onDestroy()");
735+
// When activity destroyed end all calls
736+
Log.d(TAG, "[RNCallKeepModule] onHostDestroy called");
742737
if (!isConnectionServiceAvailable() || !hasPhoneAccount()) {
743-
Log.w(TAG, "[RNCallKeepModule] endAllCalls ignored due to no ConnectionService or no phone account");
738+
Log.w(TAG, "[RNCallKeepModule] onHostDestroy ignored due to no ConnectionService or no phone account");
744739
return;
745740
}
746741

@@ -751,8 +746,8 @@ public void onHostDestroy() {
751746
connectionToEnd.onDisconnect();
752747
}
753748
this.stopListenToNativeCallsState();
754-
Log.d(TAG, "[RNCallKeepModule] endAllCalls executed");
755-
// this line will kill the android process after ending all calls
749+
Log.d(TAG, "[RNCallKeepModule] onHostDestroy executed");
750+
// This line will kill the android process after ending all calls
756751
android.os.Process.killProcess(android.os.Process.myPid());
757752
}
758753

0 commit comments

Comments
 (0)