"Fossies" - the Fresh Open Source Software Archive

Member "jitsi-meet-5079/ios/sdk/src/ExternalAPI.m" (17 Jun 2021, 6936 Bytes) of package /linux/misc/jitsi-meet-5079.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 @ 2017-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 "ExternalAPI.h"
   18 #import "JitsiMeetView+Private.h"
   19 
   20 // Events
   21 static NSString * const hangUpAction = @"org.jitsi.meet.HANG_UP";
   22 static NSString * const setAudioMutedAction = @"org.jitsi.meet.SET_AUDIO_MUTED";
   23 static NSString * const sendEndpointTextMessageAction = @"org.jitsi.meet.SEND_ENDPOINT_TEXT_MESSAGE";
   24 static NSString * const toggleScreenShareAction = @"org.jitsi.meet.TOGGLE_SCREEN_SHARE";
   25 static NSString * const retrieveParticipantsInfoAction = @"org.jitsi.meet.RETRIEVE_PARTICIPANTS_INFO";
   26 static NSString * const openChatAction = @"org.jitsi.meet.OPEN_CHAT";
   27 static NSString * const closeChatAction = @"org.jitsi.meet.CLOSE_CHAT";
   28 static NSString * const sendChatMessageAction = @"org.jitsi.meet.SEND_CHAT_MESSAGE";
   29 static NSString * const setVideoMutedAction = @"org.jitsi.meet.SET_VIDEO_MUTED";
   30 
   31 @implementation ExternalAPI
   32 
   33 static NSMapTable<NSString*, void (^)(NSArray* participantsInfo)> *participantInfoCompletionHandlers;
   34 
   35 __attribute__((constructor))
   36 static void initializeViewsMap() {
   37     participantInfoCompletionHandlers = [NSMapTable strongToStrongObjectsMapTable];
   38 }
   39 
   40 RCT_EXPORT_MODULE();
   41 
   42 - (NSDictionary *)constantsToExport {
   43     return @{
   44         @"HANG_UP": hangUpAction,
   45         @"SET_AUDIO_MUTED" : setAudioMutedAction,
   46         @"SEND_ENDPOINT_TEXT_MESSAGE": sendEndpointTextMessageAction,
   47         @"TOGGLE_SCREEN_SHARE": toggleScreenShareAction,
   48         @"RETRIEVE_PARTICIPANTS_INFO": retrieveParticipantsInfoAction,
   49         @"OPEN_CHAT": openChatAction,
   50         @"CLOSE_CHAT": closeChatAction,
   51         @"SEND_CHAT_MESSAGE": sendChatMessageAction,
   52         @"SET_VIDEO_MUTED" : setVideoMutedAction
   53     };
   54 };
   55 
   56 /**
   57  * Make sure all methods in this module are invoked on the main/UI thread.
   58  */
   59 - (dispatch_queue_t)methodQueue {
   60     return dispatch_get_main_queue();
   61 }
   62 
   63 + (BOOL)requiresMainQueueSetup {
   64     return NO;
   65 }
   66 
   67 - (NSArray<NSString *> *)supportedEvents {
   68     return @[ hangUpAction,
   69               setAudioMutedAction,
   70               sendEndpointTextMessageAction,
   71               toggleScreenShareAction,
   72               retrieveParticipantsInfoAction,
   73               openChatAction,
   74               closeChatAction,
   75               sendChatMessageAction,
   76               setVideoMutedAction
   77     ];
   78 }
   79 
   80 /**
   81  * Dispatches an event that occurred on JavaScript to the view's delegate.
   82  *
   83  * @param name The name of the event.
   84  * @param data The details/specifics of the event to send determined
   85  * by/associated with the specified `name`.
   86  * @param scope
   87  */
   88 RCT_EXPORT_METHOD(sendEvent:(NSString *)name
   89                        data:(NSDictionary *)data
   90                       scope:(NSString *)scope) {
   91     // The JavaScript App needs to provide uniquely identifying information to
   92     // the native ExternalAPI module so that the latter may match the former
   93     // to the native JitsiMeetView which hosts it.
   94     JitsiMeetView *view = [JitsiMeetView viewForExternalAPIScope:scope];
   95 
   96     if (!view) {
   97         return;
   98     }
   99 
  100     id delegate = view.delegate;
  101 
  102     if (!delegate) {
  103         return;
  104     }
  105     
  106     if ([name isEqual: @"PARTICIPANTS_INFO_RETRIEVED"]) {
  107         [self onParticipantsInfoRetrieved: data];
  108         return;
  109     }
  110 
  111     SEL sel = NSSelectorFromString([self methodNameFromEventName:name]);
  112 
  113     if (sel && [delegate respondsToSelector:sel]) {
  114         [delegate performSelector:sel withObject:data];
  115     }
  116 }
  117 
  118 - (void) onParticipantsInfoRetrieved:(NSDictionary *)data {
  119     NSArray *participantsInfoArray = [data objectForKey:@"participantsInfo"];
  120     NSString *completionHandlerId = [data objectForKey:@"requestId"];
  121     
  122     void (^completionHandler)(NSArray*) = [participantInfoCompletionHandlers objectForKey:completionHandlerId];
  123     completionHandler(participantsInfoArray);
  124     [participantInfoCompletionHandlers removeObjectForKey:completionHandlerId];
  125 }
  126 
  127 /**
  128  * Converts a specific event name i.e. redux action type description to a
  129  * method name.
  130  *
  131  * @param eventName The event name to convert to a method name.
  132  * @return A method name constructed from the specified `eventName`.
  133  */
  134 - (NSString *)methodNameFromEventName:(NSString *)eventName {
  135    NSMutableString *methodName
  136        = [NSMutableString stringWithCapacity:eventName.length];
  137 
  138    for (NSString *c in [eventName componentsSeparatedByString:@"_"]) {
  139        if (c.length) {
  140            [methodName appendString:
  141                methodName.length ? c.capitalizedString : c.lowercaseString];
  142        }
  143    }
  144    [methodName appendString:@":"];
  145 
  146    return methodName;
  147 }
  148 
  149 - (void)sendHangUp {
  150     [self sendEventWithName:hangUpAction body:nil];
  151 }
  152 
  153 - (void)sendSetAudioMuted:(BOOL)muted {
  154     NSDictionary *data = @{ @"muted": [NSNumber numberWithBool:muted]};
  155 
  156     [self sendEventWithName:setAudioMutedAction body:data];
  157 }
  158 
  159 - (void)sendEndpointTextMessage:(NSString*)message :(NSString*)to {
  160     NSMutableDictionary *data = [[NSMutableDictionary alloc] init];
  161     data[@"to"] = to;
  162     data[@"message"] = message;
  163     
  164     [self sendEventWithName:sendEndpointTextMessageAction body:data];
  165 }
  166 
  167 - (void)toggleScreenShare:(BOOL)enabled {
  168     NSMutableDictionary *data = [[NSMutableDictionary alloc] init];
  169     data[@"enabled"] = [NSNumber numberWithBool:enabled];
  170     
  171     [self sendEventWithName:toggleScreenShareAction body:data];
  172 }
  173 
  174 - (void)retrieveParticipantsInfo:(void (^)(NSArray*))completionHandler {
  175     NSString *completionHandlerId = [[NSUUID UUID] UUIDString];
  176     NSDictionary *data = @{ @"requestId": completionHandlerId};
  177     
  178     [participantInfoCompletionHandlers setObject:[completionHandler copy] forKey:completionHandlerId];
  179     
  180     [self sendEventWithName:retrieveParticipantsInfoAction body:data];
  181 }
  182 
  183 - (void)openChat:(NSString*)to {
  184     NSMutableDictionary *data = [[NSMutableDictionary alloc] init];
  185     data[@"to"] = to;
  186     
  187     [self sendEventWithName:openChatAction body:data];
  188 }
  189 
  190 - (void)closeChat {
  191     [self sendEventWithName:closeChatAction body:nil];
  192 }
  193 
  194 - (void)sendChatMessage:(NSString*)message :(NSString*)to {
  195     NSMutableDictionary *data = [[NSMutableDictionary alloc] init];
  196     data[@"to"] = to;
  197     data[@"message"] = message;
  198     
  199     [self sendEventWithName:sendChatMessageAction body:data];
  200 }
  201 
  202 - (void)sendSetVideoMuted:(BOOL)muted {
  203     NSDictionary *data = @{ @"muted": [NSNumber numberWithBool:muted]};
  204 
  205     [self sendEventWithName:setVideoMutedAction body:data];
  206 }
  207 
  208 
  209 @end