Skip to content

Commit cf4df08

Browse files
author
Ricardo Corrie
committed
Merge branch 'master' into notification-payload
2 parents 307f6b2 + 8c77cbd commit cf4df08

File tree

9 files changed

+96
-27
lines changed

9 files changed

+96
-27
lines changed

README.md

Lines changed: 48 additions & 12 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
@@ -420,14 +441,26 @@ RNCallKeep.addEventListener('didActivateAudioSession', () => {
420441
Callback for `RNCallKeep.displayIncomingCall`
421442

422443
```js
423-
RNCallKeep.addEventListener('didDisplayIncomingCall', ({ error, uuid, handle, localizedCallerName, fromPushKit }) => {
444+
RNCallKeep.addEventListener('didDisplayIncomingCall', ({ error, callUUID, handle, localizedCallerName, hasVideo, fromPushKit }) => {
424445
// you might want to do following things when receiving this event:
425446
// - Start playing ringback if it is an outgoing call
426447
});
427448
```
428449

429450
- `error` (string)
430451
- iOS only.
452+
- `callUUID` (string)
453+
- The UUID of the call.
454+
- `handle` (string)
455+
- Phone number of the caller
456+
- `localizedCallerName` (string)
457+
- Name of the caller to be displayed on the native UI
458+
- `hasVideo` (string)
459+
- `1` (video enabled)
460+
- `0` (video not enabled)
461+
- `fromPushKit` (string)
462+
- `1` (call triggered from PushKit)
463+
- `0` (call not triggered from PushKit)
431464

432465
### - didPerformSetMutedCallAction
433466

@@ -471,7 +504,7 @@ RNCallKeep.addEventListener('didPerformDTMFAction', ({ digits, callUUID }) => {
471504
- The digits that emit the dtmf tone
472505
- `callUUID` (string)
473506
- The UUID of the call.
474-
507+
475508
### - checkReachability
476509

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

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

617650
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,13 +659,13 @@ Since iOS 13, you'll have to report the incoming calls that wakes up your applic
626659
- (void)pushRegistry:(PKPushRegistry *)registry didReceiveIncomingPushWithPayload:(PKPushPayload *)payload forType:(PKPushType)type withCompletionHandler:(void (^)(void))completion {
627660
// Process the received push
628661
[RNVoipPushNotificationManager didReceiveIncomingPushWithPayload:payload forType:(NSString *)type];
629-
662+
630663
// Retrieve information like handle and callerName here
631664
// NSString *uuid = /* fetch for payload or ... */ [[[NSUUID UUID] UUIDString] lowercaseString];
632665
// NSString *callerName = @"caller name here";
633666
// NSString *handle = @"caller number here";
634667
// NSDictionary *extra = [payload.dictionaryPayload valueForKeyPath:@"custom.path.to.data"]; /* use this to pass any special data (ie. from your notification) down to RN. Can also be `nil` */
635-
668+
636669
[RNCallKeep reportNewIncomingCall:uuid handle:handle handleType:@"generic" hasVideo:false localizedCallerName:callerName fromPushKit: YES payload:extra];
637670

638671
completion();
@@ -647,6 +680,9 @@ Since iOS 13, you'll have to report the incoming calls that wakes up your applic
647680
adb logcat *:S RNCallKeepModule:V
648681
```
649682

683+
## Troubleshooting
684+
- Ensure that you construct a valid `uuid` by importing the `uuid` library and running `uuid.v4()` as shown in the examples. If you don't do this and use a custom string, the incoming call screen will never be shown on iOS.
685+
650686
## Contributing
651687

652688
Any pull request, issue report and suggestion are highly welcome!

RNCallKeep.podspec

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,6 @@ Pod::Spec.new do |s|
1313
s.requires_arc = true
1414
s.platform = :ios, "8.0"
1515
s.source_files = "ios/RNCallKeep/*.{h,m}"
16-
s.dependency 'React/Core'
16+
s.dependency 'React'
1717
end
1818

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
}

example/package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@
1111
"react-dom": "^16.8.6",
1212
"react-native": "0.59.8",
1313
"react-native-background-timer": "^2.1.1",
14-
"react-native-callkeep": "https://github.com/react-native-webrtc/react-native-callkeep#fix_outgoing_call_ios",
14+
"react-native-callkeep": "3.0.7",
1515
"react-native-device-info": "^2.3.2",
1616
"react-native-gesture-handler": "~1.3.0",
1717
"react-native-reanimated": "~1.1.0",

example/yarn.lock

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4132,9 +4132,10 @@ react-native-branch@~3.0.1:
41324132
resolved "https://registry.yarnpkg.com/react-native-branch/-/react-native-branch-3.0.1.tgz#5b07b61cbd290168cd3c3662e017ebe0f356d2ca"
41334133
integrity sha512-vbcYxPZlpF5f39GAEUF8kuGQqCNeD3E6zEdvtOq8oCGZunHXlWlKgAS6dgBKCvsHvXgHuMtpvs39VgOp8DaKig==
41344134

4135-
"react-native-callkeep@https://github.com/react-native-webrtc/react-native-callkeep#fix_outgoing_call_ios":
4136-
version "3.0.1"
4137-
resolved "https://github.com/react-native-webrtc/react-native-callkeep#22a3f2d9f8ede5e83f88d9a16c3786efe249ce1f"
4135+
4136+
version "3.0.7"
4137+
resolved "https://registry.yarnpkg.com/react-native-callkeep/-/react-native-callkeep-3.0.7.tgz#3e9afbfaaf795e74d2b92750d14f144792278467"
4138+
integrity sha512-T0BiCmE2/egDCc4tlVjna5YpQ/4YdUH4uv8e3WlCcM80SpUyKLY6cPwbLXTXhBgF08l260oVUFSNfQX6snUQbg==
41384139

41394140
react-native-device-info@^2.3.2:
41404141
version "2.3.2"

index.d.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -17,9 +17,9 @@ interface IOptions {
1717
ios: {
1818
appName: string,
1919
imageName?: string,
20-
supportsVideo: false,
21-
maximumCallGroups: '1',
22-
maximumCallsPerCallGroup: '1'
20+
supportsVideo?: boolean,
21+
maximumCallGroups?: string,
22+
maximumCallsPerCallGroup?: string,
2323
ringtoneSound?: string,
2424
},
2525
android: {

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: 19 additions & 6 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
}
@@ -345,7 +352,7 @@ + (void)reportNewIncomingCall:(NSString *)uuidString
345352
[RNCallKeep initCallKitProvider];
346353
[sharedProvider reportNewIncomingCallWithUUID:uuid update:callUpdate completion:^(NSError * _Nullable error) {
347354
RNCallKeep *callKeep = [RNCallKeep allocWithZone: nil];
348-
[callKeep sendEventWithName:RNCallKeepDidDisplayIncomingCall body:@{ @"error": error ? error.localizedDescription : @"", @"callUUID": uuidString, @"handle": handle, @"localizedCallerName": localizedCallerName, @"fromPushKit": fromPushKit ? @"1" : @"0", @"payload": payload }];
355+
[callKeep sendEventWithName:RNCallKeepDidDisplayIncomingCall body:@{ @"error": error ? error.localizedDescription : @"", @"callUUID": uuidString, @"handle": handle, @"localizedCallerName": localizedCallerName, @"hasVideo": hasVideo ? @"1" : @"0", @"fromPushKit": fromPushKit ? @"1" : @"0", @"payload": payload }];
349356
if (error == nil) {
350357
// Workaround per https://forums.developer.apple.com/message/169511
351358
if ([callKeep lessThanIos10_2]) {
@@ -472,8 +479,14 @@ + (BOOL)application:(UIApplication *)application
472479
// iOS 13 returns an INStartCallIntent userActivity type
473480
if (@available(iOS 13, *)) {
474481
INStartCallIntent *intent = (INStartCallIntent*)interaction.intent;
475-
isAudioCall = intent.callCapability == INCallCapabilityAudioCall;
476-
isVideoCall = intent.callCapability == INCallCapabilityVideoCall;
482+
// callCapability is not available on iOS > 13.2, but it is in 13.1 weirdly...
483+
if ([intent respondsToSelector:@selector(callCapability)]) {
484+
isAudioCall = intent.callCapability == INCallCapabilityAudioCall;
485+
isVideoCall = intent.callCapability == INCallCapabilityVideoCall;
486+
} else {
487+
isAudioCall = [userActivity.activityType isEqualToString:INStartAudioCallIntentIdentifier];
488+
isVideoCall = [userActivity.activityType isEqualToString:INStartVideoCallIntentIdentifier];
489+
}
477490
} else {
478491
#endif
479492
//XCode 10 and below

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "react-native-callkeep",
3-
"version": "3.0.7",
3+
"version": "3.0.8",
44
"description": "iOS 10 CallKit and Android ConnectionService Framework For React Native",
55
"main": "index.js",
66
"scripts": {},

0 commit comments

Comments
 (0)