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

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