"Fossies" - the Fresh Open Source Software Archive

Member "jitsi-meet-6316/ios/sdk/src/ExternalAPI.m" (5 Jul 2022, 6318 Bytes) of package /linux/misc/jitsi-meet-6316.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. See also the last Fossies "Diffs" side-by-side code changes report for "ExternalAPI.m": 6297_vs_6303.

    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 
   19 // Events
   20 static NSString * const hangUpAction = @"org.jitsi.meet.HANG_UP";
   21 static NSString * const setAudioMutedAction = @"org.jitsi.meet.SET_AUDIO_MUTED";
   22 static NSString * const sendEndpointTextMessageAction = @"org.jitsi.meet.SEND_ENDPOINT_TEXT_MESSAGE";
   23 static NSString * const toggleScreenShareAction = @"org.jitsi.meet.TOGGLE_SCREEN_SHARE";
   24 static NSString * const retrieveParticipantsInfoAction = @"org.jitsi.meet.RETRIEVE_PARTICIPANTS_INFO";
   25 static NSString * const openChatAction = @"org.jitsi.meet.OPEN_CHAT";
   26 static NSString * const closeChatAction = @"org.jitsi.meet.CLOSE_CHAT";
   27 static NSString * const sendChatMessageAction = @"org.jitsi.meet.SEND_CHAT_MESSAGE";
   28 static NSString * const setVideoMutedAction = @"org.jitsi.meet.SET_VIDEO_MUTED";
   29 static NSString * const setClosedCaptionsEnabledAction = @"org.jitsi.meet.SET_CLOSED_CAPTIONS_ENABLED";
   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         @"SET_CLOSED_CAPTIONS_ENABLED": setClosedCaptionsEnabledAction
   54     };
   55 };
   56 
   57 /**
   58  * Make sure all methods in this module are invoked on the main/UI thread.
   59  */
   60 - (dispatch_queue_t)methodQueue {
   61     return dispatch_get_main_queue();
   62 }
   63 
   64 + (BOOL)requiresMainQueueSetup {
   65     return NO;
   66 }
   67 
   68 - (NSArray<NSString *> *)supportedEvents {
   69     return @[ hangUpAction,
   70               setAudioMutedAction,
   71               sendEndpointTextMessageAction,
   72               toggleScreenShareAction,
   73               retrieveParticipantsInfoAction,
   74               openChatAction,
   75               closeChatAction,
   76               sendChatMessageAction,
   77               setVideoMutedAction,
   78               setClosedCaptionsEnabledAction
   79     ];
   80 }
   81 
   82 /**
   83  * Dispatches an event that occurred on JavaScript to the view's delegate.
   84  *
   85  * @param name The name of the event.
   86  * @param data The details/specifics of the event to send determined
   87  * by/associated with the specified `name`.
   88  * @param scope
   89  */
   90 RCT_EXPORT_METHOD(sendEvent:(NSString *)name
   91                        data:(NSDictionary *)data
   92                       scope:(NSString *)scope) {
   93     if ([name isEqual: @"PARTICIPANTS_INFO_RETRIEVED"]) {
   94         [self onParticipantsInfoRetrieved: data];
   95         return;
   96     }
   97     
   98     [[NSNotificationCenter defaultCenter] postNotificationName:sendEventNotificationName
   99                                                         object:nil
  100                                                       userInfo:@{@"name": name, @"data": data}];
  101 }
  102 
  103 - (void) onParticipantsInfoRetrieved:(NSDictionary *)data {
  104     NSArray *participantsInfoArray = [data objectForKey:@"participantsInfo"];
  105     NSString *completionHandlerId = [data objectForKey:@"requestId"];
  106     
  107     void (^completionHandler)(NSArray*) = [participantInfoCompletionHandlers objectForKey:completionHandlerId];
  108     completionHandler(participantsInfoArray);
  109     [participantInfoCompletionHandlers removeObjectForKey:completionHandlerId];
  110 }
  111 
  112 - (void)sendHangUp {
  113     [self sendEventWithName:hangUpAction body:nil];
  114 }
  115 
  116 - (void)sendSetAudioMuted:(BOOL)muted {
  117     NSDictionary *data = @{ @"muted": [NSNumber numberWithBool:muted]};
  118 
  119     [self sendEventWithName:setAudioMutedAction body:data];
  120 }
  121 
  122 - (void)sendEndpointTextMessage:(NSString*)message :(NSString*)to {
  123     NSMutableDictionary *data = [[NSMutableDictionary alloc] init];
  124     data[@"to"] = to;
  125     data[@"message"] = message;
  126     
  127     [self sendEventWithName:sendEndpointTextMessageAction body:data];
  128 }
  129 
  130 - (void)toggleScreenShare:(BOOL)enabled {
  131     NSMutableDictionary *data = [[NSMutableDictionary alloc] init];
  132     data[@"enabled"] = [NSNumber numberWithBool:enabled];
  133     
  134     [self sendEventWithName:toggleScreenShareAction body:data];
  135 }
  136 
  137 - (void)retrieveParticipantsInfo:(void (^)(NSArray*))completionHandler {
  138     NSString *completionHandlerId = [[NSUUID UUID] UUIDString];
  139     NSDictionary *data = @{ @"requestId": completionHandlerId};
  140     
  141     [participantInfoCompletionHandlers setObject:[completionHandler copy] forKey:completionHandlerId];
  142     
  143     [self sendEventWithName:retrieveParticipantsInfoAction body:data];
  144 }
  145 
  146 - (void)openChat:(NSString*)to {
  147     NSMutableDictionary *data = [[NSMutableDictionary alloc] init];
  148     data[@"to"] = to;
  149     
  150     [self sendEventWithName:openChatAction body:data];
  151 }
  152 
  153 - (void)closeChat {
  154     [self sendEventWithName:closeChatAction body:nil];
  155 }
  156 
  157 - (void)sendChatMessage:(NSString*)message :(NSString*)to {
  158     NSMutableDictionary *data = [[NSMutableDictionary alloc] init];
  159     data[@"to"] = to;
  160     data[@"message"] = message;
  161     
  162     [self sendEventWithName:sendChatMessageAction body:data];
  163 }
  164 
  165 - (void)sendSetVideoMuted:(BOOL)muted {
  166     NSDictionary *data = @{ @"muted": [NSNumber numberWithBool:muted]};
  167 
  168     [self sendEventWithName:setVideoMutedAction body:data];
  169 }
  170 
  171 - (void)sendSetClosedCaptionsEnabled:(BOOL)enabled {
  172     NSDictionary *data = @{ @"enabled": [NSNumber numberWithBool:enabled]};
  173 
  174     [self sendEventWithName:setClosedCaptionsEnabledAction body:data];
  175 }
  176 
  177 @end