Skip to content

Commit 7b36379

Browse files
authored
Merge pull request #133 from nimbleape/add-more-end-reasons
Add more end reasons
2 parents 1d6d537 + 575cff5 commit 7b36379

File tree

4 files changed

+61
-14
lines changed

4 files changed

+61
-14
lines changed

README.md

Lines changed: 32 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -85,6 +85,27 @@ RNCallKeep.setup(options);
8585
Any additional permissions you'd like your app to have at first launch. Can be used to simplify permission flows and avoid
8686
multiple popups to the user at different times.
8787

88+
## Constants
89+
90+
To make passing the right integer into methods easier, there are constants that are exported from the module.
91+
92+
```
93+
const CONSTANTS = {
94+
END_CALL_REASONS: {
95+
FAILED: 1,
96+
REMOTE_ENDED: 2,
97+
UNANSWERED: 3,
98+
ANSWERED_ELSEWHERE: 4,
99+
DECLINED_ELSEWHERE: 5,
100+
MISSED: 6
101+
}
102+
};
103+
104+
const { CONSTANTS as CK_CONSTANTS, RNCallKeep } from 'react-native-callkeep';
105+
106+
console.log(CK_CONSTANTS.END_CALL_REASONS.FAILED) // outputs 1
107+
```
108+
88109
## Methods
89110

90111
### setAvailable
@@ -238,14 +259,14 @@ RNCallKeep.reportEndCallWithUUID(uuid, reason);
238259
- Call failed: 1
239260
- Remote user ended call: 2
240261
- Remote user did not answer: 3
241-
- `CXCallEndedReason` constants used for iOS. `DisconnectCause` used for Android.
242-
- Example enum for reasons
262+
- Call Answered elsewhere: 4
263+
- Call declined elsewhere: 5 (on Android this will map to Remote user ended call if you use the constants)
264+
- Missed: 6 (on iOS this will map to remote user ended call)
265+
- Access reasons as constants
243266
```js
244-
END_CALL_REASON = {
245-
failed: 1,
246-
remoteEnded: 2,
247-
unanswered: 3
248-
}
267+
const { CONSTANTS as CK_CONSTANTS, RNCallKeep } from 'react-native-callkeep';
268+
269+
RNCallKeep.reportEndCallWithUUID(uuid, CK_CONSTANTS.END_CALL_REASONS.FAILED);
249270
```
250271

251272
### setMutedCall
@@ -471,7 +492,7 @@ RNCallKeep.addEventListener('didPerformDTMFAction', ({ digits, callUUID }) => {
471492
- The digits that emit the dtmf tone
472493
- `callUUID` (string)
473494
- The UUID of the call.
474-
495+
475496
### - checkReachability
476497

477498
On Android when the application is in background, after a certain delay the OS will close every connection with informing about it.
@@ -611,7 +632,7 @@ class RNCallKeepExample extends React.Component {
611632
## Receiving a call when the application is not reachable.
612633

613634
In some case your application can be unreachable :
614-
- when the user kill the application
635+
- when the user kill the application
615636
- when it's in background since a long time (eg: after ~5mn the os will kill all connections).
616637

617638
To be able to wake up your application to display the incoming call, you can use [https://github.com/ianlin/react-native-voip-push-notification](react-native-voip-push-notification) on iOS or BackgroundMessaging from [react-native-firebase](https://rnfirebase.io/docs/v5.x.x/messaging/receiving-messages#4)-(Optional)(Android-only)-Listen-for-FCM-messages-in-the-background).
@@ -626,12 +647,12 @@ Since iOS 13, you'll have to report the incoming calls that wakes up your applic
626647
- (void)pushRegistry:(PKPushRegistry *)registry didReceiveIncomingPushWithPayload:(PKPushPayload *)payload forType:(PKPushType)type withCompletionHandler:(void (^)(void))completion {
627648
// Process the received push
628649
[RNVoipPushNotificationManager didReceiveIncomingPushWithPayload:payload forType:(NSString *)type];
629-
650+
630651
// Retrieve information like handle and callerName here
631652
// NSString *uuid = /* fetch for payload or ... */ [[[NSUUID UUID] UUIDString] lowercaseString];
632653
// NSString *callerName = @"caller name here";
633654
// NSString *handle = @"caller number here";
634-
655+
635656
[RNCallKeep reportNewIncomingCall:uuid handle:handle handleType:@"generic" hasVideo:false localizedCallerName:callerName fromPushKit: YES];
636657

637658
completion();

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

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -135,11 +135,18 @@ public void reportDisconnect(int reason) {
135135
setDisconnected(new DisconnectCause(DisconnectCause.ERROR));
136136
break;
137137
case 2:
138+
case 5:
138139
setDisconnected(new DisconnectCause(DisconnectCause.REMOTE));
139140
break;
140141
case 3:
141142
setDisconnected(new DisconnectCause(DisconnectCause.BUSY));
142143
break;
144+
case 4:
145+
setDisconnected(new DisconnectCause(DisconnectCause.ANSWERED_ELSEWHERE));
146+
break;
147+
case 6:
148+
setDisconnected(new DisconnectCause(DisconnectCause.MISSED));
149+
break;
143150
default:
144151
break;
145152
}

index.js

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,18 @@ const RNCallKeepModule = NativeModules.RNCallKeep;
66
const isIOS = Platform.OS === 'ios';
77
const supportConnectionService = !isIOS && Platform.Version >= 23;
88

9+
const CONSTANTS = {
10+
END_CALL_REASONS: {
11+
FAILED: 1,
12+
REMOTE_ENDED: 2,
13+
UNANSWERED: 3,
14+
ANSWERED_ELSEWHERE: 4,
15+
DECLINED_ELSEWHERE: isIOS ? 5 : 2, // make declined elsewhere link to "Remote ended" on android because that's kinda true
16+
MISSED: isIOS ? 2 : 6 }
17+
};
18+
19+
export { CONSTANTS };
20+
921
class RNCallKeep {
1022

1123
constructor() {

ios/RNCallKeep/RNCallKeep.m

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -236,15 +236,22 @@ + (void)initCallKitProvider {
236236
#endif
237237
NSUUID *uuid = [[NSUUID alloc] initWithUUIDString:uuidString];
238238
switch (reason) {
239-
case CXCallEndedReasonFailed:
239+
case 1:
240240
[self.callKeepProvider reportCallWithUUID:uuid endedAtDate:[NSDate date] reason:CXCallEndedReasonFailed];
241241
break;
242-
case CXCallEndedReasonRemoteEnded:
242+
case 2:
243+
case 6:
243244
[self.callKeepProvider reportCallWithUUID:uuid endedAtDate:[NSDate date] reason:CXCallEndedReasonRemoteEnded];
244245
break;
245-
case CXCallEndedReasonUnanswered:
246+
case 3:
246247
[self.callKeepProvider reportCallWithUUID:uuid endedAtDate:[NSDate date] reason:CXCallEndedReasonUnanswered];
247248
break;
249+
case 4:
250+
[self.callKeepProvider reportCallWithUUID:uuid endedAtDate:[NSDate date] reason:CXCallEndedReasonAnsweredElsewhere];
251+
break;
252+
case 5:
253+
[self.callKeepProvider reportCallWithUUID:uuid endedAtDate:[NSDate date] reason:CXCallEndedReasonDeclinedElsewhere];
254+
break;
248255
default:
249256
break;
250257
}

0 commit comments

Comments
 (0)