You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

ExternalAPI.m 2.4KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384
  1. /*
  2. * Copyright @ 2017-present Atlassian Pty Ltd
  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 "RCTBridgeModule.h"
  17. #import "JitsiMeetView+Private.h"
  18. @interface ExternalAPI : NSObject<RCTBridgeModule>
  19. @end
  20. @implementation ExternalAPI
  21. RCT_EXPORT_MODULE();
  22. /**
  23. * Dispatches an event that occurred on JavaScript to the view's delegate.
  24. *
  25. * @param name The name of the event.
  26. * @param data The details/specifics of the event to send determined
  27. * by/associated with the specified `name`.
  28. * @param scope
  29. */
  30. RCT_EXPORT_METHOD(sendEvent:(NSString *)name
  31. data:(NSDictionary *)data
  32. scope:(NSString *)scope) {
  33. // The JavaScript App needs to provide uniquely identifying information to
  34. // the native ExternalAPI module so that the latter may match the former
  35. // to the native JitsiMeetView which hosts it.
  36. JitsiMeetView *view = [JitsiMeetView viewForExternalAPIScope:scope];
  37. if (!view) {
  38. return;
  39. }
  40. id delegate = view.delegate;
  41. if (!delegate) {
  42. return;
  43. }
  44. SEL sel = NSSelectorFromString([self methodNameFromEventName:name]);
  45. if (sel && [delegate respondsToSelector:sel]) {
  46. [delegate performSelector:sel withObject:data];
  47. }
  48. }
  49. /**
  50. * Converts a specific event name i.e. redux action type description to a
  51. * method name.
  52. *
  53. * @param eventName The event name to convert to a method name.
  54. * @return A method name constructed from the specified `eventName`.
  55. */
  56. - (NSString *)methodNameFromEventName:(NSString *)eventName {
  57. NSMutableString *methodName
  58. = [NSMutableString stringWithCapacity:eventName.length];
  59. for (NSString *c in [eventName componentsSeparatedByString:@"_"]) {
  60. if (c.length) {
  61. [methodName appendString:
  62. methodName.length ? c.capitalizedString : c.lowercaseString];
  63. }
  64. }
  65. [methodName appendString:@":"];
  66. return methodName;
  67. }
  68. @end