Skip to content

Commit 916cbce

Browse files
author
Kyle Kurz
committed
Merge remote-tracking branch 'upstream/master'
2 parents 7d7720f + fd7010b commit 916cbce

File tree

12 files changed

+146
-50
lines changed

12 files changed

+146
-50
lines changed

README.md

Lines changed: 53 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,7 @@ const options = {
5151
}
5252
};
5353

54-
RNCallKeep.setup(options);
54+
RNCallKeep.setup(options).then(accepted => {});
5555
```
5656

5757
- `options`: Object
@@ -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,28 @@ 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, payload }) => {
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)
464+
- `didDisplayIncomingCall` (object)
465+
- VOIP push payload.
431466

432467
### - didPerformSetMutedCallAction
433468

@@ -471,7 +506,7 @@ RNCallKeep.addEventListener('didPerformDTMFAction', ({ digits, callUUID }) => {
471506
- The digits that emit the dtmf tone
472507
- `callUUID` (string)
473508
- The UUID of the call.
474-
509+
475510
### - checkReachability
476511

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

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

617652
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 +661,14 @@ Since iOS 13, you'll have to report the incoming calls that wakes up your applic
626661
- (void)pushRegistry:(PKPushRegistry *)registry didReceiveIncomingPushWithPayload:(PKPushPayload *)payload forType:(PKPushType)type withCompletionHandler:(void (^)(void))completion {
627662
// Process the received push
628663
[RNVoipPushNotificationManager didReceiveIncomingPushWithPayload:payload forType:(NSString *)type];
629-
664+
630665
// Retrieve information like handle and callerName here
631666
// NSString *uuid = /* fetch for payload or ... */ [[[NSUUID UUID] UUIDString] lowercaseString];
632667
// NSString *callerName = @"caller name here";
633668
// NSString *handle = @"caller number here";
634-
635-
[RNCallKeep reportNewIncomingCall:uuid handle:handle handleType:@"generic" hasVideo:false localizedCallerName:callerName fromPushKit: YES];
669+
// 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` */
670+
671+
[RNCallKeep reportNewIncomingCall:uuid handle:handle handleType:@"generic" hasVideo:false localizedCallerName:callerName fromPushKit: YES payload:extra];
636672

637673
completion();
638674
}
@@ -646,6 +682,9 @@ Since iOS 13, you'll have to report the incoming calls that wakes up your applic
646682
adb logcat *:S RNCallKeepModule:V
647683
```
648684

685+
## Troubleshooting
686+
- 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.
687+
649688
## Contributing
650689

651690
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/RNCallKeepModule.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -478,7 +478,7 @@ private Boolean hasPermissions() {
478478
}
479479

480480
private static boolean hasPhoneAccount() {
481-
return isConnectionServiceAvailable() && telecomManager.getPhoneAccount(handle).isEnabled();
481+
return isConnectionServiceAvailable() && telecomManager != null && telecomManager.getPhoneAccount(handle).isEnabled();
482482
}
483483

484484
private void registerReceiver() {

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

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -100,7 +100,7 @@ public void onAnswer() {
100100
setAudioModeIsVoip(true);
101101

102102
sendCallRequestToActivity(ACTION_ANSWER_CALL, handle);
103-
sendCallRequestToActivity(ACTION_AUDIO_SESSION, null);
103+
sendCallRequestToActivity(ACTION_AUDIO_SESSION, handle);
104104
Log.d(TAG, "onAnswer executed");
105105
}
106106

@@ -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
}

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -188,7 +188,7 @@ private Connection makeOutgoingCall(ConnectionRequest request, String uuid, Bool
188188
HashMap<String, String> extrasMap = this.bundleToMap(extras);
189189

190190
sendCallRequestToActivity(ACTION_ONGOING_CALL, extrasMap);
191-
sendCallRequestToActivity(ACTION_AUDIO_SESSION, null);
191+
sendCallRequestToActivity(ACTION_AUDIO_SESSION, extrasMap);
192192

193193
Log.d(TAG, "onCreateOutgoingConnection: calling");
194194

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: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
export type Events =
1+
export type Events =
22
'didReceiveStartCallAction' |
33
'answerCall' |
44
'endCall' |
@@ -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: 15 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() {
@@ -175,7 +187,10 @@ class RNCallKeep {
175187

176188
if (shouldOpenAccounts) {
177189
RNCallKeepModule.openPhoneAccounts();
190+
return true;
178191
}
192+
193+
return false;
179194
};
180195

181196
_hasDefaultPhoneAccount = async (options) => {

ios/RNCallKeep/RNCallKeep.h

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -32,5 +32,9 @@ continueUserActivity:(NSUserActivity *)userActivity
3232
handleType:(NSString *)handleType
3333
hasVideo:(BOOL)hasVideo
3434
localizedCallerName:(NSString * _Nullable)localizedCallerName
35-
fromPushKit:(BOOL)fromPushKit;
36-
@end
35+
fromPushKit:(BOOL)fromPushKit
36+
payload:(NSDictionary * _Nullable)payload;
37+
38+
+ (void)endCallWithUUID:(NSString *)uuidString
39+
reason:(int)reason;
40+
@end

0 commit comments

Comments
 (0)