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.

ViewController.m 5.6KB

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