Nevar pievienot vairāk kā 25 tēmas Tēmai ir jāsākas ar burtu vai ciparu, tā var saturēt domu zīmes ('-') un var būt līdz 35 simboliem gara.

JitsiMeetView.m 5.6KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193
  1. /*
  2. * Copyright @ 2018-present 8x8, Inc.
  3. * Copyright @ 2017-2018 Atlassian Pty Ltd
  4. *
  5. * Licensed under the Apache License, Version 2.0 (the "License");
  6. * you may not use this file except in compliance with the License.
  7. * You may obtain a copy of the License at
  8. *
  9. * http://www.apache.org/licenses/LICENSE-2.0
  10. *
  11. * Unless required by applicable law or agreed to in writing, software
  12. * distributed under the License is distributed on an "AS IS" BASIS,
  13. * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  14. * See the License for the specific language governing permissions and
  15. * limitations under the License.
  16. */
  17. #include <mach/mach_time.h>
  18. #import "JitsiMeet+Private.h"
  19. #import "JitsiMeetConferenceOptions+Private.h"
  20. #import "JitsiMeetView+Private.h"
  21. #import "ReactUtils.h"
  22. #import "RNRootView.h"
  23. /**
  24. * Backwards compatibility: turn the boolean prop into a feature flag.
  25. */
  26. static NSString *const PiPEnabledFeatureFlag = @"pip.enabled";
  27. @implementation JitsiMeetView {
  28. /**
  29. * The unique identifier of this `JitsiMeetView` within the process for the
  30. * purposes of `ExternalAPI`. The name scope was inspired by postis which we
  31. * use on Web for the similar purposes of the iframe-based external API.
  32. */
  33. NSString *externalAPIScope;
  34. /**
  35. * React Native view where the entire content will be rendered.
  36. */
  37. RNRootView *rootView;
  38. }
  39. /**
  40. * The `JitsiMeetView`s associated with their `ExternalAPI` scopes (i.e. unique
  41. * identifiers within the process).
  42. */
  43. static NSMapTable<NSString *, JitsiMeetView *> *views;
  44. /**
  45. * This gets called automagically when the program starts.
  46. */
  47. __attribute__((constructor))
  48. static void initializeViewsMap() {
  49. views = [NSMapTable strongToWeakObjectsMapTable];
  50. }
  51. #pragma mark Initializers
  52. - (instancetype)init {
  53. self = [super init];
  54. if (self) {
  55. [self initWithXXX];
  56. }
  57. return self;
  58. }
  59. - (instancetype)initWithCoder:(NSCoder *)coder {
  60. self = [super initWithCoder:coder];
  61. if (self) {
  62. [self initWithXXX];
  63. }
  64. return self;
  65. }
  66. - (instancetype)initWithFrame:(CGRect)frame {
  67. self = [super initWithFrame:frame];
  68. if (self) {
  69. [self initWithXXX];
  70. }
  71. return self;
  72. }
  73. /**
  74. * Internal initialization:
  75. *
  76. * - sets the background color
  77. * - initializes the external API scope
  78. */
  79. - (void)initWithXXX {
  80. // Hook this JitsiMeetView into ExternalAPI.
  81. externalAPIScope = [NSUUID UUID].UUIDString;
  82. [views setObject:self forKey:externalAPIScope];
  83. // Set a background color which is in accord with the JavaScript and Android
  84. // parts of the application and causes less perceived visual flicker than
  85. // the default background color.
  86. self.backgroundColor
  87. = [UIColor colorWithRed:.07f green:.07f blue:.07f alpha:1];
  88. }
  89. #pragma mark API
  90. - (void)join:(JitsiMeetConferenceOptions *)options {
  91. [self setProps:options == nil ? @{} : [options asProps]];
  92. }
  93. - (void)leave {
  94. [self setProps:@{}];
  95. }
  96. #pragma mark Private methods
  97. /**
  98. * Passes the given props to the React Native application. The props which we pass
  99. * are a combination of 3 different sources:
  100. *
  101. * - JitsiMeet.defaultConferenceOptions
  102. * - This function's parameters
  103. * - Some extras which are added by this function
  104. */
  105. - (void)setProps:(NSDictionary *_Nonnull)newProps {
  106. NSMutableDictionary *props = mergeProps([[JitsiMeet sharedInstance] getDefaultProps], newProps);
  107. // Set the PiP flag if it wasn't manually set.
  108. NSMutableDictionary *featureFlags = props[@"flags"];
  109. if (featureFlags[PiPEnabledFeatureFlag] == nil) {
  110. featureFlags[PiPEnabledFeatureFlag]
  111. = [NSNumber numberWithBool:
  112. self.delegate && [self.delegate respondsToSelector:@selector(enterPictureInPicture:)]];
  113. }
  114. props[@"externalAPIScope"] = externalAPIScope;
  115. // This method is supposed to be imperative i.e. a second
  116. // invocation with one and the same URL is expected to join the respective
  117. // conference again if the first invocation was followed by leaving the
  118. // conference. However, React and, respectively,
  119. // appProperties/initialProperties are declarative expressions i.e. one and
  120. // the same URL will not trigger an automatic re-render in the JavaScript
  121. // source code. The workaround implemented bellow introduces imperativeness
  122. // in React Component props by defining a unique value per invocation.
  123. props[@"timestamp"] = @(mach_absolute_time());
  124. if (rootView) {
  125. // Update props with the new URL.
  126. rootView.appProperties = props;
  127. } else {
  128. RCTBridge *bridge = [[JitsiMeet sharedInstance] getReactBridge];
  129. rootView
  130. = [[RNRootView alloc] initWithBridge:bridge
  131. moduleName:@"App"
  132. initialProperties:props];
  133. rootView.backgroundColor = self.backgroundColor;
  134. // Add rootView as a subview which completely covers this one.
  135. [rootView setFrame:[self bounds]];
  136. rootView.autoresizingMask
  137. = UIViewAutoresizingFlexibleWidth
  138. | UIViewAutoresizingFlexibleHeight;
  139. [self addSubview:rootView];
  140. }
  141. }
  142. + (BOOL)setPropsInViews:(NSDictionary *_Nonnull)newProps {
  143. BOOL handled = NO;
  144. if (views) {
  145. for (NSString *externalAPIScope in views) {
  146. JitsiMeetView *view
  147. = [self viewForExternalAPIScope:externalAPIScope];
  148. if (view) {
  149. [view setProps:newProps];
  150. handled = YES;
  151. }
  152. }
  153. }
  154. return handled;
  155. }
  156. + (instancetype)viewForExternalAPIScope:(NSString *)externalAPIScope {
  157. return [views objectForKey:externalAPIScope];
  158. }
  159. @end