選択できるのは25トピックまでです。 トピックは、先頭が英数字で、英数字とダッシュ('-')を使用した35文字以内のものにしてください。

Invite.js 5.6KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217
  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.registerListeners();
  16. }
  17. /**
  18. * Registering listeners.
  19. * Primarily listeners for conference events.
  20. */
  21. registerListeners() {
  22. this.conference.on(ConferenceEvents.LOCK_STATE_CHANGED,
  23. (locked, error) => {
  24. console.log("Received channel password lock change: ", locked,
  25. error);
  26. if (!locked) {
  27. this.roomLocker.resetPassword();
  28. }
  29. this.setLockedFromElsewhere(locked);
  30. });
  31. this.conference.on(ConferenceEvents.USER_ROLE_CHANGED, (id) => {
  32. if (APP.conference.isLocalId(id)
  33. && this.isModerator !== this.conference.isModerator) {
  34. this.setModerator(this.conference.isModerator);
  35. }
  36. });
  37. APP.UI.addListener( UIEvents.INVITE_CLICKED,
  38. () => { this.openLinkDialog(); });
  39. APP.UI.addListener( UIEvents.INVITE_URL_INITIALISED,
  40. (inviteUrl) => {
  41. this.updateInviteUrl(inviteUrl);
  42. });
  43. APP.UI.addListener( UIEvents.PASSWORD_REQUIRED,
  44. () => {
  45. this.setLockedFromElsewhere(true);
  46. this.roomLocker.requirePassword().then(() => {
  47. let pass = this.roomLocker.password;
  48. // we received that password is required, but user is trying
  49. // anyway to login without a password, mark room as not
  50. // locked in case he succeeds (maybe someone removed the
  51. // password meanwhile), if it is still locked another
  52. // password required will be received and the room again
  53. // will be marked as locked.
  54. if (!pass)
  55. this.setLockedFromElsewhere(false);
  56. this.conference.join(this.roomLocker.password);
  57. });
  58. });
  59. }
  60. /**
  61. * Updates the view.
  62. * If dialog hasn't been defined -
  63. * creates it and updates
  64. */
  65. updateView() {
  66. if (!this.view) {
  67. this.initDialog();
  68. }
  69. this.view.updateView();
  70. }
  71. /**
  72. * Room locker factory
  73. * @param room
  74. * @returns {Object} RoomLocker
  75. * @factory
  76. */
  77. createRoomLocker(room = this.conference) {
  78. let roomLocker = createRoomLocker(room);
  79. this.roomLocker = roomLocker;
  80. return this.getRoomLocker();
  81. }
  82. /**
  83. * Room locker getter
  84. * @returns {Object} RoomLocker
  85. */
  86. getRoomLocker() {
  87. return this.roomLocker;
  88. }
  89. /**
  90. * Opens the invite link dialog.
  91. */
  92. openLinkDialog () {
  93. if (!this.view) {
  94. this.initDialog();
  95. }
  96. this.view.open();
  97. }
  98. /**
  99. * Dialog initialization.
  100. * creating view object using as a model this module
  101. */
  102. initDialog() {
  103. this.password = this.getPassword();
  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. * Updates the room invite url.
  151. */
  152. updateInviteUrl (newInviteUrl) {
  153. this.inviteUrl = newInviteUrl;
  154. this.updateView();
  155. }
  156. /**
  157. * Helper method for encoding
  158. * Invite URL
  159. * @returns {string}
  160. */
  161. getEncodedInviteUrl() {
  162. return encodeURI(this.inviteUrl);
  163. }
  164. /**
  165. * Is locked flag.
  166. * Delegates to room locker
  167. * @returns {Boolean} isLocked
  168. */
  169. isLocked() {
  170. return this.roomLocker.isLocked;
  171. }
  172. /**
  173. * Set flag locked from elsewhere to room locker.
  174. * @param isLocked
  175. */
  176. setLockedFromElsewhere(isLocked) {
  177. // isLocked can be 1, true or false
  178. let newLockState = (isLocked === 1) || isLocked;
  179. let oldLockState = this.roomLocker.isLocked;
  180. if (oldLockState !== newLockState) {
  181. this.roomLocker.lockedElsewhere = isLocked;
  182. APP.UI.emitEvent(UIEvents.TOGGLE_ROOM_LOCK);
  183. this.updateView();
  184. }
  185. }
  186. }
  187. export default Invite;