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.4KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207
  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. this.conference.on(ConferenceEvents.CONFERENCE_JOINED, () => {
  39. let roomLocker = this.getRoomLocker();
  40. roomLocker.hideRequirePasswordDialog();
  41. });
  42. APP.UI.addListener( UIEvents.INVITE_CLICKED,
  43. () => { this.openLinkDialog(); });
  44. APP.UI.addListener( UIEvents.PASSWORD_REQUIRED,
  45. () => {
  46. this.setLockedFromElsewhere(true);
  47. this.roomLocker.requirePassword().then(() => {
  48. let pass = this.roomLocker.password;
  49. // we received that password is required, but user is trying
  50. // anyway to login without a password, mark room as not
  51. // locked in case he succeeds (maybe someone removed the
  52. // password meanwhile), if it is still locked another
  53. // password required will be received and the room again
  54. // will be marked as locked.
  55. if (!pass)
  56. this.setLockedFromElsewhere(false);
  57. this.conference.join(this.roomLocker.password);
  58. });
  59. });
  60. }
  61. /**
  62. * Updates the view.
  63. * If dialog hasn't been defined -
  64. * creates it and updates
  65. */
  66. updateView() {
  67. if (!this.view) {
  68. this.initDialog();
  69. }
  70. this.view.updateView();
  71. }
  72. /**
  73. * Room locker factory
  74. * @param room
  75. * @returns {Object} RoomLocker
  76. * @factory
  77. */
  78. createRoomLocker(room = this.conference) {
  79. let roomLocker = createRoomLocker(room);
  80. this.roomLocker = roomLocker;
  81. return this.getRoomLocker();
  82. }
  83. /**
  84. * Room locker getter
  85. * @returns {Object} RoomLocker
  86. */
  87. getRoomLocker() {
  88. return this.roomLocker;
  89. }
  90. /**
  91. * Opens the invite link dialog.
  92. */
  93. openLinkDialog () {
  94. if (!this.view) {
  95. this.initDialog();
  96. }
  97. this.view.open();
  98. }
  99. /**
  100. * Dialog initialization.
  101. * creating view object using as a model this module
  102. */
  103. initDialog() {
  104. this.view = new InviteDialogView(this);
  105. }
  106. /**
  107. * Password getter
  108. * @returns {String} password
  109. */
  110. getPassword() {
  111. return this.roomLocker.password;
  112. }
  113. /**
  114. * Switches between the moderator view and normal view.
  115. *
  116. * @param isModerator indicates if the participant is moderator
  117. */
  118. setModerator(isModerator) {
  119. this.isModerator = isModerator;
  120. this.updateView();
  121. }
  122. /**
  123. * Allows to unlock the room.
  124. * If the current user is moderator.
  125. */
  126. setRoomUnlocked() {
  127. if (this.isModerator) {
  128. this.roomLocker.lock().then(() => {
  129. APP.UI.emitEvent(UIEvents.TOGGLE_ROOM_LOCK);
  130. this.updateView();
  131. });
  132. }
  133. }
  134. /**
  135. * Allows to lock the room if
  136. * the current user is moderator.
  137. * Takes the password.
  138. * @param {String} newPass
  139. */
  140. setRoomLocked(newPass) {
  141. let isModerator = this.isModerator;
  142. if (isModerator && (newPass || !this.roomLocker.isLocked)) {
  143. this.roomLocker.lock(newPass).then(() => {
  144. APP.UI.emitEvent(UIEvents.TOGGLE_ROOM_LOCK);
  145. this.updateView();
  146. });
  147. }
  148. }
  149. /**
  150. * Helper method for encoding
  151. * Invite URL
  152. * @returns {string}
  153. */
  154. getEncodedInviteUrl() {
  155. return encodeURI(this.inviteUrl);
  156. }
  157. /**
  158. * Is locked flag.
  159. * Delegates to room locker
  160. * @returns {Boolean} isLocked
  161. */
  162. isLocked() {
  163. return this.roomLocker.isLocked;
  164. }
  165. /**
  166. * Set flag locked from elsewhere to room locker.
  167. * @param isLocked
  168. */
  169. setLockedFromElsewhere(isLocked) {
  170. let oldLockState = this.roomLocker.isLocked;
  171. if (oldLockState !== isLocked) {
  172. this.roomLocker.lockedElsewhere = isLocked;
  173. APP.UI.emitEvent(UIEvents.TOGGLE_ROOM_LOCK);
  174. this.updateView();
  175. }
  176. }
  177. }
  178. export default Invite;