Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 7 additions & 1 deletion actions.js
Original file line number Diff line number Diff line change
Expand Up @@ -15,9 +15,15 @@ const RNCallKeepDidPerformDTMFAction = 'RNCallKeepDidPerformDTMFAction';
const RNCallKeepProviderReset = 'RNCallKeepProviderReset';
const isIOS = Platform.OS === 'ios';

const didReceiveStartCallAction = handler =>
const didReceiveStartCallAction = handler => {
eventEmitter.addListener(RNCallKeepDidReceiveStartCallAction, (data) => handler(data));

if (isIOS) {
// Tell CallKeep that we are ready to receive `RNCallKeepDidReceiveStartCallAction` event and prevent delay
RNCallKeepModule._startCallActionEventListenerAdded();
}
};

const answerCall = handler =>
eventEmitter.addListener(RNCallKeepPerformAnswerCallAction, (data) => handler(data));

Expand Down
34 changes: 21 additions & 13 deletions ios/RNCallKeep/RNCallKeep.m
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,11 @@

#import <AVFoundation/AVAudioSession.h>

static int const DelayInSeconds = 3;
#ifdef DEBUG
static int const OUTGOING_CALL_WAKEUP_DELAY = 10;
#else
static int const OUTGOING_CALL_WAKEUP_DELAY = 5;
#endif

static NSString *const RNCallKeepHandleStartCallNotification = @"RNCallKeepHandleStartCallNotification";
static NSString *const RNCallKeepDidReceiveStartCallAction = @"RNCallKeepDidReceiveStartCallAction";
Expand Down Expand Up @@ -45,15 +49,20 @@ - (instancetype)init
NSLog(@"[RNCallKeep][init]");
#endif
if (self = [super init]) {
[[NSNotificationCenter defaultCenter] addObserver:self
selector:@selector(handleStartCallNotification:)
name:RNCallKeepHandleStartCallNotification
object:nil];
_isStartCallActionEventListenerAdded = NO;
}
return self;
}

+ (id)allocWithZone:(NSZone *)zone {
static RNCallKeep *sharedInstance = nil;
static dispatch_once_t onceToken;
dispatch_once(&onceToken, ^{
sharedInstance = [super allocWithZone:zone];
});
return sharedInstance;
}

- (void)dealloc
{
#ifdef DEBUG
Expand Down Expand Up @@ -281,7 +290,7 @@ - (void)dealloc
CXPlayDTMFCallAction *dtmfAction = [[CXPlayDTMFCallAction alloc] initWithCallUUID:uuid digits:key type:CXPlayDTMFCallActionTypeHardPause];
CXTransaction *transaction = [[CXTransaction alloc] init];
[transaction addAction:dtmfAction];

[self requestTransaction:transaction];
}

Expand Down Expand Up @@ -444,9 +453,8 @@ + (BOOL)application:(UIApplication *)application
@"video": @(isVideoCall)
};

[[NSNotificationCenter defaultCenter] postNotificationName:RNCallKeepHandleStartCallNotification
object:self
userInfo:userInfo];
RNCallKeep *callKeep = [RNCallKeep allocWithZone: nil];
[callKeep handleStartCallNotification: userInfo];
return YES;
}
return NO;
Expand All @@ -457,21 +465,21 @@ + (BOOL)requiresMainQueueSetup
return YES;
}

- (void)handleStartCallNotification:(NSNotification *)notification
- (void)handleStartCallNotification:(NSDictionary *)userInfo
{
#ifdef DEBUG
NSLog(@"[RNCallKeep][handleStartCallNotification] userInfo = %@", notification.userInfo);
NSLog(@"[RNCallKeep][handleStartCallNotification] userInfo = %@", userInfo);
#endif
int delayInSeconds;
if (!_isStartCallActionEventListenerAdded) {
// Workaround for when app is just launched and JS side hasn't registered to the event properly
delayInSeconds = DelayInSeconds;
delayInSeconds = OUTGOING_CALL_WAKEUP_DELAY;
} else {
delayInSeconds = 0;
}
dispatch_time_t popTime = dispatch_time(DISPATCH_TIME_NOW, (int64_t)(delayInSeconds * NSEC_PER_SEC));
dispatch_after(popTime, dispatch_get_main_queue(), ^{
[self sendEventWithName:RNCallKeepDidReceiveStartCallAction body:notification.userInfo];
[self sendEventWithName:RNCallKeepDidReceiveStartCallAction body:userInfo];
});
}

Expand Down