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.

Invite.js 5.2KB

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