Вы не можете выбрать более 25 тем Темы должны начинаться с буквы или цифры, могут содержать дефисы(-) и должны содержать не более 35 символов.

ViewController.m 6.0KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182
  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 "ViewController.h"
  17. /**
  18. * The query to perform through JMAddPeopleController when the InviteButton is
  19. * tapped in order to exercise the public API of the feature invite. If nil, the
  20. * InviteButton will not be rendered.
  21. */
  22. static NSString * const ADD_PEOPLE_CONTROLLER_QUERY = nil;
  23. @interface ViewController ()
  24. @end
  25. @implementation ViewController
  26. - (void)viewDidLoad {
  27. [super viewDidLoad];
  28. JitsiMeetView *view = (JitsiMeetView *) self.view;
  29. #ifdef DEBUG
  30. view.delegate = self;
  31. // inviteController
  32. JMInviteController *inviteController = view.inviteController;
  33. inviteController.delegate = self;
  34. inviteController.addPeopleEnabled
  35. = inviteController.dialOutEnabled
  36. = ADD_PEOPLE_CONTROLLER_QUERY != nil;
  37. #endif // #ifdef DEBUG
  38. // As this is the Jitsi Meet app (i.e. not the Jitsi Meet SDK), we do want
  39. // the Welcome page to be enabled. It defaults to disabled in the SDK at the
  40. // time of this writing but it is clearer to be explicit about what we want
  41. // anyway.
  42. view.welcomePageEnabled = YES;
  43. [view loadURL:nil];
  44. }
  45. #if DEBUG
  46. // JitsiMeetViewDelegate
  47. - (void)_onJitsiMeetViewDelegateEvent:(NSString *)name
  48. withData:(NSDictionary *)data {
  49. NSLog(
  50. @"[%s:%d] JitsiMeetViewDelegate %@ %@",
  51. __FILE__, __LINE__, name, data);
  52. NSAssert(
  53. [NSThread isMainThread],
  54. @"JitsiMeetViewDelegate %@ method invoked on a non-main thread",
  55. name);
  56. }
  57. - (void)conferenceFailed:(NSDictionary *)data {
  58. [self _onJitsiMeetViewDelegateEvent:@"CONFERENCE_FAILED" withData:data];
  59. }
  60. - (void)conferenceJoined:(NSDictionary *)data {
  61. [self _onJitsiMeetViewDelegateEvent:@"CONFERENCE_JOINED" withData:data];
  62. }
  63. - (void)conferenceLeft:(NSDictionary *)data {
  64. [self _onJitsiMeetViewDelegateEvent:@"CONFERENCE_LEFT" withData:data];
  65. }
  66. - (void)conferenceWillJoin:(NSDictionary *)data {
  67. [self _onJitsiMeetViewDelegateEvent:@"CONFERENCE_WILL_JOIN" withData:data];
  68. }
  69. - (void)conferenceWillLeave:(NSDictionary *)data {
  70. [self _onJitsiMeetViewDelegateEvent:@"CONFERENCE_WILL_LEAVE" withData:data];
  71. }
  72. - (void)loadConfigError:(NSDictionary *)data {
  73. [self _onJitsiMeetViewDelegateEvent:@"LOAD_CONFIG_ERROR" withData:data];
  74. }
  75. // JMInviteControllerDelegate
  76. - (void)beginAddPeople:(JMAddPeopleController *)addPeopleController {
  77. NSLog(
  78. @"[%s:%d] JMInviteControllerDelegate %s",
  79. __FILE__, __LINE__, __FUNCTION__);
  80. NSAssert(
  81. [NSThread isMainThread],
  82. @"JMInviteControllerDelegate beginAddPeople: invoked on a non-main thread");
  83. NSString *query = ADD_PEOPLE_CONTROLLER_QUERY;
  84. JitsiMeetView *view = (JitsiMeetView *) self.view;
  85. JMInviteController *inviteController = view.inviteController;
  86. if (query
  87. && (inviteController.addPeopleEnabled
  88. || inviteController.dialOutEnabled)) {
  89. addPeopleController.delegate = self;
  90. [addPeopleController performQuery:query];
  91. } else {
  92. // XXX Explicitly invoke endAddPeople on addPeopleController; otherwise,
  93. // it is going to be memory-leaked in the associated JMInviteController
  94. // and no subsequent InviteButton clicks/taps will be delivered.
  95. [addPeopleController endAddPeople];
  96. }
  97. }
  98. // JMAddPeopleControllerDelegate
  99. - (void)addPeopleController:(JMAddPeopleController * _Nonnull)controller
  100. didReceiveResults:(NSArray<NSDictionary *> * _Nonnull)results
  101. forQuery:(NSString * _Nonnull)query {
  102. NSAssert(
  103. [NSThread isMainThread],
  104. @"JMAddPeopleControllerDelegate addPeopleController:didReceiveResults:forQuery: invoked on a non-main thread");
  105. NSUInteger count = results.count;
  106. if (count) {
  107. // Exercise JMAddPeopleController's inviteById: implementation.
  108. NSMutableArray *ids = [NSMutableArray arrayWithCapacity:count];
  109. for (NSUInteger i = 0; i < count; ++i) {
  110. ids[i] = results[i][@"id"];
  111. }
  112. [controller inviteById:ids];
  113. // Exercise JMInviteController's invite:withCompletion: implementation.
  114. //
  115. // XXX Technically, only at most one of the two exercises will result in
  116. // an actual invitation eventually.
  117. JitsiMeetView *view = (JitsiMeetView *) self.view;
  118. JMInviteController *inviteController = view.inviteController;
  119. [inviteController invite:results withCompletion:nil];
  120. return;
  121. }
  122. // XXX Explicitly invoke endAddPeople on addPeopleController; otherwise, it
  123. // is going to be memory-leaked in the associated JMInviteController and no
  124. // subsequent InviteButton clicks/taps will be delivered.
  125. [controller endAddPeople];
  126. }
  127. - (void) inviteSettled:(NSArray<NSDictionary *> * _Nonnull)failedInvitees
  128. fromSearchController:(JMAddPeopleController * _Nonnull)addPeopleController {
  129. NSAssert(
  130. [NSThread isMainThread],
  131. @"JMAddPeopleControllerDelegate inviteSettled:fromSearchController: invoked on a non-main thread");
  132. // XXX Explicitly invoke endAddPeople on addPeopleController; otherwise, it
  133. // is going to be memory-leaked in the associated JMInviteController and no
  134. // subsequent InviteButton clicks/taps will be delivered. Technically,
  135. // endAddPeople will automatically be invoked if there are no
  136. // failedInviteees i.e. the invite succeeeded for all specified invitees.
  137. [addPeopleController endAddPeople];
  138. }
  139. #endif // #ifdef DEBUG
  140. @end