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

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216
  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.createRoomLocker(conference);
  15. this.initDialog();
  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, role) => {
  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.INVITE_URL_INITIALISED,
  41. (inviteUrl) => {
  42. this.updateInviteUrl(inviteUrl);
  43. });
  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.password = this.getPassword();
  105. this.view = new InviteDialogView(this);
  106. }
  107. /**
  108. * Password getter
  109. * @returns {String} password
  110. */
  111. getPassword() {
  112. return this.roomLocker.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.roomLocker.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.roomLocker.isLocked)) {
  144. this.roomLocker.lock(newPass).then(() => {
  145. APP.UI.emitEvent(UIEvents.TOGGLE_ROOM_LOCK);
  146. this.updateView();
  147. });
  148. }
  149. }
  150. /**
  151. * Updates the room invite url.
  152. */
  153. updateInviteUrl (newInviteUrl) {
  154. this.inviteUrl = newInviteUrl;
  155. this.updateView();
  156. }
  157. /**
  158. * Helper method for encoding
  159. * Invite URL
  160. * @returns {string}
  161. */
  162. getEncodedInviteUrl() {
  163. return encodeURI(this.inviteUrl);
  164. }
  165. /**
  166. * Is locked flag.
  167. * Delegates to room locker
  168. * @returns {Boolean} isLocked
  169. */
  170. isLocked() {
  171. return this.roomLocker.isLocked;
  172. }
  173. /**
  174. * Set flag locked from elsewhere to room locker.
  175. * @param isLocked
  176. */
  177. setLockedFromElsewhere(isLocked) {
  178. let oldLockState = this.roomLocker.lockedElsewhere;
  179. if (oldLockState !== isLocked) {
  180. this.roomLocker.lockedElsewhere = isLocked;
  181. APP.UI.emitEvent(UIEvents.TOGGLE_ROOM_LOCK);
  182. this.updateView();
  183. }
  184. }
  185. }
  186. export default Invite;