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.

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