Nevar pievienot vairāk kā 25 tēmas Tēmai ir jāsākas ar burtu vai ciparu, tā var saturēt domu zīmes ('-') un var būt līdz 35 simboliem gara.

Invite.js 5.3KB

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