Skip to content

Commit 55cce2d

Browse files
committed
Merged master
2 parents 62214b9 + 6323479 commit 55cce2d

File tree

7 files changed

+68
-13
lines changed

7 files changed

+68
-13
lines changed

README.md

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -61,6 +61,34 @@ const options = {
6161
RNCallKeep.setup(options).then(accepted => {});
6262
```
6363

64+
iOS only.
65+
66+
Alternative on iOS you can perform setup in `AppDelegate.m`. Doing this allows capturing events prior to the react native event bridge being up. Please be aware that calling setup in `AppDelegate.m` will ignore any subsequent calls to `RNCallKeep.setup();`.
67+
68+
```objective-c
69+
@implementation AppDelegate
70+
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions
71+
{
72+
self.bridge = [[RCTBridge alloc] initWithDelegate:self launchOptions:launchOptions];
73+
74+
[RNCallKeep setup:@{
75+
@"appName": @"Awesome App",
76+
@"maximumCallGroups": @3,
77+
@"maximumCallsPerCallGroup": @1,
78+
@"supportsVideo": @NO,
79+
}];
80+
81+
RCTRootView *rootView = [[RCTRootView alloc] initWithBridge:self.bridge
82+
moduleName:@"App"
83+
initialProperties:nil];
84+
85+
// ======== OTHER CODE REDACTED ==========
86+
87+
return YES;
88+
}
89+
90+
```
91+
6492
- `options`: Object
6593
- `ios`: object
6694
- `appName`: string (required)
@@ -643,6 +671,8 @@ Called as soon as JS context initializes if there were some actions performed by
643671

644672
Since iOS 13, you must display incoming call on receiving PushKit push notification. But if app was killed, it takes some time to create JS context. If user answers the call (or ends it) before JS context has been initialized, user actions will be passed as events array of this event. Similar situation can happen if user would like to start a call from Recents or similar iOS app, assuming that your app was in killed state.
645673

674+
In order for this event to reliably fire, it's necessary to perform setup in `AppDelegate.m`
675+
646676
**NOTE: You still need to subscribe / handle the rest events as usuall. This is just a helper whcih cache and propagate early fired events if and only if for "the native events which DID fire BEFORE js bridge is initialed", it does NOT mean this will have events each time when the app reopened.**
647677

648678
```js

android/build.gradle

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
buildscript {
22
repositories {
3+
mavenCentral()
34
google()
4-
jcenter()
55
}
66

77
dependencies {

docs/android-installation.md

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -60,7 +60,6 @@ public class MainActivity extends ReactActivity {
6060

6161
1. In `android/app/src/main/AndroidManifest.xml` add these permissions:
6262

63-
6463
```xml
6564
<uses-permission android:name="android.permission.BIND_TELECOM_CONNECTION_SERVICE"/>
6665
<uses-permission android:name="android.permission.FOREGROUND_SERVICE" />
@@ -72,7 +71,12 @@ public class MainActivity extends ReactActivity {
7271
<service android:name="io.wazo.callkeep.VoiceConnectionService"
7372
android:label="Wazo"
7473
android:permission="android.permission.BIND_TELECOM_CONNECTION_SERVICE"
75-
android:foregroundServiceType="camera|microphone">>
74+
// Use this to target android >= 11
75+
android:foregroundServiceType="camera|microphone"
76+
// For android < 11
77+
android:foregroundServiceType="phoneCall"
78+
>
79+
7680
<intent-filter>
7781
<action android:name="android.telecom.ConnectionService" />
7882
</intent-filter>
@@ -81,6 +85,8 @@ public class MainActivity extends ReactActivity {
8185
</application>
8286
```
8387

88+
Beware to choose the right `foregroundServiceType` depending on the version of Android you want to target.
89+
8490
2. To be able to wake up your killed application when making an outgoing call form the native Phone application:
8591

8692
Add this in the `application` node of `android/app/src/main/AndroidManifest.xml` :

example/yarn.lock

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -5278,9 +5278,9 @@ xtend@~4.0.1:
52785278
integrity sha512-LKYU1iAXJXUgAXn9URjiu+MWhyUXHsvfp7mcuYm9dSUKK0/CjtrUwFAxD82/mCWbtLsGjFIad0wIsod4zrTAEQ==
52795279

52805280
y18n@^3.2.1:
5281-
version "3.2.1"
5282-
resolved "https://registry.yarnpkg.com/y18n/-/y18n-3.2.1.tgz#6d15fba884c08679c0d77e88e7759e811e07fa41"
5283-
integrity sha1-bRX7qITAhnnA136I53WegR4H+kE=
5281+
version "3.2.2"
5282+
resolved "https://registry.yarnpkg.com/y18n/-/y18n-3.2.2.tgz#85c901bd6470ce71fc4bb723ad209b70f7f28696"
5283+
integrity sha512-uGZHXkHnhF0XeeAPgnKfPv1bgKAYyVvmNL1xlKsPYZPaIHxGti2hHqvOCQv71XMsLxu1QjergkqogUnms5D3YQ==
52845284

52855285
yallist@^2.1.2:
52865286
version "2.1.2"

index.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ const CONSTANTS = {
1717
},
1818
};
1919

20-
export { CONSTANTS };
20+
export { emit, CONSTANTS };
2121

2222
class RNCallKeep {
2323
constructor() {

ios/RNCallKeep/RNCallKeep.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -45,4 +45,6 @@ continueUserActivity:(NSUserActivity *)userActivity
4545

4646
+ (BOOL)isCallActive:(NSString *)uuidString;
4747

48+
+ (void)setup:(NSDictionary *)options;
49+
4850
@end

ios/RNCallKeep/RNCallKeep.m

Lines changed: 23 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@
1212
#import <React/RCTConvert.h>
1313
#import <React/RCTEventDispatcher.h>
1414
#import <React/RCTUtils.h>
15+
#import <React/RCTLog.h>
1516

1617
#import <AVFoundation/AVAudioSession.h>
1718

@@ -43,6 +44,7 @@ @implementation RNCallKeep
4344
NSMutableArray *_delayedEvents;
4445
}
4546

47+
static bool isSetupNatively;
4648
static CXProvider* sharedProvider;
4749

4850
// should initialise in AppDelegate.m
@@ -55,7 +57,7 @@ - (instancetype)init
5557
#endif
5658
if (self = [super init]) {
5759
_isStartCallActionEventListenerAdded = NO;
58-
_delayedEvents = [NSMutableArray array];
60+
if (_delayedEvents == nil) _delayedEvents = [NSMutableArray array];
5961
}
6062
return self;
6163
}
@@ -118,10 +120,11 @@ - (void)sendEventWithNameWrapper:(NSString *)name body:(id)body {
118120
if (_hasListeners) {
119121
[self sendEventWithName:name body:body];
120122
} else {
121-
NSDictionary *dictionary = @{
122-
@"name": name,
123-
@"data": body
124-
};
123+
NSDictionary *dictionary = [NSDictionary dictionaryWithObjectsAndKeys:
124+
name, @"name",
125+
body, @"data",
126+
nil
127+
];
125128
[_delayedEvents addObject:dictionary];
126129
}
127130
}
@@ -133,8 +136,22 @@ + (void)initCallKitProvider {
133136
}
134137
}
135138

139+
+ (void)setup:(NSDictionary *)options {
140+
RNCallKeep *callKeep = [RNCallKeep allocWithZone: nil];
141+
[callKeep setup:options];
142+
isSetupNatively = YES;
143+
}
144+
136145
RCT_EXPORT_METHOD(setup:(NSDictionary *)options)
137146
{
147+
if (isSetupNatively) {
148+
#ifdef DEBUG
149+
NSLog(@"[RNCallKeep][setup] already setup");
150+
RCTLog(@"[RNCallKeep][setup] already setup in native code");
151+
#endif
152+
return;
153+
}
154+
138155
#ifdef DEBUG
139156
NSLog(@"[RNCallKeep][setup] options = %@", options);
140157
#endif
@@ -183,7 +200,7 @@ + (void)initCallKitProvider {
183200
supportsHolding:(BOOL)supportsHolding
184201
supportsDTMF:(BOOL)supportsDTMF
185202
supportsGrouping:(BOOL)supportsGrouping
186-
supportsUngrouping:(BOOL)supportsUngrouping)
203+
supportsUngrouping:(BOOL)supportsUngrouping)
187204
{
188205
[RNCallKeep reportNewIncomingCall: uuidString
189206
handle: handle

0 commit comments

Comments
 (0)