Skip to content

Commit af8dd00

Browse files
authored
Merge pull request #38 from aarkalyk/display-incoming-call-callback
Callback for displayIncomingCall method
2 parents b85dc00 + 7eee28b commit af8dd00

File tree

3 files changed

+35
-10
lines changed

3 files changed

+35
-10
lines changed

README.md

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -134,6 +134,8 @@ Initialise RNCallKit with options
134134
- generic
135135
- number (default)
136136
- email
137+
- **hasVideo**: boolean (optional)
138+
- false (default)
137139
- **localizedCallerName**: string (optional)
138140

139141
Call when you receive incoming calls to display system UI
@@ -209,6 +211,12 @@ The `AudioSession` has been activated by **RNCallKit**, you might want to do fol
209211

210212
- Start playing ringback if it is an outgoing call
211213

214+
### - didDisplayIncomingCall
215+
216+
Callback for `RNCallKit.displayIncomingCall`
217+
218+
**error**: string (optional)
219+
212220
## Usage
213221

214222
```javascript
@@ -237,6 +245,7 @@ class RNCallKitExample extends React.Component {
237245
RNCallKit.addEventListener('answerCall', this.onRNCallKitPerformAnswerCallAction);
238246
RNCallKit.addEventListener('endCall', this.onRNCallKitPerformEndCallAction);
239247
RNCallKit.addEventListener('didActivateAudioSession', this.onRNCallKitDidActivateAudioSession);
248+
RNCallKit.addEventListener('didDisplayIncomingCall', this.onRNCallKitDidDisplayIncomingCall);
240249
}
241250

242251
onRNCallKitDidReceiveStartCallAction(data) {
@@ -277,6 +286,12 @@ class RNCallKitExample extends React.Component {
277286
*/
278287
}
279288

289+
onRNCallKitDidDisplayIncomingCall(error) {
290+
/* You will get this event after RNCallKit finishes showing incoming call UI
291+
* You can check if there was an error while displaying
292+
*/
293+
}
294+
280295
// This is a fake function where you can receive incoming call notifications
281296
onIncomingCall() {
282297
// Store the generated uuid somewhere

index.js

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@ const RNCallKitDidReceiveStartCallAction = 'RNCallKitDidReceiveStartCallAction';
1515
const RNCallKitPerformAnswerCallAction = 'RNCallKitPerformAnswerCallAction';
1616
const RNCallKitPerformEndCallAction = 'RNCallKitPerformEndCallAction';
1717
const RNCallKitDidActivateAudioSession = 'RNCallKitDidActivateAudioSession';
18+
const RNCallKitDidDisplayIncomingCall = 'RNCallKitDidDisplayIncomingCall';
1819

1920
export default class RNCallKit {
2021
static addEventListener(type, handler) {
@@ -41,7 +42,13 @@ export default class RNCallKit {
4142
RNCallKitDidActivateAudioSession,
4243
() => { handler(); }
4344
);
45+
} else if (type === 'didDisplayIncomingCall') {
46+
listener = _RNCallKitEmitter.addListener(
47+
RNCallKitDidDisplayIncomingCall,
48+
(data) => { handler(data.error); }
49+
);
4450
}
51+
4552
_callkitEventHandlers.set(handler, listener);
4653
}
4754

ios/RNCallKit/RNCallKit.m

Lines changed: 13 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@
2222
static NSString *const RNCallKitPerformAnswerCallAction = @"RNCallKitPerformAnswerCallAction";
2323
static NSString *const RNCallKitPerformEndCallAction = @"RNCallKitPerformEndCallAction";
2424
static NSString *const RNCallKitDidActivateAudioSession = @"RNCallKitDidActivateAudioSession";
25+
static NSString *const RNCallKitDidDisplayIncomingCall = @"RNCallKitDidDisplayIncomingCall";
2526

2627
@implementation RNCallKit
2728
{
@@ -60,11 +61,12 @@ - (void)dealloc
6061
- (NSArray<NSString *> *)supportedEvents
6162
{
6263
return @[
63-
RNCallKitDidReceiveStartCallAction,
64-
RNCallKitPerformAnswerCallAction,
65-
RNCallKitPerformEndCallAction,
66-
RNCallKitDidActivateAudioSession
67-
];
64+
RNCallKitDidReceiveStartCallAction,
65+
RNCallKitPerformAnswerCallAction,
66+
RNCallKitPerformEndCallAction,
67+
RNCallKitDidActivateAudioSession,
68+
RNCallKitDidDisplayIncomingCall
69+
];
6870
}
6971

7072
RCT_EXPORT_METHOD(setup:(NSDictionary *)options)
@@ -104,6 +106,7 @@ - (void)dealloc
104106
callUpdate.localizedCallerName = localizedCallerName;
105107

106108
[self.callKitProvider reportNewIncomingCallWithUUID:uuid update:callUpdate completion:^(NSError * _Nullable error) {
109+
[self sendEventWithName:RNCallKitDidDisplayIncomingCall body:@{ @"error": error ? error.localizedDescription : @"" }];
107110
if (error == nil) {
108111
// Workaround per https://forums.developer.apple.com/message/169511
109112
if ([self lessThanIos10_2]) {
@@ -309,7 +312,7 @@ + (BOOL)application:(UIApplication *)application
309312

310313
+ (BOOL)application:(UIApplication *)application
311314
continueUserActivity:(NSUserActivity *)userActivity
312-
restorationHandler:(void(^)(NSArray * __nullable restorableObjects))restorationHandler
315+
restorationHandler:(void(^)(NSArray * __nullable restorableObjects))restorationHandler
313316
{
314317
#ifdef DEBUG
315318
NSLog(@"[RNCallKit][application:continueUserActivity]");
@@ -319,25 +322,25 @@ + (BOOL)application:(UIApplication *)application
319322
NSString *handle;
320323
BOOL isAudioCall = [userActivity.activityType isEqualToString:INStartAudioCallIntentIdentifier];
321324
BOOL isVideoCall = [userActivity.activityType isEqualToString:INStartVideoCallIntentIdentifier];
322-
325+
323326
if (isAudioCall) {
324327
INStartAudioCallIntent *startAudioCallIntent = (INStartAudioCallIntent *)interaction.intent;
325328
contact = [startAudioCallIntent.contacts firstObject];
326329
} else if (isVideoCall) {
327330
INStartVideoCallIntent *startVideoCallIntent = (INStartVideoCallIntent *)interaction.intent;
328331
contact = [startVideoCallIntent.contacts firstObject];
329332
}
330-
333+
331334
if (contact != nil) {
332335
handle = contact.personHandle.value;
333336
}
334-
337+
335338
if (handle != nil && handle.length > 0 ){
336339
NSDictionary *userInfo = @{
337340
@"handle": handle,
338341
@"video": @(isVideoCall)
339342
};
340-
343+
341344
[[NSNotificationCenter defaultCenter] postNotificationName:RNCallKitHandleStartCallNotification
342345
object:self
343346
userInfo:userInfo];

0 commit comments

Comments
 (0)