|
@@ -1,5 +1,6 @@
|
1
|
1
|
/*
|
2
|
|
- * Copyright @ 2017-present Atlassian Pty Ltd
|
|
2
|
+ * Copyright @ 2018-present 8x8, Inc.
|
|
3
|
+ * Copyright @ 2017-2018 Atlassian Pty Ltd
|
3
|
4
|
*
|
4
|
5
|
* Licensed under the Apache License, Version 2.0 (the "License");
|
5
|
6
|
* you may not use this file except in compliance with the License.
|
|
@@ -14,62 +15,15 @@
|
14
|
15
|
* limitations under the License.
|
15
|
16
|
*/
|
16
|
17
|
|
17
|
|
-#import <Intents/Intents.h>
|
18
|
|
-
|
19
|
18
|
#include <mach/mach_time.h>
|
20
|
19
|
|
21
|
|
-#import <React/RCTAssert.h>
|
22
|
|
-#import <React/RCTLinkingManager.h>
|
23
|
20
|
#import <React/RCTRootView.h>
|
24
|
21
|
|
25
|
|
-#import <RNGoogleSignin/RNGoogleSignin.h>
|
26
|
|
-
|
27
|
|
-#import "Dropbox.h"
|
|
22
|
+#import "JitsiMeet+Private.h"
|
28
|
23
|
#import "JitsiMeetView+Private.h"
|
29
|
|
-#import "RCTBridgeWrapper.h"
|
30
|
24
|
|
31
|
|
-/**
|
32
|
|
- * A `RCTFatalHandler` implementation which swallows JavaScript errors. In the
|
33
|
|
- * Release configuration, React Native will (intentionally) raise an unhandled
|
34
|
|
- * `NSException` for an unhandled JavaScript error. This will effectively kill
|
35
|
|
- * the application. `_RCTFatal` is suitable to be in accord with the Web i.e.
|
36
|
|
- * not kill the application.
|
37
|
|
- */
|
38
|
|
-RCTFatalHandler _RCTFatal = ^(NSError *error) {
|
39
|
|
- id jsStackTrace = error.userInfo[RCTJSStackTraceKey];
|
40
|
|
- @try {
|
41
|
|
- NSString *name
|
42
|
|
- = [NSString stringWithFormat:@"%@: %@",
|
43
|
|
- RCTFatalExceptionName,
|
44
|
|
- error.localizedDescription];
|
45
|
|
- NSString *message
|
46
|
|
- = RCTFormatError(error.localizedDescription, jsStackTrace, 75);
|
47
|
|
- [NSException raise:name format:@"%@", message];
|
48
|
|
- } @catch (NSException *e) {
|
49
|
|
- if (!jsStackTrace) {
|
50
|
|
- @throw;
|
51
|
|
- }
|
52
|
|
- }
|
53
|
|
-};
|
54
|
25
|
|
55
|
|
-/**
|
56
|
|
- * Helper function to register a fatal error handler for React. Our handler
|
57
|
|
- * won't kill the process, it will swallow JS errors and print stack traces
|
58
|
|
- * instead.
|
59
|
|
- */
|
60
|
|
-void registerFatalErrorHandler() {
|
61
|
|
-#if !DEBUG
|
62
|
|
- // In the Release configuration, React Native will (intentionally) raise an
|
63
|
|
- // unhandled `NSException` for an unhandled JavaScript error. This will
|
64
|
|
- // effectively kill the application. In accord with the Web, do not kill the
|
65
|
|
- // application.
|
66
|
|
- if (!RCTGetFatalHandler()) {
|
67
|
|
- RCTSetFatalHandler(_RCTFatal);
|
68
|
|
- }
|
69
|
|
-#endif
|
70
|
|
-}
|
71
|
|
-
|
72
|
|
-@interface JitsiMeetView() {
|
|
26
|
+@implementation JitsiMeetView {
|
73
|
27
|
/**
|
74
|
28
|
* The unique identifier of this `JitsiMeetView` within the process for the
|
75
|
29
|
* purposes of `ExternalAPI`. The name scope was inspired by postis which we
|
|
@@ -78,98 +32,24 @@ void registerFatalErrorHandler() {
|
78
|
32
|
NSString *externalAPIScope;
|
79
|
33
|
|
80
|
34
|
RCTRootView *rootView;
|
81
|
|
-}
|
82
|
35
|
|
83
|
|
-@end
|
84
|
|
-
|
85
|
|
-@implementation JitsiMeetView {
|
86
|
36
|
NSNumber *_pictureInPictureEnabled;
|
87
|
37
|
}
|
88
|
38
|
|
89
|
39
|
@dynamic pictureInPictureEnabled;
|
90
|
40
|
|
91
|
|
-static NSString *_conferenceActivityType;
|
92
|
|
-
|
93
|
|
-static RCTBridgeWrapper *bridgeWrapper;
|
94
|
|
-
|
95
|
|
-/**
|
96
|
|
- * Copy of the `launchOptions` dictionary that the application was started with.
|
97
|
|
- * It is required for the initial URL to be used if a (Universal) link was used
|
98
|
|
- * to launch a new instance of the application.
|
99
|
|
- */
|
100
|
|
-static NSDictionary *_launchOptions;
|
101
|
|
-
|
102
|
41
|
/**
|
103
|
42
|
* The `JitsiMeetView`s associated with their `ExternalAPI` scopes (i.e. unique
|
104
|
43
|
* identifiers within the process).
|
105
|
44
|
*/
|
106
|
45
|
static NSMapTable<NSString *, JitsiMeetView *> *views;
|
107
|
46
|
|
108
|
|
-+ (BOOL)application:(UIApplication *)application
|
109
|
|
- didFinishLaunchingWithOptions:(NSDictionary *)launchOptions {
|
110
|
|
- // Store launch options, will be used when we create the bridge.
|
111
|
|
- _launchOptions = [launchOptions copy];
|
112
|
|
-
|
113
|
|
- [Dropbox setAppKey];
|
114
|
|
-
|
115
|
|
- return YES;
|
116
|
|
-}
|
117
|
|
-
|
118
|
|
-#pragma mark Linking delegate helpers
|
119
|
|
-// https://facebook.github.io/react-native/docs/linking.html
|
120
|
|
-
|
121
|
|
-+ (BOOL)application:(UIApplication *)application
|
122
|
|
- continueUserActivity:(NSUserActivity *)userActivity
|
123
|
|
- restorationHandler:(void (^)(NSArray *restorableObjects))restorationHandler
|
124
|
|
-{
|
125
|
|
- // XXX At least twice we received bug reports about malfunctioning loadURL
|
126
|
|
- // in the Jitsi Meet SDK while the Jitsi Meet app seemed to functioning as
|
127
|
|
- // expected in our testing. But that was to be expected because the app does
|
128
|
|
- // not exercise loadURL. In order to increase the test coverage of loadURL,
|
129
|
|
- // channel Universal linking through loadURL.
|
130
|
|
-
|
131
|
|
- id url = [self conferenceURLFromUserActivity:userActivity];
|
132
|
|
-
|
133
|
|
- if (url && [self loadURLObjectInViews:url]) {
|
134
|
|
- return YES;
|
135
|
|
- }
|
136
|
|
-
|
137
|
|
- return [RCTLinkingManager application:application
|
138
|
|
- continueUserActivity:userActivity
|
139
|
|
- restorationHandler:restorationHandler];
|
140
|
|
-}
|
141
|
|
-
|
142
|
|
-+ (BOOL)application:(UIApplication *)app
|
143
|
|
- openURL:(NSURL *)url
|
144
|
|
- options:(NSDictionary<UIApplicationOpenURLOptionsKey,id> *)options {
|
145
|
|
- if ([Dropbox application:app openURL:url options:options]) {
|
146
|
|
- return YES;
|
147
|
|
- }
|
148
|
|
-
|
149
|
|
- if ([RNGoogleSignin application:app
|
150
|
|
- openURL:url
|
151
|
|
- sourceApplication:options[UIApplicationOpenURLOptionsSourceApplicationKey]
|
152
|
|
- annotation:options[UIApplicationOpenURLOptionsAnnotationKey]]) {
|
153
|
|
- return YES;
|
154
|
|
- }
|
155
|
|
-
|
156
|
|
- // XXX At least twice we received bug reports about malfunctioning loadURL
|
157
|
|
- // in the Jitsi Meet SDK while the Jitsi Meet app seemed to functioning as
|
158
|
|
- // expected in our testing. But that was to be expected because the app does
|
159
|
|
- // not exercise loadURL. In order to increase the test coverage of loadURL,
|
160
|
|
- // channel Universal linking through loadURL.
|
161
|
|
- if ([self loadURLInViews:url]) {
|
162
|
|
- return YES;
|
163
|
|
- }
|
164
|
|
-
|
165
|
|
- return [RCTLinkingManager application:app openURL:url options:options];
|
166
|
|
-}
|
167
|
|
-
|
168
|
|
-+ (BOOL)application:(UIApplication *)application
|
169
|
|
- openURL:(NSURL *)url
|
170
|
|
- sourceApplication:(NSString *)sourceApplication
|
171
|
|
- annotation:(id)annotation {
|
172
|
|
- return [self application:application openURL:url options:@{}];
|
|
47
|
+/**
|
|
48
|
+ * This gets called automagically when the program starts.
|
|
49
|
+ */
|
|
50
|
+__attribute__((constructor))
|
|
51
|
+static void initializeViewsMap() {
|
|
52
|
+ views = [NSMapTable strongToWeakObjectsMapTable];
|
173
|
53
|
}
|
174
|
54
|
|
175
|
55
|
#pragma mark Initializers
|
|
@@ -201,19 +81,26 @@ static NSMapTable<NSString *, JitsiMeetView *> *views;
|
201
|
81
|
return self;
|
202
|
82
|
}
|
203
|
83
|
|
204
|
|
-#pragma mark API
|
205
|
|
-
|
206
|
84
|
/**
|
207
|
|
- * Loads a specific `NSURL` which may identify a conference to join. If the
|
208
|
|
- * specified `NSURL` is `nil` and the Welcome page is enabled, the Welcome page
|
209
|
|
- * is displayed instead.
|
|
85
|
+ * Internal initialization:
|
210
|
86
|
*
|
211
|
|
- * @param url The `NSURL` to load which may identify a conference to join.
|
|
87
|
+ * - sets the background color
|
|
88
|
+ * - initializes the external API scope
|
212
|
89
|
*/
|
213
|
|
-- (void)loadURL:(NSURL *)url {
|
214
|
|
- [self loadURLString:url ? url.absoluteString : nil];
|
|
90
|
+- (void)initWithXXX {
|
|
91
|
+ // Hook this JitsiMeetView into ExternalAPI.
|
|
92
|
+ externalAPIScope = [NSUUID UUID].UUIDString;
|
|
93
|
+ [views setObject:self forKey:externalAPIScope];
|
|
94
|
+
|
|
95
|
+ // Set a background color which is in accord with the JavaScript and Android
|
|
96
|
+ // parts of the application and causes less perceived visual flicker than
|
|
97
|
+ // the default background color.
|
|
98
|
+ self.backgroundColor
|
|
99
|
+ = [UIColor colorWithRed:.07f green:.07f blue:.07f alpha:1];
|
215
|
100
|
}
|
216
|
101
|
|
|
102
|
+#pragma mark API
|
|
103
|
+
|
217
|
104
|
/**
|
218
|
105
|
* Loads a specific URL which may identify a conference to join. The URL is
|
219
|
106
|
* specified in the form of an `NSDictionary` of properties which (1)
|
|
@@ -224,7 +111,7 @@ static NSMapTable<NSString *, JitsiMeetView *> *views;
|
224
|
111
|
*
|
225
|
112
|
* @param urlObject The URL to load which may identify a conference to join.
|
226
|
113
|
*/
|
227
|
|
-- (void)loadURLObject:(NSDictionary *)urlObject {
|
|
114
|
+- (void)loadURL:(NSDictionary *_Nullable)urlObject {
|
228
|
115
|
NSMutableDictionary *props = [[NSMutableDictionary alloc] init];
|
229
|
116
|
|
230
|
117
|
if (self.defaultURL) {
|
|
@@ -242,14 +129,14 @@ static NSMapTable<NSString *, JitsiMeetView *> *views;
|
242
|
129
|
props[@"url"] = urlObject;
|
243
|
130
|
}
|
244
|
131
|
|
245
|
|
- // XXX The method loadURLObject: is supposed to be imperative i.e. a second
|
|
132
|
+ // XXX The method loadURL: is supposed to be imperative i.e. a second
|
246
|
133
|
// invocation with one and the same URL is expected to join the respective
|
247
|
134
|
// conference again if the first invocation was followed by leaving the
|
248
|
135
|
// conference. However, React and, respectively,
|
249
|
136
|
// appProperties/initialProperties are declarative expressions i.e. one and
|
250
|
137
|
// the same URL will not trigger an automatic re-render in the JavaScript
|
251
|
138
|
// source code. The workaround implemented bellow introduces imperativeness
|
252
|
|
- // in React Component props by defining a unique value per loadURLObject:
|
|
139
|
+ // in React Component props by defining a unique value per loadURL:
|
253
|
140
|
// invocation.
|
254
|
141
|
props[@"timestamp"] = @(mach_absolute_time());
|
255
|
142
|
|
|
@@ -257,8 +144,9 @@ static NSMapTable<NSString *, JitsiMeetView *> *views;
|
257
|
144
|
// Update props with the new URL.
|
258
|
145
|
rootView.appProperties = props;
|
259
|
146
|
} else {
|
|
147
|
+ RCTBridge *bridge = [[JitsiMeet sharedInstance] getReactBridge];
|
260
|
148
|
rootView
|
261
|
|
- = [[RCTRootView alloc] initWithBridge:bridgeWrapper.bridge
|
|
149
|
+ = [[RCTRootView alloc] initWithBridge:bridge
|
262
|
150
|
moduleName:@"App"
|
263
|
151
|
initialProperties:props];
|
264
|
152
|
rootView.backgroundColor = self.backgroundColor;
|
|
@@ -272,28 +160,6 @@ static NSMapTable<NSString *, JitsiMeetView *> *views;
|
272
|
160
|
}
|
273
|
161
|
}
|
274
|
162
|
|
275
|
|
-/**
|
276
|
|
- * Loads a specific URL `NSString` which may identify a conference to
|
277
|
|
- * join. If the specified URL `NSString` is `nil` and the Welcome page is
|
278
|
|
- * enabled, the Welcome page is displayed instead.
|
279
|
|
- *
|
280
|
|
- * @param urlString The URL `NSString` to load which may identify a conference
|
281
|
|
- * to join.
|
282
|
|
- */
|
283
|
|
-- (void)loadURLString:(NSString *)urlString {
|
284
|
|
- [self loadURLObject:urlString ? @{ @"url": urlString } : nil];
|
285
|
|
-}
|
286
|
|
-
|
287
|
|
-#pragma conferenceActivityType getter / setter
|
288
|
|
-
|
289
|
|
-+ (NSString *)conferenceActivityType {
|
290
|
|
- return _conferenceActivityType;
|
291
|
|
-}
|
292
|
|
-
|
293
|
|
-+ (void) setConferenceActivityType:(NSString *)conferenceActivityType {
|
294
|
|
- _conferenceActivityType = conferenceActivityType;
|
295
|
|
-}
|
296
|
|
-
|
297
|
163
|
#pragma pictureInPictureEnabled getter / setter
|
298
|
164
|
|
299
|
165
|
- (void) setPictureInPictureEnabled:(BOOL)pictureInPictureEnabled {
|
|
@@ -318,19 +184,7 @@ static NSMapTable<NSString *, JitsiMeetView *> *views;
|
318
|
184
|
|
319
|
185
|
#pragma mark Private methods
|
320
|
186
|
|
321
|
|
-/**
|
322
|
|
- * Loads a specific `NSURL` in all existing `JitsiMeetView`s.
|
323
|
|
- *
|
324
|
|
- * @param url The `NSURL` to load in all existing `JitsiMeetView`s.
|
325
|
|
- * @return `YES` if the specified `url` was submitted for loading in at least
|
326
|
|
- * one `JitsiMeetView`; otherwise, `NO`.
|
327
|
|
- */
|
328
|
|
-+ (BOOL)loadURLInViews:(NSURL *)url {
|
329
|
|
- return
|
330
|
|
- [self loadURLObjectInViews:url ? @{ @"url": url.absoluteString } : nil];
|
331
|
|
-}
|
332
|
|
-
|
333
|
|
-+ (BOOL)loadURLObjectInViews:(NSDictionary *)urlObject {
|
|
187
|
++ (BOOL)loadURLInViews:(NSDictionary *)urlObject {
|
334
|
188
|
BOOL handled = NO;
|
335
|
189
|
|
336
|
190
|
if (views) {
|
|
@@ -339,7 +193,7 @@ static NSMapTable<NSString *, JitsiMeetView *> *views;
|
339
|
193
|
= [self viewForExternalAPIScope:externalAPIScope];
|
340
|
194
|
|
341
|
195
|
if (view) {
|
342
|
|
- [view loadURLObject:urlObject];
|
|
196
|
+ [view loadURL:urlObject];
|
343
|
197
|
handled = YES;
|
344
|
198
|
}
|
345
|
199
|
}
|
|
@@ -348,79 +202,8 @@ static NSMapTable<NSString *, JitsiMeetView *> *views;
|
348
|
202
|
return handled;
|
349
|
203
|
}
|
350
|
204
|
|
351
|
|
-+ (NSDictionary *)conferenceURLFromUserActivity:(NSUserActivity *)userActivity {
|
352
|
|
- NSString *activityType = userActivity.activityType;
|
353
|
|
-
|
354
|
|
- if ([activityType isEqualToString:NSUserActivityTypeBrowsingWeb]) {
|
355
|
|
- // App was started by opening a URL in the browser
|
356
|
|
- return @{ @"url" : userActivity.webpageURL.absoluteString };
|
357
|
|
- } else if ([activityType isEqualToString:@"INStartAudioCallIntent"]
|
358
|
|
- || [activityType isEqualToString:@"INStartVideoCallIntent"]) {
|
359
|
|
- // App was started by a CallKit Intent
|
360
|
|
- INIntent *intent = userActivity.interaction.intent;
|
361
|
|
- NSArray<INPerson *> *contacts;
|
362
|
|
- NSString *url;
|
363
|
|
- BOOL startAudioOnly = NO;
|
364
|
|
-
|
365
|
|
- if ([intent isKindOfClass:[INStartAudioCallIntent class]]) {
|
366
|
|
- contacts = ((INStartAudioCallIntent *) intent).contacts;
|
367
|
|
- startAudioOnly = YES;
|
368
|
|
- } else if ([intent isKindOfClass:[INStartVideoCallIntent class]]) {
|
369
|
|
- contacts = ((INStartVideoCallIntent *) intent).contacts;
|
370
|
|
- }
|
371
|
|
-
|
372
|
|
- if (contacts && (url = contacts.firstObject.personHandle.value)) {
|
373
|
|
- return @{
|
374
|
|
- @"config": @{@"startAudioOnly":@(startAudioOnly)},
|
375
|
|
- @"url": url
|
376
|
|
- };
|
377
|
|
- }
|
378
|
|
- } else if (_conferenceActivityType && [activityType isEqualToString:_conferenceActivityType]) {
|
379
|
|
- // App was started by continuing a registered NSUserActivity (SiriKit, Handoff, ...)
|
380
|
|
- NSString *url;
|
381
|
|
-
|
382
|
|
- if ((url = userActivity.userInfo[@"url"])) {
|
383
|
|
- return @{ @"url" : url };
|
384
|
|
- }
|
385
|
|
- }
|
386
|
|
-
|
387
|
|
- return nil;
|
388
|
|
-}
|
389
|
|
-
|
390
|
205
|
+ (instancetype)viewForExternalAPIScope:(NSString *)externalAPIScope {
|
391
|
206
|
return [views objectForKey:externalAPIScope];
|
392
|
207
|
}
|
393
|
208
|
|
394
|
|
-/**
|
395
|
|
- * Internal initialization:
|
396
|
|
- *
|
397
|
|
- * - sets the background color
|
398
|
|
- * - creates the React bridge
|
399
|
|
- * - loads the necessary custom fonts
|
400
|
|
- * - registers a custom fatal error error handler for React
|
401
|
|
- */
|
402
|
|
-- (void)initWithXXX {
|
403
|
|
- static dispatch_once_t dispatchOncePredicate;
|
404
|
|
-
|
405
|
|
- dispatch_once(&dispatchOncePredicate, ^{
|
406
|
|
- // Initialize the static state of JitsiMeetView.
|
407
|
|
- bridgeWrapper
|
408
|
|
- = [[RCTBridgeWrapper alloc] initWithLaunchOptions:_launchOptions];
|
409
|
|
- views = [NSMapTable strongToWeakObjectsMapTable];
|
410
|
|
-
|
411
|
|
- // Register a fatal error handler for React.
|
412
|
|
- registerFatalErrorHandler();
|
413
|
|
- });
|
414
|
|
-
|
415
|
|
- // Hook this JitsiMeetView into ExternalAPI.
|
416
|
|
- externalAPIScope = [NSUUID UUID].UUIDString;
|
417
|
|
- [views setObject:self forKey:externalAPIScope];
|
418
|
|
-
|
419
|
|
- // Set a background color which is in accord with the JavaScript and Android
|
420
|
|
- // parts of the application and causes less perceived visual flicker than
|
421
|
|
- // the default background color.
|
422
|
|
- self.backgroundColor
|
423
|
|
- = [UIColor colorWithRed:.07f green:.07f blue:.07f alpha:1];
|
424
|
|
-}
|
425
|
|
-
|
426
|
209
|
@end
|