"Fossies" - the Fresh Open Source Software Archive

Member "jitsi-meet-7309/ios/sdk/src/ExternalAPI.m" (31 May 2023, 6272 Bytes) of package /linux/misc/jitsi-meet-7309.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 
   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     if ([name isEqual: @"PARTICIPANTS_INFO_RETRIEVED"]) {
   93         [self onParticipantsInfoRetrieved: data];
   94         return;
   95     }
   96     
   97     [[NSNotificationCenter defaultCenter] postNotificationName:sendEventNotificationName
   98                                                         object:nil
   99                                                       userInfo:@{@"name": name, @"data": data}];
  100 }
  101 
  102 - (void) onParticipantsInfoRetrieved:(NSDictionary *)data {
  103     NSArray *participantsInfoArray = [data objectForKey:@"participantsInfo"];
  104     NSString *completionHandlerId = [data objectForKey:@"requestId"];
  105     
  106     void (^completionHandler)(NSArray*) = [participantInfoCompletionHandlers objectForKey:completionHandlerId];
  107     completionHandler(participantsInfoArray);
  108     [participantInfoCompletionHandlers removeObjectForKey:completionHandlerId];
  109 }
  110 
  111 - (void)sendHangUp {
  112     [self sendEventWithName:hangUpAction body:nil];
  113 }
  114 
  115 - (void)sendSetAudioMuted:(BOOL)muted {
  116     NSDictionary *data = @{ @"muted": [NSNumber numberWithBool:muted]};
  117 
  118     [self sendEventWithName:setAudioMutedAction body:data];
  119 }
  120 
  121 - (void)sendEndpointTextMessage:(NSString*)message :(NSString*)to {
  122     NSMutableDictionary *data = [[NSMutableDictionary alloc] init];
  123     data[@"to"] = to;
  124     data[@"message"] = message;
  125     
  126     [self sendEventWithName:sendEndpointTextMessageAction body:data];
  127 }
  128 
  129 - (void)toggleScreenShare:(BOOL)enabled {
  130     NSMutableDictionary *data = [[NSMutableDictionary alloc] init];
  131     data[@"enabled"] = [NSNumber numberWithBool:enabled];
  132     
  133     [self sendEventWithName:toggleScreenShareAction body:data];
  134 }
  135 
  136 - (void)retrieveParticipantsInfo:(void (^)(NSArray*))completionHandler {
  137     NSString *completionHandlerId = [[NSUUID UUID] UUIDString];
  138     NSDictionary *data = @{ @"requestId": completionHandlerId};
  139     
  140     [participantInfoCompletionHandlers setObject:[completionHandler copy] forKey:completionHandlerId];
  141     
  142     [self sendEventWithName:retrieveParticipantsInfoAction body:data];
  143 }
  144 
  145 - (void)openChat:(NSString*)to {
  146     NSMutableDictionary *data = [[NSMutableDictionary alloc] init];
  147     data[@"to"] = to;
  148     
  149     [self sendEventWithName:openChatAction body:data];
  150 }
  151 
  152 - (void)closeChat {
  153     [self sendEventWithName:closeChatAction body:nil];
  154 }
  155 
  156 - (void)sendChatMessage:(NSString*)message :(NSString*)to {
  157     NSMutableDictionary *data = [[NSMutableDictionary alloc] init];
  158     data[@"to"] = to;
  159     data[@"message"] = message;
  160     
  161     [self sendEventWithName:sendChatMessageAction body:data];
  162 }
  163 
  164 - (void)sendSetVideoMuted:(BOOL)muted {
  165     NSDictionary *data = @{ @"muted": [NSNumber numberWithBool:muted]};
  166 
  167     [self sendEventWithName:setVideoMutedAction body:data];
  168 }
  169 
  170 - (void)sendSetClosedCaptionsEnabled:(BOOL)enabled {
  171     NSDictionary *data = @{ @"enabled": [NSNumber numberWithBool:enabled]};
  172 
  173     [self sendEventWithName:setClosedCaptionsEnabledAction body:data];
  174 }
  175 
  176 @end