"Fossies" - the Fresh Open Source Software Archive

Member "jitsi-meet-6193/ios/sdk/src/JitsiMeet.m" (20 May 2022, 7824 Bytes) of package /linux/misc/jitsi-meet-6193.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 #import "RNSplashScreen.h"
   26 #import "ScheenshareEventEmiter.h"
   27 
   28 #import <RNGoogleSignin/RNGoogleSignin.h>
   29 #import <WebRTC/RTCLogging.h>
   30 
   31 @implementation JitsiMeet {
   32     RCTBridgeWrapper *_bridgeWrapper;
   33     NSDictionary *_launchOptions;
   34     ScheenshareEventEmiter *_screenshareEventEmiter;
   35 }
   36 
   37 #pragma mak - This class is a singleton
   38 
   39 + (instancetype)sharedInstance {
   40     static JitsiMeet *sharedInstance = nil;
   41     static dispatch_once_t onceToken;
   42 
   43     dispatch_once(&onceToken, ^{
   44         sharedInstance = [[self alloc] init];
   45     });
   46 
   47     return sharedInstance;
   48 }
   49 
   50 - (instancetype)init {
   51     if (self = [super init]) {
   52         // Initialize the one and only bridge for interfacing with React Native.
   53         _bridgeWrapper = [[RCTBridgeWrapper alloc] init];
   54         
   55         // Initialize the listener for handling start/stop screensharing notifications.
   56         _screenshareEventEmiter = [[ScheenshareEventEmiter alloc] init];
   57 
   58         // Register a fatal error handler for React.
   59         registerReactFatalErrorHandler();
   60 
   61         // Register a log handler for React.
   62         registerReactLogHandler();
   63 
   64 #if 0
   65         // Enable WebRTC logs
   66         RTCSetMinDebugLogLevel(RTCLoggingSeverityInfo);
   67 #endif
   68     }
   69 
   70     return self;
   71 }
   72 
   73 #pragma mark - Methods that the App delegate must call
   74 
   75 -             (BOOL)application:(UIApplication *)application
   76   didFinishLaunchingWithOptions:(NSDictionary *)launchOptions {
   77 
   78     _launchOptions = [launchOptions copy];
   79 
   80     [Dropbox setAppKey];
   81 
   82     return YES;
   83 }
   84 
   85 -    (BOOL)application:(UIApplication *)application
   86   continueUserActivity:(NSUserActivity *)userActivity
   87     restorationHandler:(void (^)(NSArray<id<UIUserActivityRestoring>> *))restorationHandler {
   88 
   89     JitsiMeetConferenceOptions *options = [self optionsFromUserActivity:userActivity];
   90 
   91     return options && [JitsiMeetView setPropsInViews:[options asProps]];
   92 }
   93 
   94 - (BOOL)application:(UIApplication *)app
   95             openURL:(NSURL *)url
   96             options:(NSDictionary<UIApplicationOpenURLOptionsKey,id> *)options {
   97 
   98     if ([Dropbox application:app openURL:url options:options]) {
   99         return YES;
  100     }
  101 
  102     if ([RNGoogleSignin application:app
  103                             openURL:url
  104                             options:options]) {
  105         return YES;
  106     }
  107 
  108     if (_customUrlScheme == nil || ![_customUrlScheme isEqualToString:url.scheme]) {
  109         return NO;
  110     }
  111 
  112     JitsiMeetConferenceOptions *conferenceOptions = [JitsiMeetConferenceOptions fromBuilder:^(JitsiMeetConferenceOptionsBuilder *builder) {
  113         builder.room = [url absoluteString];
  114     }];
  115 
  116     return [JitsiMeetView setPropsInViews:[conferenceOptions asProps]];
  117 }
  118 
  119 #pragma mark - Utility methods
  120 
  121 - (void)instantiateReactNativeBridge {
  122     if (_bridgeWrapper != nil) {
  123         return;
  124     };
  125     
  126     _bridgeWrapper = [[RCTBridgeWrapper alloc] init];
  127 }
  128 
  129 - (void)destroyReactNativeBridge {
  130     [_bridgeWrapper invalidate];
  131     _bridgeWrapper = nil;
  132 }
  133 
  134 - (JitsiMeetConferenceOptions *)getInitialConferenceOptions {
  135     if (_launchOptions[UIApplicationLaunchOptionsURLKey]) {
  136         NSURL *url = _launchOptions[UIApplicationLaunchOptionsURLKey];
  137         return [JitsiMeetConferenceOptions fromBuilder:^(JitsiMeetConferenceOptionsBuilder *builder) {
  138             builder.room = [url absoluteString];
  139         }];
  140     } else {
  141         NSDictionary *userActivityDictionary
  142             = _launchOptions[UIApplicationLaunchOptionsUserActivityDictionaryKey];
  143         NSUserActivity *userActivity
  144             = [userActivityDictionary objectForKey:@"UIApplicationLaunchOptionsUserActivityKey"];
  145         if (userActivity != nil) {
  146             return [self optionsFromUserActivity:userActivity];
  147         }
  148     }
  149 
  150     return nil;
  151 }
  152 
  153 - (BOOL)isCrashReportingDisabled {
  154     NSUserDefaults *userDefaults = [[NSUserDefaults alloc] initWithSuiteName:@"jitsi-default-preferences"];
  155     return [userDefaults stringForKey:@"isCrashReportingDisabled"];
  156 }
  157 
  158 - (JitsiMeetConferenceOptions *)optionsFromUserActivity:(NSUserActivity *)userActivity {
  159     NSString *activityType = userActivity.activityType;
  160 
  161     if ([activityType isEqualToString:NSUserActivityTypeBrowsingWeb]) {
  162         // App was started by opening a URL in the browser
  163         NSURL *url = userActivity.webpageURL;
  164         if ([_universalLinkDomains containsObject:url.host]) {
  165             return [JitsiMeetConferenceOptions fromBuilder:^(JitsiMeetConferenceOptionsBuilder *builder) {
  166                 builder.room = [url absoluteString];
  167             }];
  168         }
  169     } else if ([activityType isEqualToString:@"INStartAudioCallIntent"]
  170                || [activityType isEqualToString:@"INStartVideoCallIntent"]) {
  171         // App was started by a CallKit Intent
  172         INIntent *intent = userActivity.interaction.intent;
  173         NSArray<INPerson *> *contacts;
  174         NSString *url;
  175         BOOL audioOnly = NO;
  176 
  177         if ([intent isKindOfClass:[INStartAudioCallIntent class]]) {
  178             contacts = ((INStartAudioCallIntent *) intent).contacts;
  179             audioOnly = YES;
  180         } else if ([intent isKindOfClass:[INStartVideoCallIntent class]]) {
  181             contacts = ((INStartVideoCallIntent *) intent).contacts;
  182         }
  183 
  184         if (contacts && (url = contacts.firstObject.personHandle.value)) {
  185             return [JitsiMeetConferenceOptions fromBuilder:^(JitsiMeetConferenceOptionsBuilder *builder) {
  186                 builder.audioOnly = audioOnly;
  187                 builder.room = url;
  188             }];
  189         }
  190     } else if (self.conferenceActivityType && [activityType isEqualToString:self.conferenceActivityType]) {
  191         // App was started by continuing a registered NSUserActivity (SiriKit, Handoff, ...)
  192         NSString *url;
  193 
  194         if ((url = userActivity.userInfo[@"url"])) {
  195             return [JitsiMeetConferenceOptions fromBuilder:^(JitsiMeetConferenceOptionsBuilder *builder) {
  196                 builder.room = url;
  197             }];
  198         }
  199     }
  200 
  201     return nil;
  202 }
  203 
  204 - (void)showSplashScreen:(UIView*)rootView {
  205     [RNSplashScreen showSplash:@"LaunchScreen" inRootView:rootView];
  206 }
  207 
  208 #pragma mark - Property getter / setters
  209 
  210 - (NSArray<NSString *> *)universalLinkDomains {
  211     return _universalLinkDomains ? _universalLinkDomains : @[];
  212 }
  213 
  214 - (void)setDefaultConferenceOptions:(JitsiMeetConferenceOptions *)defaultConferenceOptions {
  215     if (defaultConferenceOptions != nil && _defaultConferenceOptions.room != nil) {
  216         @throw [NSException exceptionWithName:@"RuntimeError"
  217                                        reason:@"'room' must be null in the default conference options"
  218                                      userInfo:nil];
  219     }
  220     _defaultConferenceOptions = defaultConferenceOptions;
  221 }
  222 
  223 #pragma mark - Private API methods
  224 
  225 - (NSDictionary *)getDefaultProps {
  226     return _defaultConferenceOptions == nil ? @{} : [_defaultConferenceOptions asProps];
  227 }
  228 
  229 - (RCTBridge *)getReactBridge {
  230     return _bridgeWrapper.bridge;
  231 }
  232 
  233 - (ExternalAPI *)getExternalAPI {
  234     return [_bridgeWrapper.bridge moduleForClass:ExternalAPI.class];
  235 }
  236 
  237 @end