"Fossies" - the Fresh Open Source Software Archive

Member "jitsi-meet-4434/ios/sdk/src/JitsiMeet.m" (25 Sep 2020, 7062 Bytes) of package /linux/misc/jitsi-meet-4434.tar.gz:


As a special service "Fossies" has tried to format the requested source page into HTML format using (guessed) Matlab source code syntax highlighting (style: standard) with prefixed line numbers. Alternatively you can here view or download the uninterpreted source code file.

    1 /*
    2  * Copyright @ 2019-present 8x8, Inc.
    3  *
    4  * Licensed under the Apache License, Version 2.0 (the "License");
    5  * you may not use this file except in compliance with the License.
    6  * You may obtain a copy of the License at
    7  *
    8  *     http://www.apache.org/licenses/LICENSE-2.0
    9  *
   10  * Unless required by applicable law or agreed to in writing, software
   11  * distributed under the License is distributed on an "AS IS" BASIS,
   12  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
   13  * See the License for the specific language governing permissions and
   14  * limitations under the License.
   15  */
   16 
   17 #import <Intents/Intents.h>
   18 
   19 #import "Dropbox.h"
   20 #import "JitsiMeet+Private.h"
   21 #import "JitsiMeetConferenceOptions+Private.h"
   22 #import "JitsiMeetView+Private.h"
   23 #import "RCTBridgeWrapper.h"
   24 #import "ReactUtils.h"
   25 
   26 #import <RNGoogleSignin/RNGoogleSignin.h>
   27 #import <WebRTC/RTCLogging.h>
   28 
   29 
   30 @implementation JitsiMeet {
   31     RCTBridgeWrapper *_bridgeWrapper;
   32     NSDictionary *_launchOptions;
   33 }
   34 
   35 #pragma mak - This class is a singleton
   36 
   37 + (instancetype)sharedInstance {
   38     static JitsiMeet *sharedInstance = nil;
   39     static dispatch_once_t onceToken;
   40 
   41     dispatch_once(&onceToken, ^{
   42         sharedInstance = [[self alloc] init];
   43     });
   44 
   45     return sharedInstance;
   46 }
   47 
   48 - (instancetype)init {
   49     if (self = [super init]) {
   50         // Initialize the on and only bridge for interfacing with React Native.
   51         _bridgeWrapper = [[RCTBridgeWrapper alloc] init];
   52 
   53         // Register a fatal error handler for React.
   54         registerReactFatalErrorHandler();
   55 
   56         // Register a log handler for React.
   57         registerReactLogHandler();
   58 
   59 #if 0
   60         // Enable WebRTC logs
   61         RTCSetMinDebugLogLevel(RTCLoggingSeverityInfo);
   62 #endif
   63     }
   64 
   65     return self;
   66 }
   67 
   68 #pragma mark - Methods that the App delegate must call
   69 
   70 -             (BOOL)application:(UIApplication *)application
   71   didFinishLaunchingWithOptions:(NSDictionary *)launchOptions {
   72 
   73     _launchOptions = [launchOptions copy];
   74 
   75     [Dropbox setAppKey];
   76 
   77     return YES;
   78 }
   79 
   80 -    (BOOL)application:(UIApplication *)application
   81   continueUserActivity:(NSUserActivity *)userActivity
   82     restorationHandler:(void (^)(NSArray<id<UIUserActivityRestoring>> *))restorationHandler {
   83 
   84     JitsiMeetConferenceOptions *options = [self optionsFromUserActivity:userActivity];
   85 
   86     return options && [JitsiMeetView setPropsInViews:[options asProps]];
   87 }
   88 
   89 - (BOOL)application:(UIApplication *)app
   90             openURL:(NSURL *)url
   91             options:(NSDictionary<UIApplicationOpenURLOptionsKey,id> *)options {
   92 
   93     if ([Dropbox application:app openURL:url options:options]) {
   94         return YES;
   95     }
   96 
   97     if ([RNGoogleSignin application:app
   98                             openURL:url
   99                             options:options]) {
  100         return YES;
  101     }
  102 
  103     if (_customUrlScheme == nil || ![_customUrlScheme isEqualToString:url.scheme]) {
  104         return NO;
  105     }
  106 
  107     JitsiMeetConferenceOptions *conferenceOptions = [JitsiMeetConferenceOptions fromBuilder:^(JitsiMeetConferenceOptionsBuilder *builder) {
  108         builder.room = [url absoluteString];
  109     }];
  110 
  111     return [JitsiMeetView setPropsInViews:[conferenceOptions asProps]];
  112 }
  113 
  114 #pragma mark - Utility methods
  115 
  116 - (JitsiMeetConferenceOptions *)getInitialConferenceOptions {
  117     if (_launchOptions[UIApplicationLaunchOptionsURLKey]) {
  118         NSURL *url = _launchOptions[UIApplicationLaunchOptionsURLKey];
  119         return [JitsiMeetConferenceOptions fromBuilder:^(JitsiMeetConferenceOptionsBuilder *builder) {
  120             builder.room = [url absoluteString];
  121         }];
  122     } else {
  123         NSDictionary *userActivityDictionary
  124             = _launchOptions[UIApplicationLaunchOptionsUserActivityDictionaryKey];
  125         NSUserActivity *userActivity
  126             = [userActivityDictionary objectForKey:@"UIApplicationLaunchOptionsUserActivityKey"];
  127         if (userActivity != nil) {
  128             return [self optionsFromUserActivity:userActivity];
  129         }
  130     }
  131 
  132     return nil;
  133 }
  134 
  135 - (BOOL)isCrashReportingDisabled {
  136     NSUserDefaults *userDefaults = [[NSUserDefaults alloc] initWithSuiteName:@"jitsi-default-preferences"];
  137     return [userDefaults stringForKey:@"isCrashReportingDisabled"];
  138 }
  139 
  140 - (JitsiMeetConferenceOptions *)optionsFromUserActivity:(NSUserActivity *)userActivity {
  141     NSString *activityType = userActivity.activityType;
  142 
  143     if ([activityType isEqualToString:NSUserActivityTypeBrowsingWeb]) {
  144         // App was started by opening a URL in the browser
  145         NSURL *url = userActivity.webpageURL;
  146         if ([_universalLinkDomains containsObject:url.host]) {
  147             return [JitsiMeetConferenceOptions fromBuilder:^(JitsiMeetConferenceOptionsBuilder *builder) {
  148                 builder.room = [url absoluteString];
  149             }];
  150         }
  151     } else if ([activityType isEqualToString:@"INStartAudioCallIntent"]
  152                || [activityType isEqualToString:@"INStartVideoCallIntent"]) {
  153         // App was started by a CallKit Intent
  154         INIntent *intent = userActivity.interaction.intent;
  155         NSArray<INPerson *> *contacts;
  156         NSString *url;
  157         BOOL audioOnly = NO;
  158 
  159         if ([intent isKindOfClass:[INStartAudioCallIntent class]]) {
  160             contacts = ((INStartAudioCallIntent *) intent).contacts;
  161             audioOnly = YES;
  162         } else if ([intent isKindOfClass:[INStartVideoCallIntent class]]) {
  163             contacts = ((INStartVideoCallIntent *) intent).contacts;
  164         }
  165 
  166         if (contacts && (url = contacts.firstObject.personHandle.value)) {
  167             return [JitsiMeetConferenceOptions fromBuilder:^(JitsiMeetConferenceOptionsBuilder *builder) {
  168                 builder.audioOnly = audioOnly;
  169                 builder.room = url;
  170             }];
  171         }
  172     } else if (self.conferenceActivityType && [activityType isEqualToString:self.conferenceActivityType]) {
  173         // App was started by continuing a registered NSUserActivity (SiriKit, Handoff, ...)
  174         NSString *url;
  175 
  176         if ((url = userActivity.userInfo[@"url"])) {
  177             return [JitsiMeetConferenceOptions fromBuilder:^(JitsiMeetConferenceOptionsBuilder *builder) {
  178                 builder.room = url;
  179             }];
  180         }
  181     }
  182 
  183     return nil;
  184 }
  185 
  186 #pragma mark - Property getter / setters
  187 
  188 - (NSArray<NSString *> *)universalLinkDomains {
  189     return _universalLinkDomains ? _universalLinkDomains : @[];
  190 }
  191 
  192 - (void)setDefaultConferenceOptions:(JitsiMeetConferenceOptions *)defaultConferenceOptions {
  193     if (defaultConferenceOptions != nil && _defaultConferenceOptions.room != nil) {
  194         @throw [NSException exceptionWithName:@"RuntimeError"
  195                                        reason:@"'room' must be null in the default conference options"
  196                                      userInfo:nil];
  197     }
  198     _defaultConferenceOptions = defaultConferenceOptions;
  199 }
  200 
  201 #pragma mark - Private API methods
  202 
  203 - (NSDictionary *)getDefaultProps {
  204     return _defaultConferenceOptions == nil ? @{} : [_defaultConferenceOptions asProps];
  205 }
  206 
  207 - (RCTBridge *)getReactBridge {
  208     return _bridgeWrapper.bridge;
  209 }
  210 
  211 @end