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.

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210
  1. /* global JitsiMeetJS, APP */
  2. const logger = require("jitsi-meet-logger").getLogger(__filename);
  3. import InviteDialogView from './InviteDialogView';
  4. import createRoomLocker from './RoomLocker';
  5. import UIEvents from '../../../service/UI/UIEvents';
  6. const ConferenceEvents = JitsiMeetJS.events.conference;
  7. /**
  8. * Invite module
  9. * Constructor takes conference object giving
  10. * ability to subscribe on its events
  11. */
  12. class Invite {
  13. constructor(conference) {
  14. this.conference = conference;
  15. this.inviteUrl = APP.ConferenceUrl.getInviteUrl();
  16. this.createRoomLocker(conference);
  17. this.registerListeners();
  18. }
  19. /**
  20. * Registering listeners.
  21. * Primarily listeners for conference events.
  22. */
  23. registerListeners() {
  24. this.conference.on(ConferenceEvents.LOCK_STATE_CHANGED,
  25. (locked, error) => {
  26. logger.log("Received channel password lock change: ", locked,
  27. error);
  28. if (!locked) {
  29. this.getRoomLocker().resetPassword();
  30. }
  31. this.setLockedFromElsewhere(locked);
  32. });
  33. this.conference.on(ConferenceEvents.USER_ROLE_CHANGED, (id) => {
  34. if (APP.conference.isLocalId(id)
  35. && this.isModerator !== this.conference.isModerator()) {
  36. this.setModerator(this.conference.isModerator());
  37. }
  38. });
  39. this.conference.on(ConferenceEvents.CONFERENCE_JOINED, () => {
  40. let roomLocker = this.getRoomLocker();
  41. roomLocker.hideRequirePasswordDialog();
  42. });
  43. APP.UI.addListener( UIEvents.INVITE_CLICKED,
  44. () => { this.openLinkDialog(); });
  45. APP.UI.addListener( UIEvents.PASSWORD_REQUIRED,
  46. () => {
  47. let roomLocker = this.getRoomLocker();
  48. this.setLockedFromElsewhere(true);
  49. roomLocker.requirePassword().then(() => {
  50. let pass = roomLocker.password;
  51. // we received that password is required, but user is trying
  52. // anyway to login without a password, mark room as not
  53. // locked in case he succeeds (maybe someone removed the
  54. // password meanwhile), if it is still locked another
  55. // password required will be received and the room again
  56. // will be marked as locked.
  57. if (!pass)
  58. this.setLockedFromElsewhere(false);
  59. this.conference.join(pass);
  60. });
  61. });
  62. }
  63. /**
  64. * Updates the view.
  65. * If dialog hasn't been defined -
  66. * creates it and updates
  67. */
  68. updateView() {
  69. if (!this.view) {
  70. this.initDialog();
  71. }
  72. this.view.updateView();
  73. }
  74. /**
  75. * Room locker factory
  76. * @param room
  77. * @returns {Object} RoomLocker
  78. * @factory
  79. */
  80. createRoomLocker(room = this.conference) {
  81. let roomLocker = createRoomLocker(room);
  82. this.roomLocker = roomLocker;
  83. return this.getRoomLocker();
  84. }
  85. /**
  86. * Room locker getter
  87. * @returns {Object} RoomLocker
  88. */
  89. getRoomLocker() {
  90. return this.roomLocker;
  91. }
  92. /**
  93. * Opens the invite link dialog.
  94. */
  95. openLinkDialog () {
  96. if (!this.view) {
  97. this.initDialog();
  98. }
  99. this.view.open();
  100. }
  101. /**
  102. * Dialog initialization.
  103. * creating view object using as a model this module
  104. */
  105. initDialog() {
  106. this.view = new InviteDialogView(this);
  107. }
  108. /**
  109. * Password getter
  110. * @returns {String} password
  111. */
  112. getPassword() {
  113. return this.getRoomLocker().password;
  114. }
  115. /**
  116. * Switches between the moderator view and normal view.
  117. *
  118. * @param isModerator indicates if the participant is moderator
  119. */
  120. setModerator(isModerator) {
  121. this.isModerator = isModerator;
  122. this.updateView();
  123. }
  124. /**
  125. * Allows to unlock the room.
  126. * If the current user is moderator.
  127. */
  128. setRoomUnlocked() {
  129. if (this.isModerator) {
  130. this.getRoomLocker().lock().then(() => {
  131. APP.UI.emitEvent(UIEvents.TOGGLE_ROOM_LOCK);
  132. this.updateView();
  133. });
  134. }
  135. }
  136. /**
  137. * Allows to lock the room if
  138. * the current user is moderator.
  139. * Takes the password.
  140. * @param {String} newPass
  141. */
  142. setRoomLocked(newPass) {
  143. let isModerator = this.isModerator;
  144. if (isModerator && (newPass || !this.getRoomLocker().isLocked)) {
  145. this.getRoomLocker().lock(newPass).then(() => {
  146. APP.UI.emitEvent(UIEvents.TOGGLE_ROOM_LOCK);
  147. this.updateView();
  148. });
  149. }
  150. }
  151. /**
  152. * Helper method for encoding
  153. * Invite URL
  154. * @returns {string}
  155. */
  156. getEncodedInviteUrl() {
  157. return encodeURI(this.inviteUrl);
  158. }
  159. /**
  160. * Is locked flag.
  161. * Delegates to room locker
  162. * @returns {Boolean} isLocked
  163. */
  164. isLocked() {
  165. return this.getRoomLocker().isLocked;
  166. }
  167. /**
  168. * Set flag locked from elsewhere to room locker.
  169. * @param isLocked
  170. */
  171. setLockedFromElsewhere(isLocked) {
  172. let roomLocker = this.getRoomLocker();
  173. let oldLockState = roomLocker.isLocked;
  174. if (oldLockState !== isLocked) {
  175. roomLocker.lockedElsewhere = isLocked;
  176. APP.UI.emitEvent(UIEvents.TOGGLE_ROOM_LOCK);
  177. this.updateView();
  178. }
  179. }
  180. }
  181. export default Invite;