Você não pode selecionar mais de 25 tópicos Os tópicos devem começar com uma letra ou um número, podem incluir traços ('-') e podem ter até 35 caracteres.

ExternalAPI.m 3.6KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126
  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. #import "ExternalAPI.h"
  17. #import "JitsiMeetView+Private.h"
  18. // Events
  19. static NSString * const hangUpAction = @"org.jitsi.meet.HANG_UP";
  20. static NSString * const setAudioMutedAction = @"org.jitsi.meet.SET_AUDIO_MUTED";
  21. static NSString * const sendEndpointTextMessageAction = @"org.jitsi.meet.SEND_ENDPOINT_TEXT_MESSAGE";
  22. @implementation ExternalAPI
  23. RCT_EXPORT_MODULE();
  24. - (NSDictionary *)constantsToExport {
  25. return @{
  26. @"HANG_UP": hangUpAction,
  27. @"SET_AUDIO_MUTED" : setAudioMutedAction,
  28. @"SEND_ENDPOINT_TEXT_MESSAGE": sendEndpointTextMessageAction
  29. };
  30. };
  31. /**
  32. * Make sure all methods in this module are invoked on the main/UI thread.
  33. */
  34. - (dispatch_queue_t)methodQueue {
  35. return dispatch_get_main_queue();
  36. }
  37. + (BOOL)requiresMainQueueSetup {
  38. return NO;
  39. }
  40. - (NSArray<NSString *> *)supportedEvents {
  41. return @[ hangUpAction, setAudioMutedAction, sendEndpointTextMessageAction ];
  42. }
  43. /**
  44. * Dispatches an event that occurred on JavaScript to the view's delegate.
  45. *
  46. * @param name The name of the event.
  47. * @param data The details/specifics of the event to send determined
  48. * by/associated with the specified `name`.
  49. * @param scope
  50. */
  51. RCT_EXPORT_METHOD(sendEvent:(NSString *)name
  52. data:(NSDictionary *)data
  53. scope:(NSString *)scope) {
  54. // The JavaScript App needs to provide uniquely identifying information to
  55. // the native ExternalAPI module so that the latter may match the former
  56. // to the native JitsiMeetView which hosts it.
  57. JitsiMeetView *view = [JitsiMeetView viewForExternalAPIScope:scope];
  58. if (!view) {
  59. return;
  60. }
  61. id delegate = view.delegate;
  62. if (!delegate) {
  63. return;
  64. }
  65. SEL sel = NSSelectorFromString([self methodNameFromEventName:name]);
  66. if (sel && [delegate respondsToSelector:sel]) {
  67. [delegate performSelector:sel withObject:data];
  68. }
  69. }
  70. /**
  71. * Converts a specific event name i.e. redux action type description to a
  72. * method name.
  73. *
  74. * @param eventName The event name to convert to a method name.
  75. * @return A method name constructed from the specified `eventName`.
  76. */
  77. - (NSString *)methodNameFromEventName:(NSString *)eventName {
  78. NSMutableString *methodName
  79. = [NSMutableString stringWithCapacity:eventName.length];
  80. for (NSString *c in [eventName componentsSeparatedByString:@"_"]) {
  81. if (c.length) {
  82. [methodName appendString:
  83. methodName.length ? c.capitalizedString : c.lowercaseString];
  84. }
  85. }
  86. [methodName appendString:@":"];
  87. return methodName;
  88. }
  89. - (void)sendHangUp {
  90. [self sendEventWithName:hangUpAction body:nil];
  91. }
  92. - (void)sendSetAudioMuted:(BOOL)muted {
  93. NSDictionary *data = @{ @"muted": [NSNumber numberWithBool:muted]};
  94. [self sendEventWithName:setAudioMutedAction body:data];
  95. }
  96. - (void)sendEndpointTextMessage:(NSString*)to :(NSString*)message {
  97. NSDictionary *data = @{
  98. @"to": to,
  99. @"message": message
  100. };
  101. [self sendEventWithName:sendEndpointTextMessageAction body:data];
  102. }
  103. @end