|
|
@@ -22,36 +22,49 @@
|
|
22
|
22
|
#import <Foundation/Foundation.h>
|
|
23
|
23
|
#import <UIKit/UIKit.h>
|
|
24
|
24
|
|
|
|
25
|
+@import CallKit;
|
|
|
26
|
+
|
|
25
|
27
|
#import <React/RCTBridge.h>
|
|
26
|
28
|
#import <React/RCTConvert.h>
|
|
27
|
|
-#import <React/RCTEventEmitter.h>
|
|
28
|
29
|
#import <React/RCTEventDispatcher.h>
|
|
|
30
|
+#import <React/RCTEventEmitter.h>
|
|
29
|
31
|
#import <React/RCTUtils.h>
|
|
30
|
32
|
|
|
31
|
|
-// Weakly load CallKit, because it's not available on iOS 9.
|
|
32
|
|
-@import CallKit;
|
|
33
|
|
-
|
|
34
|
|
-
|
|
35
|
|
-// Events we will emit.
|
|
36
|
|
-static NSString *const RNCallKitPerformAnswerCallAction = @"performAnswerCallAction";
|
|
37
|
|
-static NSString *const RNCallKitPerformEndCallAction = @"performEndCallAction";
|
|
38
|
|
-static NSString *const RNCallKitPerformSetMutedCallAction = @"performSetMutedCallAction";
|
|
39
|
|
-static NSString *const RNCallKitProviderDidReset = @"providerDidReset";
|
|
40
|
|
-
|
|
|
33
|
+// The events emitted/supported by RNCallKit:
|
|
|
34
|
+static NSString * const RNCallKitPerformAnswerCallAction
|
|
|
35
|
+ = @"performAnswerCallAction";
|
|
|
36
|
+static NSString * const RNCallKitPerformEndCallAction
|
|
|
37
|
+ = @"performEndCallAction";
|
|
|
38
|
+static NSString * const RNCallKitPerformSetMutedCallAction
|
|
|
39
|
+ = @"performSetMutedCallAction";
|
|
|
40
|
+static NSString * const RNCallKitProviderDidReset
|
|
|
41
|
+ = @"providerDidReset";
|
|
41
|
42
|
|
|
42
|
43
|
@interface RNCallKit : RCTEventEmitter <CXProviderDelegate>
|
|
43
|
44
|
@end
|
|
44
|
45
|
|
|
45
|
46
|
@implementation RNCallKit
|
|
46
|
47
|
{
|
|
47
|
|
- CXCallController *callKitCallController;
|
|
48
|
|
- CXProvider *callKitProvider;
|
|
|
48
|
+ CXCallController *_callController;
|
|
|
49
|
+ CXProvider *_provider;
|
|
49
|
50
|
}
|
|
50
|
51
|
|
|
51
|
|
-RCT_EXPORT_MODULE()
|
|
|
52
|
+RCT_EXTERN void RCTRegisterModule(Class);
|
|
52
|
53
|
|
|
53
|
|
-- (NSArray<NSString *> *)supportedEvents
|
|
54
|
|
-{
|
|
|
54
|
++ (void)load {
|
|
|
55
|
+ // Make the react-native module RNCallKit available (to JS) only if CallKit
|
|
|
56
|
+ // is available on the executing operating sytem. For example, CallKit is
|
|
|
57
|
+ // not available on iOS 9.
|
|
|
58
|
+ if ([CXCallController class]) {
|
|
|
59
|
+ RCTRegisterModule(self);
|
|
|
60
|
+ }
|
|
|
61
|
+}
|
|
|
62
|
+
|
|
|
63
|
++ (NSString *)moduleName {
|
|
|
64
|
+ return @"RNCallKit";
|
|
|
65
|
+}
|
|
|
66
|
+
|
|
|
67
|
+- (NSArray<NSString *> *)supportedEvents {
|
|
55
|
68
|
return @[
|
|
56
|
69
|
RNCallKitPerformAnswerCallAction,
|
|
57
|
70
|
RNCallKitPerformEndCallAction,
|
|
|
@@ -60,33 +73,17 @@ RCT_EXPORT_MODULE()
|
|
60
|
73
|
];
|
|
61
|
74
|
}
|
|
62
|
75
|
|
|
63
|
|
-// Configure CallKit
|
|
64
|
|
-RCT_EXPORT_METHOD(setup:(NSDictionary *)options)
|
|
65
|
|
-{
|
|
66
|
|
-#ifdef DEBUG
|
|
67
|
|
- NSLog(@"[RNCallKit][setup] options = %@", options);
|
|
68
|
|
-#endif
|
|
69
|
|
- callKitCallController = [[CXCallController alloc] init];
|
|
70
|
|
- if (callKitProvider) {
|
|
71
|
|
- [callKitProvider invalidate];
|
|
72
|
|
- }
|
|
73
|
|
- callKitProvider = [[CXProvider alloc] initWithConfiguration:[self getProviderConfiguration: options]];
|
|
74
|
|
- [callKitProvider setDelegate:self queue:nil];
|
|
75
|
|
-}
|
|
76
|
|
-
|
|
77
|
|
-#pragma mark - CXCallController call actions
|
|
78
|
|
-
|
|
79
|
76
|
// Display the incoming call to the user
|
|
80
|
|
-RCT_EXPORT_METHOD(displayIncomingCall:(NSString *)uuidString
|
|
|
77
|
+RCT_EXPORT_METHOD(displayIncomingCall:(NSString *)callUUID
|
|
81
|
78
|
handle:(NSString *)handle
|
|
82
|
79
|
hasVideo:(BOOL)hasVideo
|
|
83
|
80
|
resolve:(RCTPromiseResolveBlock)resolve
|
|
84
|
|
- reject:(RCTPromiseRejectBlock)reject)
|
|
85
|
|
-{
|
|
|
81
|
+ reject:(RCTPromiseRejectBlock)reject) {
|
|
86
|
82
|
#ifdef DEBUG
|
|
87
|
|
- NSLog(@"[RNCallKit][displayIncomingCall] uuidString = %@", uuidString);
|
|
|
83
|
+ NSLog(@"[RNCallKit][displayIncomingCall] callUUID = %@", callUUID);
|
|
88
|
84
|
#endif
|
|
89
|
|
- NSUUID *uuid = [[NSUUID alloc] initWithUUIDString:uuidString];
|
|
|
85
|
+
|
|
|
86
|
+ NSUUID *callUUID_ = [[NSUUID alloc] initWithUUIDString:callUUID];
|
|
90
|
87
|
CXCallUpdate *callUpdate = [[CXCallUpdate alloc] init];
|
|
91
|
88
|
callUpdate.remoteHandle
|
|
92
|
89
|
= [[CXHandle alloc] initWithType:CXHandleTypeGeneric value:handle];
|
|
|
@@ -95,149 +92,208 @@ RCT_EXPORT_METHOD(displayIncomingCall:(NSString *)uuidString
|
|
95
|
92
|
callUpdate.supportsGrouping = NO;
|
|
96
|
93
|
callUpdate.supportsUngrouping = NO;
|
|
97
|
94
|
callUpdate.hasVideo = hasVideo;
|
|
98
|
|
-
|
|
99
|
|
- [callKitProvider reportNewIncomingCallWithUUID:uuid
|
|
100
|
|
- update:callUpdate
|
|
101
|
|
- completion:^(NSError * _Nullable error) {
|
|
102
|
|
- if (error == nil) {
|
|
103
|
|
- resolve(nil);
|
|
104
|
|
- } else {
|
|
|
95
|
+
|
|
|
96
|
+ [self.provider reportNewIncomingCallWithUUID:callUUID_
|
|
|
97
|
+ update:callUpdate
|
|
|
98
|
+ completion:^(NSError * _Nullable error) {
|
|
|
99
|
+ if (error) {
|
|
105
|
100
|
reject(nil, @"Error reporting new incoming call", error);
|
|
|
101
|
+ } else {
|
|
|
102
|
+ resolve(nil);
|
|
106
|
103
|
}
|
|
107
|
104
|
}];
|
|
108
|
105
|
}
|
|
109
|
106
|
|
|
110
|
107
|
// End call
|
|
111
|
|
-RCT_EXPORT_METHOD(endCall:(NSString *)uuidString
|
|
|
108
|
+RCT_EXPORT_METHOD(endCall:(NSString *)callUUID
|
|
112
|
109
|
resolve:(RCTPromiseResolveBlock)resolve
|
|
113
|
|
- reject:(RCTPromiseRejectBlock)reject)
|
|
114
|
|
-{
|
|
|
110
|
+ reject:(RCTPromiseRejectBlock)reject) {
|
|
115
|
111
|
#ifdef DEBUG
|
|
116
|
|
- NSLog(@"[RNCallKit][endCall] uuidString = %@", uuidString);
|
|
|
112
|
+ NSLog(@"[RNCallKit][endCall] callUUID = %@", callUUID);
|
|
117
|
113
|
#endif
|
|
118
|
|
- NSUUID *uuid = [[NSUUID alloc] initWithUUIDString:uuidString];
|
|
119
|
|
- CXEndCallAction *action = [[CXEndCallAction alloc] initWithCallUUID:uuid];
|
|
120
|
|
- CXTransaction *transaction = [[CXTransaction alloc] initWithAction:action];
|
|
121
|
|
- [self requestTransaction:transaction resolve:resolve reject:reject];
|
|
|
114
|
+
|
|
|
115
|
+ NSUUID *callUUID_ = [[NSUUID alloc] initWithUUIDString:callUUID];
|
|
|
116
|
+ CXEndCallAction *action
|
|
|
117
|
+ = [[CXEndCallAction alloc] initWithCallUUID:callUUID_];
|
|
|
118
|
+ [self requestTransaction:[[CXTransaction alloc] initWithAction:action]
|
|
|
119
|
+ resolve:resolve
|
|
|
120
|
+ reject:reject];
|
|
122
|
121
|
}
|
|
123
|
122
|
|
|
124
|
123
|
// Mute / unmute (audio)
|
|
125
|
|
-RCT_EXPORT_METHOD(setMuted:(NSString *)uuidString
|
|
126
|
|
- muted:(BOOL) muted
|
|
127
|
|
- resolve:(RCTPromiseResolveBlock)resolve
|
|
128
|
|
- reject:(RCTPromiseRejectBlock)reject)
|
|
129
|
|
-{
|
|
|
124
|
+RCT_EXPORT_METHOD(setMuted:(NSString *)callUUID
|
|
|
125
|
+ muted:(BOOL)muted
|
|
|
126
|
+ resolve:(RCTPromiseResolveBlock)resolve
|
|
|
127
|
+ reject:(RCTPromiseRejectBlock)reject) {
|
|
130
|
128
|
#ifdef DEBUG
|
|
131
|
|
- NSLog(@"[RNCallKit][setMuted] uuidString = %@", uuidString);
|
|
|
129
|
+ NSLog(@"[RNCallKit][setMuted] callUUID = %@", callUUID);
|
|
132
|
130
|
#endif
|
|
133
|
|
- NSUUID *uuid = [[NSUUID alloc] initWithUUIDString:uuidString];
|
|
|
131
|
+
|
|
|
132
|
+ NSUUID *callUUID_ = [[NSUUID alloc] initWithUUIDString:callUUID];
|
|
134
|
133
|
CXSetMutedCallAction *action
|
|
135
|
|
- = [[CXSetMutedCallAction alloc] initWithCallUUID:uuid muted:muted];
|
|
136
|
|
- CXTransaction *transaction = [[CXTransaction alloc] initWithAction:action];
|
|
137
|
|
- [self requestTransaction:transaction resolve:resolve reject:reject];
|
|
|
134
|
+ = [[CXSetMutedCallAction alloc] initWithCallUUID:callUUID_ muted:muted];
|
|
|
135
|
+ [self requestTransaction:[[CXTransaction alloc] initWithAction:action]
|
|
|
136
|
+ resolve:resolve
|
|
|
137
|
+ reject:reject];
|
|
|
138
|
+}
|
|
|
139
|
+
|
|
|
140
|
+RCT_EXPORT_METHOD(setProviderConfiguration:(NSDictionary *)dictionary) {
|
|
|
141
|
+#ifdef DEBUG
|
|
|
142
|
+ NSLog(
|
|
|
143
|
+ @"[RNCallKit][setProviderConfiguration:] dictionary = %@",
|
|
|
144
|
+ dictionary);
|
|
|
145
|
+#endif
|
|
|
146
|
+
|
|
|
147
|
+ CXProviderConfiguration *configuration
|
|
|
148
|
+ = [self providerConfigurationFromDictionary:dictionary];
|
|
|
149
|
+ if (_provider) {
|
|
|
150
|
+ _provider.configuration = configuration;
|
|
|
151
|
+ } else {
|
|
|
152
|
+ _provider = [[CXProvider alloc] initWithConfiguration:configuration];
|
|
|
153
|
+ [_provider setDelegate:self queue:nil];
|
|
|
154
|
+ }
|
|
138
|
155
|
}
|
|
139
|
156
|
|
|
140
|
157
|
// Start outgoing call
|
|
141
|
|
-RCT_EXPORT_METHOD(startCall:(NSString *)uuidString
|
|
|
158
|
+RCT_EXPORT_METHOD(startCall:(NSString *)callUUID
|
|
142
|
159
|
handle:(NSString *)handle
|
|
143
|
160
|
video:(BOOL)video
|
|
144
|
161
|
resolve:(RCTPromiseResolveBlock)resolve
|
|
145
|
|
- reject:(RCTPromiseRejectBlock)reject)
|
|
146
|
|
-{
|
|
|
162
|
+ reject:(RCTPromiseRejectBlock)reject) {
|
|
147
|
163
|
#ifdef DEBUG
|
|
148
|
|
- NSLog(@"[RNCallKit][startCall] uuidString = %@", uuidString);
|
|
|
164
|
+ NSLog(@"[RNCallKit][startCall] callUUID = %@", callUUID);
|
|
149
|
165
|
#endif
|
|
150
|
|
- NSUUID *uuid = [[NSUUID alloc] initWithUUIDString:uuidString];
|
|
151
|
|
- CXHandle *callHandle
|
|
|
166
|
+
|
|
|
167
|
+ NSUUID *callUUID_ = [[NSUUID alloc] initWithUUIDString:callUUID];
|
|
|
168
|
+ CXHandle *handle_
|
|
152
|
169
|
= [[CXHandle alloc] initWithType:CXHandleTypeGeneric value:handle];
|
|
153
|
170
|
CXStartCallAction *action
|
|
154
|
|
- = [[CXStartCallAction alloc] initWithCallUUID:uuid handle:callHandle];
|
|
|
171
|
+ = [[CXStartCallAction alloc] initWithCallUUID:callUUID_
|
|
|
172
|
+ handle:handle_];
|
|
155
|
173
|
action.video = video;
|
|
156
|
174
|
CXTransaction *transaction = [[CXTransaction alloc] initWithAction:action];
|
|
157
|
175
|
[self requestTransaction:transaction resolve:resolve reject:reject];
|
|
158
|
176
|
}
|
|
159
|
177
|
|
|
160
|
178
|
// Indicate call failed
|
|
161
|
|
-RCT_EXPORT_METHOD(reportCallFailed:(NSString *)uuidString
|
|
162
|
|
- resolve:(RCTPromiseResolveBlock)resolve
|
|
163
|
|
- reject:(RCTPromiseRejectBlock)reject)
|
|
164
|
|
-{
|
|
165
|
|
- NSUUID *uuid = [[NSUUID alloc] initWithUUIDString:uuidString];
|
|
166
|
|
- [callKitProvider reportCallWithUUID:uuid
|
|
167
|
|
- endedAtDate:[NSDate date]
|
|
168
|
|
- reason:CXCallEndedReasonFailed];
|
|
|
179
|
+RCT_EXPORT_METHOD(reportCallFailed:(NSString *)callUUID
|
|
|
180
|
+ resolve:(RCTPromiseResolveBlock)resolve
|
|
|
181
|
+ reject:(RCTPromiseRejectBlock)reject) {
|
|
|
182
|
+ NSUUID *callUUID_ = [[NSUUID alloc] initWithUUIDString:callUUID];
|
|
|
183
|
+ [self.provider reportCallWithUUID:callUUID_
|
|
|
184
|
+ endedAtDate:[NSDate date]
|
|
|
185
|
+ reason:CXCallEndedReasonFailed];
|
|
169
|
186
|
resolve(nil);
|
|
170
|
187
|
}
|
|
171
|
188
|
|
|
172
|
|
-// Indicate outgoing call connected
|
|
173
|
|
-RCT_EXPORT_METHOD(reportConnectedOutgoingCall:(NSString *)uuidString
|
|
174
|
|
- resolve:(RCTPromiseResolveBlock)resolve
|
|
175
|
|
- reject:(RCTPromiseRejectBlock)reject)
|
|
176
|
|
-{
|
|
177
|
|
- NSUUID *uuid = [[NSUUID alloc] initWithUUIDString:uuidString];
|
|
178
|
|
- [callKitProvider reportOutgoingCallWithUUID:uuid
|
|
179
|
|
- connectedAtDate:[NSDate date]];
|
|
|
189
|
+// Indicate outgoing call connected.
|
|
|
190
|
+RCT_EXPORT_METHOD(reportConnectedOutgoingCall:(NSString *)callUUID
|
|
|
191
|
+ resolve:(RCTPromiseResolveBlock)resolve
|
|
|
192
|
+ reject:(RCTPromiseRejectBlock)reject) {
|
|
|
193
|
+ NSUUID *callUUID_ = [[NSUUID alloc] initWithUUIDString:callUUID];
|
|
|
194
|
+ [self.provider reportOutgoingCallWithUUID:callUUID_
|
|
|
195
|
+ connectedAtDate:[NSDate date]];
|
|
180
|
196
|
resolve(nil);
|
|
181
|
197
|
}
|
|
182
|
198
|
|
|
183
|
|
-// Update call in case we have a display name or video capability changes
|
|
184
|
|
-RCT_EXPORT_METHOD(updateCall:(NSString *)uuidString
|
|
|
199
|
+// Update call in case we have a display name or video capability changes.
|
|
|
200
|
+RCT_EXPORT_METHOD(updateCall:(NSString *)callUUID
|
|
185
|
201
|
options:(NSDictionary *)options
|
|
186
|
202
|
resolve:(RCTPromiseResolveBlock)resolve
|
|
187
|
|
- reject:(RCTPromiseRejectBlock)reject)
|
|
188
|
|
-{
|
|
|
203
|
+ reject:(RCTPromiseRejectBlock)reject) {
|
|
189
|
204
|
#ifdef DEBUG
|
|
190
|
|
- NSLog(@"[RNCallKit][updateCall] uuidString = %@ options = %@", uuidString, options);
|
|
|
205
|
+ NSLog(
|
|
|
206
|
+ @"[RNCallKit][updateCall] callUUID = %@ options = %@",
|
|
|
207
|
+ callUUID,
|
|
|
208
|
+ options);
|
|
191
|
209
|
#endif
|
|
192
|
|
- NSUUID *uuid = [[NSUUID alloc] initWithUUIDString:uuidString];
|
|
193
|
|
- CXCallUpdate *update = [[CXCallUpdate alloc] init];
|
|
|
210
|
+
|
|
|
211
|
+ NSUUID *callUUID_ = [[NSUUID alloc] initWithUUIDString:callUUID];
|
|
|
212
|
+ CXCallUpdate *callUpdate = [[CXCallUpdate alloc] init];
|
|
194
|
213
|
if (options[@"displayName"]) {
|
|
195
|
|
- update.localizedCallerName = options[@"displayName"];
|
|
|
214
|
+ callUpdate.localizedCallerName = options[@"displayName"];
|
|
196
|
215
|
}
|
|
197
|
216
|
if (options[@"hasVideo"]) {
|
|
198
|
|
- update.hasVideo = [(NSNumber*)options[@"hasVideo"] boolValue];
|
|
|
217
|
+ callUpdate.hasVideo = [(NSNumber*)options[@"hasVideo"] boolValue];
|
|
199
|
218
|
}
|
|
200
|
|
- [callKitProvider reportCallWithUUID:uuid updated:update];
|
|
|
219
|
+ [self.provider reportCallWithUUID:callUUID_ updated:callUpdate];
|
|
201
|
220
|
resolve(nil);
|
|
202
|
221
|
}
|
|
203
|
222
|
|
|
204
|
223
|
#pragma mark - Helper methods
|
|
205
|
224
|
|
|
206
|
|
-- (CXProviderConfiguration *)getProviderConfiguration:(NSDictionary* )settings
|
|
207
|
|
-{
|
|
|
225
|
+- (CXCallController *)callController {
|
|
|
226
|
+ if (!_callController) {
|
|
|
227
|
+ _callController = [[CXCallController alloc] init];
|
|
|
228
|
+ }
|
|
|
229
|
+
|
|
|
230
|
+ return _callController;
|
|
|
231
|
+}
|
|
|
232
|
+
|
|
|
233
|
+- (CXProvider *)provider {
|
|
|
234
|
+ if (!_provider) {
|
|
|
235
|
+ [self setProviderConfiguration:nil];
|
|
|
236
|
+ }
|
|
|
237
|
+
|
|
|
238
|
+ return _provider;
|
|
|
239
|
+}
|
|
|
240
|
+
|
|
|
241
|
+- (CXProviderConfiguration *)providerConfigurationFromDictionary:(NSDictionary* )dictionary {
|
|
208
|
242
|
#ifdef DEBUG
|
|
209
|
|
- NSLog(@"[RNCallKit][getProviderConfiguration]");
|
|
|
243
|
+ NSLog(@"[RNCallKit][providerConfigurationFromDictionary:]");
|
|
210
|
244
|
#endif
|
|
|
245
|
+
|
|
|
246
|
+ if (!dictionary) {
|
|
|
247
|
+ dictionary = @{};
|
|
|
248
|
+ }
|
|
|
249
|
+
|
|
|
250
|
+ // localizedName
|
|
|
251
|
+ NSString *localizedName = dictionary[@"localizedName"];
|
|
|
252
|
+ if (!localizedName) {
|
|
|
253
|
+ localizedName
|
|
|
254
|
+ = [[NSBundle mainBundle] infoDictionary][@"CFBundleDisplayName"];
|
|
|
255
|
+ }
|
|
|
256
|
+
|
|
211
|
257
|
CXProviderConfiguration *providerConfiguration
|
|
212
|
|
- = [[CXProviderConfiguration alloc] initWithLocalizedName:settings[@"appName"]];
|
|
213
|
|
- providerConfiguration.supportsVideo = YES;
|
|
|
258
|
+ = [[CXProviderConfiguration alloc] initWithLocalizedName:localizedName];
|
|
|
259
|
+
|
|
|
260
|
+ // iconTemplateImageData
|
|
|
261
|
+ NSString *iconTemplateImageName = dictionary[@"iconTemplateImageName"];
|
|
|
262
|
+ if (iconTemplateImageName) {
|
|
|
263
|
+ UIImage *iconTemplateImage = [UIImage imageNamed:iconTemplateImageName];
|
|
|
264
|
+ if (iconTemplateImage) {
|
|
|
265
|
+ providerConfiguration.iconTemplateImageData
|
|
|
266
|
+ = UIImagePNGRepresentation(iconTemplateImage);
|
|
|
267
|
+ }
|
|
|
268
|
+ }
|
|
|
269
|
+
|
|
214
|
270
|
providerConfiguration.maximumCallGroups = 1;
|
|
215
|
271
|
providerConfiguration.maximumCallsPerCallGroup = 1;
|
|
|
272
|
+ providerConfiguration.ringtoneSound = dictionary[@"ringtoneSound"];
|
|
216
|
273
|
providerConfiguration.supportedHandleTypes
|
|
217
|
|
- = [NSSet setWithObjects:[NSNumber numberWithInteger:CXHandleTypeGeneric], nil];
|
|
218
|
|
- if (settings[@"imageName"]) {
|
|
219
|
|
- providerConfiguration.iconTemplateImageData
|
|
220
|
|
- = UIImagePNGRepresentation([UIImage imageNamed:settings[@"imageName"]]);
|
|
221
|
|
- }
|
|
222
|
|
- if (settings[@"ringtoneSound"]) {
|
|
223
|
|
- providerConfiguration.ringtoneSound = settings[@"ringtoneSound"];
|
|
224
|
|
- }
|
|
|
274
|
+ = [NSSet setWithObjects:@(CXHandleTypeGeneric), nil];
|
|
|
275
|
+ providerConfiguration.supportsVideo = YES;
|
|
|
276
|
+
|
|
225
|
277
|
return providerConfiguration;
|
|
226
|
278
|
}
|
|
227
|
279
|
|
|
228
|
280
|
- (void)requestTransaction:(CXTransaction *)transaction
|
|
229
|
281
|
resolve:(RCTPromiseResolveBlock)resolve
|
|
230
|
|
- reject:(RCTPromiseRejectBlock)reject
|
|
231
|
|
-{
|
|
|
282
|
+ reject:(RCTPromiseRejectBlock)reject {
|
|
232
|
283
|
#ifdef DEBUG
|
|
233
|
284
|
NSLog(@"[RNCallKit][requestTransaction] transaction = %@", transaction);
|
|
234
|
285
|
#endif
|
|
235
|
|
- [callKitCallController requestTransaction:transaction completion:^(NSError * _Nullable error) {
|
|
236
|
|
- if (error == nil) {
|
|
237
|
|
- resolve(nil);
|
|
238
|
|
- } else {
|
|
239
|
|
- NSLog(@"[RNCallKit][requestTransaction] Error requesting transaction (%@): (%@)", transaction.actions, error);
|
|
|
286
|
+
|
|
|
287
|
+ [self.callController requestTransaction:transaction
|
|
|
288
|
+ completion:^(NSError * _Nullable error) {
|
|
|
289
|
+ if (error) {
|
|
|
290
|
+ NSLog(
|
|
|
291
|
+ @"[RNCallKit][requestTransaction] Error requesting transaction (%@): (%@)",
|
|
|
292
|
+ transaction.actions,
|
|
|
293
|
+ error);
|
|
240
|
294
|
reject(nil, @"Error processing CallKit transaction", error);
|
|
|
295
|
+ } else {
|
|
|
296
|
+ resolve(nil);
|
|
241
|
297
|
}
|
|
242
|
298
|
}];
|
|
243
|
299
|
}
|
|
|
@@ -247,53 +303,62 @@ RCT_EXPORT_METHOD(updateCall:(NSString *)uuidString
|
|
247
|
303
|
// Called when the provider has been reset. We should terminate all calls.
|
|
248
|
304
|
- (void)providerDidReset:(CXProvider *)provider {
|
|
249
|
305
|
#ifdef DEBUG
|
|
250
|
|
- NSLog(@"[RNCallKit][CXProviderDelegate][provider:providerDidReset]");
|
|
|
306
|
+ NSLog(@"[RNCallKit][CXProviderDelegate][providerDidReset:]");
|
|
251
|
307
|
#endif
|
|
|
308
|
+
|
|
252
|
309
|
[self sendEventWithName:RNCallKitProviderDidReset body:nil];
|
|
253
|
310
|
}
|
|
254
|
311
|
|
|
255
|
312
|
// Answering incoming call
|
|
256
|
|
-- (void)provider:(CXProvider *)provider performAnswerCallAction:(CXAnswerCallAction *)action
|
|
257
|
|
-{
|
|
|
313
|
+- (void) provider:(CXProvider *)provider
|
|
|
314
|
+ performAnswerCallAction:(CXAnswerCallAction *)action {
|
|
258
|
315
|
#ifdef DEBUG
|
|
259
|
|
- NSLog(@"[RNCallKit][CXProviderDelegate][provider:performAnswerCallAction]");
|
|
|
316
|
+ NSLog(@"[RNCallKit][CXProviderDelegate][provider:performAnswerCallAction:]");
|
|
260
|
317
|
#endif
|
|
|
318
|
+
|
|
261
|
319
|
[self sendEventWithName:RNCallKitPerformAnswerCallAction
|
|
262
|
320
|
body:@{ @"callUUID": action.callUUID.UUIDString }];
|
|
263
|
321
|
[action fulfill];
|
|
264
|
322
|
}
|
|
265
|
323
|
|
|
266
|
324
|
// Call ended, user request
|
|
267
|
|
-- (void)provider:(CXProvider *)provider performEndCallAction:(CXEndCallAction *)action
|
|
268
|
|
-{
|
|
|
325
|
+- (void) provider:(CXProvider *)provider
|
|
|
326
|
+ performEndCallAction:(CXEndCallAction *)action {
|
|
269
|
327
|
#ifdef DEBUG
|
|
270
|
|
- NSLog(@"[RNCallKit][CXProviderDelegate][provider:performEndCallAction]");
|
|
|
328
|
+ NSLog(@"[RNCallKit][CXProviderDelegate][provider:performEndCallAction:]");
|
|
271
|
329
|
#endif
|
|
|
330
|
+
|
|
272
|
331
|
[self sendEventWithName:RNCallKitPerformEndCallAction
|
|
273
|
332
|
body:@{ @"callUUID": action.callUUID.UUIDString }];
|
|
274
|
333
|
[action fulfill];
|
|
275
|
334
|
}
|
|
276
|
335
|
|
|
277
|
336
|
// Handle audio mute from CallKit view
|
|
278
|
|
-- (void)provider:(CXProvider *)provider performSetMutedCallAction:(CXSetMutedCallAction *)action {
|
|
|
337
|
+- (void) provider:(CXProvider *)provider
|
|
|
338
|
+ performSetMutedCallAction:(CXSetMutedCallAction *)action {
|
|
279
|
339
|
#ifdef DEBUG
|
|
280
|
|
- NSLog(@"[RNCallKit][CXProviderDelegate][provider:performSetMutedCallAction]");
|
|
|
340
|
+ NSLog(@"[RNCallKit][CXProviderDelegate][provider:performSetMutedCallAction:]");
|
|
281
|
341
|
#endif
|
|
|
342
|
+
|
|
282
|
343
|
[self sendEventWithName:RNCallKitPerformSetMutedCallAction
|
|
283
|
|
- body:@{ @"callUUID": action.callUUID.UUIDString,
|
|
284
|
|
- @"muted": [NSNumber numberWithBool:action.muted]}];
|
|
|
344
|
+ body:@{
|
|
|
345
|
+ @"callUUID": action.callUUID.UUIDString,
|
|
|
346
|
+ @"muted": @(action.muted)
|
|
|
347
|
+ }];
|
|
285
|
348
|
[action fulfill];
|
|
286
|
349
|
}
|
|
287
|
350
|
|
|
288
|
351
|
// Starting outgoing call
|
|
289
|
|
-- (void)provider:(CXProvider *)provider performStartCallAction:(CXStartCallAction *)action
|
|
290
|
|
-{
|
|
|
352
|
+- (void) provider:(CXProvider *)provider
|
|
|
353
|
+ performStartCallAction:(CXStartCallAction *)action {
|
|
291
|
354
|
#ifdef DEBUG
|
|
292
|
|
- NSLog(@"[RNCallKit][CXProviderDelegate][provider:performStartCallAction]");
|
|
|
355
|
+ NSLog(@"[RNCallKit][CXProviderDelegate][provider:performStartCallAction:]");
|
|
293
|
356
|
#endif
|
|
|
357
|
+
|
|
294
|
358
|
[action fulfill];
|
|
295
|
|
-
|
|
296
|
|
- // Update call info
|
|
|
359
|
+
|
|
|
360
|
+ // Update call info.
|
|
|
361
|
+ NSUUID *callUUID = action.callUUID;
|
|
297
|
362
|
CXCallUpdate *callUpdate = [[CXCallUpdate alloc] init];
|
|
298
|
363
|
callUpdate.remoteHandle = action.handle;
|
|
299
|
364
|
callUpdate.supportsDTMF = NO;
|
|
|
@@ -301,34 +366,31 @@ RCT_EXPORT_METHOD(updateCall:(NSString *)uuidString
|
|
301
|
366
|
callUpdate.supportsGrouping = NO;
|
|
302
|
367
|
callUpdate.supportsUngrouping = NO;
|
|
303
|
368
|
callUpdate.hasVideo = action.isVideo;
|
|
304
|
|
- [callKitProvider reportCallWithUUID:action.callUUID updated:callUpdate];
|
|
305
|
|
-
|
|
306
|
|
- // Notify the system about the outgoing call
|
|
307
|
|
- [callKitProvider reportOutgoingCallWithUUID:action.callUUID
|
|
308
|
|
- startedConnectingAtDate:[NSDate date]];
|
|
309
|
|
-}
|
|
|
369
|
+ [provider reportCallWithUUID:callUUID updated:callUpdate];
|
|
310
|
370
|
|
|
311
|
|
-// These just help with debugging
|
|
|
371
|
+ // Notify the system about the outgoing call.
|
|
|
372
|
+ [provider reportOutgoingCallWithUUID:callUUID
|
|
|
373
|
+ startedConnectingAtDate:[NSDate date]];
|
|
|
374
|
+}
|
|
312
|
375
|
|
|
313
|
|
-- (void)provider:(CXProvider *)provider didActivateAudioSession:(AVAudioSession *)audioSession
|
|
314
|
|
-{
|
|
|
376
|
+// The following just help with debugging:
|
|
315
|
377
|
#ifdef DEBUG
|
|
316
|
|
- NSLog(@"[RNCallKit][CXProviderDelegate][provider:didActivateAudioSession]");
|
|
317
|
|
-#endif
|
|
|
378
|
+
|
|
|
379
|
+- (void) provider:(CXProvider *)provider
|
|
|
380
|
+ didActivateAudioSession:(AVAudioSession *)audioSession {
|
|
|
381
|
+ NSLog(@"[RNCallKit][CXProviderDelegate][provider:didActivateAudioSession:]");
|
|
318
|
382
|
}
|
|
319
|
383
|
|
|
320
|
|
-- (void)provider:(CXProvider *)provider didDeactivateAudioSession:(AVAudioSession *)audioSession
|
|
321
|
|
-{
|
|
322
|
|
-#ifdef DEBUG
|
|
323
|
|
- NSLog(@"[RNCallKit][CXProviderDelegate][provider:didDeactivateAudioSession]");
|
|
324
|
|
-#endif
|
|
|
384
|
+- (void) provider:(CXProvider *)provider
|
|
|
385
|
+ didDeactivateAudioSession:(AVAudioSession *)audioSession {
|
|
|
386
|
+ NSLog(@"[RNCallKit][CXProviderDelegate][provider:didDeactivateAudioSession:]");
|
|
325
|
387
|
}
|
|
326
|
388
|
|
|
327
|
|
-- (void)provider:(CXProvider *)provider timedOutPerformingAction:(CXAction *)action
|
|
328
|
|
-{
|
|
329
|
|
-#ifdef DEBUG
|
|
330
|
|
- NSLog(@"[RNCallKit][CXProviderDelegate][provider:timedOutPerformingAction]");
|
|
331
|
|
-#endif
|
|
|
389
|
+- (void) provider:(CXProvider *)provider
|
|
|
390
|
+ timedOutPerformingAction:(CXAction *)action {
|
|
|
391
|
+ NSLog(@"[RNCallKit][CXProviderDelegate][provider:timedOutPerformingAction:]");
|
|
332
|
392
|
}
|
|
333
|
393
|
|
|
|
394
|
+#endif
|
|
|
395
|
+
|
|
334
|
396
|
@end
|