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.

JitsiMeetConferenceOptions.m 5.7KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238
  1. /*
  2. * Copyright @ 2019-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 <React/RCTUtils.h>
  17. #import "JitsiMeetConferenceOptions+Private.h"
  18. #import "JitsiMeetUserInfo+Private.h"
  19. /**
  20. * Backwards compatibility: turn the boolean property into a feature flag.
  21. */
  22. static NSString *const WelcomePageEnabledFeatureFlag = @"welcomepage.enabled";
  23. @implementation JitsiMeetConferenceOptionsBuilder {
  24. NSNumber *_audioOnly;
  25. NSNumber *_audioMuted;
  26. NSNumber *_videoMuted;
  27. NSMutableDictionary *_featureFlags;
  28. }
  29. @dynamic audioOnly;
  30. @dynamic audioMuted;
  31. @dynamic videoMuted;
  32. @dynamic welcomePageEnabled;
  33. - (instancetype)init {
  34. if (self = [super init]) {
  35. _serverURL = nil;
  36. _room = nil;
  37. _subject = nil;
  38. _token = nil;
  39. _colorScheme = nil;
  40. _featureFlags = [[NSMutableDictionary alloc] init];
  41. _audioOnly = nil;
  42. _audioMuted = nil;
  43. _videoMuted = nil;
  44. _userInfo = nil;
  45. }
  46. return self;
  47. }
  48. - (void)setFeatureFlag:(NSString *)flag withBoolean:(BOOL)value {
  49. [self setFeatureFlag:flag withValue:[NSNumber numberWithBool:value]];
  50. }
  51. - (void)setFeatureFlag:(NSString *)flag withValue:(id)value {
  52. _featureFlags[flag] = value;
  53. }
  54. #pragma mark - Dynamic properties
  55. - (void)setAudioOnly:(BOOL)audioOnly {
  56. _audioOnly = [NSNumber numberWithBool:audioOnly];
  57. }
  58. - (BOOL)audioOnly {
  59. return _audioOnly && [_audioOnly boolValue];
  60. }
  61. - (void)setAudioMuted:(BOOL)audioMuted {
  62. _audioMuted = [NSNumber numberWithBool:audioMuted];
  63. }
  64. - (BOOL)audioMuted {
  65. return _audioMuted && [_audioMuted boolValue];
  66. }
  67. - (void)setVideoMuted:(BOOL)videoMuted {
  68. _videoMuted = [NSNumber numberWithBool:videoMuted];
  69. }
  70. - (BOOL)videoMuted {
  71. return _videoMuted && [_videoMuted boolValue];
  72. }
  73. - (void)setWelcomePageEnabled:(BOOL)welcomePageEnabled {
  74. [self setFeatureFlag:WelcomePageEnabledFeatureFlag
  75. withBoolean:welcomePageEnabled];
  76. }
  77. - (BOOL)welcomePageEnabled {
  78. NSNumber *n = _featureFlags[WelcomePageEnabledFeatureFlag];
  79. return n != nil ? [n boolValue] : NO;
  80. }
  81. #pragma mark - Private API
  82. - (NSNumber *)getAudioOnly {
  83. return _audioOnly;
  84. }
  85. - (NSNumber *)getAudioMuted {
  86. return _audioMuted;
  87. }
  88. - (NSNumber *)getVideoMuted {
  89. return _videoMuted;
  90. }
  91. @end
  92. @implementation JitsiMeetConferenceOptions {
  93. NSNumber *_audioOnly;
  94. NSNumber *_audioMuted;
  95. NSNumber *_videoMuted;
  96. NSDictionary *_featureFlags;
  97. }
  98. @dynamic audioOnly;
  99. @dynamic audioMuted;
  100. @dynamic videoMuted;
  101. @dynamic welcomePageEnabled;
  102. #pragma mark - Dynamic properties
  103. - (BOOL)audioOnly {
  104. return _audioOnly && [_audioOnly boolValue];
  105. }
  106. - (BOOL)audioMuted {
  107. return _audioMuted && [_audioMuted boolValue];
  108. }
  109. - (BOOL)videoMuted {
  110. return _videoMuted && [_videoMuted boolValue];
  111. }
  112. - (BOOL)welcomePageEnabled {
  113. NSNumber *n = _featureFlags[WelcomePageEnabledFeatureFlag];
  114. return n != nil ? [n boolValue] : NO;
  115. }
  116. #pragma mark - Internal initializer
  117. - (instancetype)initWithBuilder:(JitsiMeetConferenceOptionsBuilder *)builder {
  118. if (self = [super init]) {
  119. _serverURL = builder.serverURL;
  120. _room = builder.room;
  121. _subject = builder.subject;
  122. _token = builder.token;
  123. _colorScheme = builder.colorScheme;
  124. _audioOnly = [builder getAudioOnly];
  125. _audioMuted = [builder getAudioMuted];
  126. _videoMuted = [builder getVideoMuted];
  127. _featureFlags = [NSDictionary dictionaryWithDictionary:builder.featureFlags];
  128. _userInfo = builder.userInfo;
  129. }
  130. return self;
  131. }
  132. #pragma mark - API
  133. + (instancetype)fromBuilder:(void (^)(JitsiMeetConferenceOptionsBuilder *))initBlock {
  134. JitsiMeetConferenceOptionsBuilder *builder = [[JitsiMeetConferenceOptionsBuilder alloc] init];
  135. initBlock(builder);
  136. return [[JitsiMeetConferenceOptions alloc] initWithBuilder:builder];
  137. }
  138. #pragma mark - Private API
  139. - (NSDictionary *)asProps {
  140. NSMutableDictionary *props = [[NSMutableDictionary alloc] init];
  141. props[@"flags"] = [NSMutableDictionary dictionaryWithDictionary:_featureFlags];
  142. if (_colorScheme != nil) {
  143. props[@"colorScheme"] = self.colorScheme;
  144. }
  145. NSMutableDictionary *config = [[NSMutableDictionary alloc] init];
  146. if (_audioOnly != nil) {
  147. config[@"startAudioOnly"] = @(self.audioOnly);
  148. }
  149. if (_audioMuted != nil) {
  150. config[@"startWithAudioMuted"] = @(self.audioMuted);
  151. }
  152. if (_videoMuted != nil) {
  153. config[@"startWithVideoMuted"] = @(self.videoMuted);
  154. }
  155. if (_subject != nil) {
  156. config[@"subject"] = self.subject;
  157. }
  158. NSMutableDictionary *urlProps = [[NSMutableDictionary alloc] init];
  159. // The room is fully qualified.
  160. if (_room != nil && [_room containsString:@"://"]) {
  161. urlProps[@"url"] = _room;
  162. } else {
  163. if (_serverURL != nil) {
  164. urlProps[@"serverURL"] = [_serverURL absoluteString];
  165. }
  166. if (_room != nil) {
  167. urlProps[@"room"] = _room;
  168. }
  169. }
  170. if (_token != nil) {
  171. urlProps[@"jwt"] = _token;
  172. }
  173. if (_token == nil && _userInfo != nil) {
  174. props[@"userInfo"] = [self.userInfo asDict];
  175. }
  176. urlProps[@"config"] = config;
  177. props[@"url"] = urlProps;
  178. return props;
  179. }
  180. @end