123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216 |
- /* global JitsiMeetJS, APP */
-
- import InviteDialogView from './InviteDialogView';
- import createRoomLocker from './RoomLocker';
- import UIEvents from '../../../service/UI/UIEvents';
-
- const ConferenceEvents = JitsiMeetJS.events.conference;
-
- /**
- * Invite module
- * Constructor takes conference object giving
- * ability to subscribe on its events
- */
- class Invite {
- constructor(conference) {
- this.conference = conference;
- this.createRoomLocker(conference);
- this.initDialog();
- this.registerListeners();
- }
-
- /**
- * Registering listeners.
- * Primarily listeners for conference events.
- */
- registerListeners() {
-
- this.conference.on(ConferenceEvents.LOCK_STATE_CHANGED,
- (locked, error) => {
-
- console.log("Received channel password lock change: ", locked,
- error);
-
- if (!locked) {
- this.roomLocker.resetPassword();
- }
-
- this.setLockedFromElsewhere(locked);
- });
-
- this.conference.on(ConferenceEvents.USER_ROLE_CHANGED, (id) => {
- if (APP.conference.isLocalId(id)
- && this.isModerator !== this.conference.isModerator) {
-
- this.setModerator(this.conference.isModerator);
- }
- });
-
- APP.UI.addListener( UIEvents.INVITE_CLICKED,
- () => { this.openLinkDialog(); });
-
- APP.UI.addListener( UIEvents.INVITE_URL_INITIALISED,
- (inviteUrl) => {
- this.updateInviteUrl(inviteUrl);
- });
-
- APP.UI.addListener( UIEvents.PASSWORD_REQUIRED,
- () => {
- this.setLockedFromElsewhere(true);
- this.roomLocker.requirePassword().then(() => {
- let pass = this.roomLocker.password;
- // we received that password is required, but user is trying
- // anyway to login without a password, mark room as not
- // locked in case he succeeds (maybe someone removed the
- // password meanwhile), if it is still locked another
- // password required will be received and the room again
- // will be marked as locked.
- if (!pass)
- this.setLockedFromElsewhere(false);
- this.conference.join(this.roomLocker.password);
- });
- });
- }
-
- /**
- * Updates the view.
- * If dialog hasn't been defined -
- * creates it and updates
- */
- updateView() {
- if (!this.view) {
- this.initDialog();
- }
-
- this.view.updateView();
- }
-
- /**
- * Room locker factory
- * @param room
- * @returns {Object} RoomLocker
- * @factory
- */
- createRoomLocker(room = this.conference) {
- let roomLocker = createRoomLocker(room);
- this.roomLocker = roomLocker;
- return this.getRoomLocker();
- }
-
- /**
- * Room locker getter
- * @returns {Object} RoomLocker
- */
- getRoomLocker() {
- return this.roomLocker;
- }
-
- /**
- * Opens the invite link dialog.
- */
- openLinkDialog () {
- if (!this.view) {
- this.initDialog();
- }
-
- this.view.open();
- }
-
- /**
- * Dialog initialization.
- * creating view object using as a model this module
- */
- initDialog() {
- this.password = this.getPassword();
- this.view = new InviteDialogView(this);
- }
-
- /**
- * Password getter
- * @returns {String} password
- */
- getPassword() {
- return this.roomLocker.password;
- }
-
- /**
- * Switches between the moderator view and normal view.
- *
- * @param isModerator indicates if the participant is moderator
- */
- setModerator(isModerator) {
- this.isModerator = isModerator;
-
- this.updateView();
- }
-
- /**
- * Allows to unlock the room.
- * If the current user is moderator.
- */
- setRoomUnlocked() {
- if (this.isModerator) {
- this.roomLocker.lock().then(() => {
- APP.UI.emitEvent(UIEvents.TOGGLE_ROOM_LOCK);
- this.updateView();
- });
- }
- }
-
- /**
- * Allows to lock the room if
- * the current user is moderator.
- * Takes the password.
- * @param {String} newPass
- */
- setRoomLocked(newPass) {
- let isModerator = this.isModerator;
- if (isModerator && (newPass || !this.roomLocker.isLocked)) {
- this.roomLocker.lock(newPass).then(() => {
- APP.UI.emitEvent(UIEvents.TOGGLE_ROOM_LOCK);
- this.updateView();
- });
- }
- }
-
- /**
- * Updates the room invite url.
- */
- updateInviteUrl (newInviteUrl) {
- this.inviteUrl = newInviteUrl;
- this.updateView();
- }
-
- /**
- * Helper method for encoding
- * Invite URL
- * @returns {string}
- */
- getEncodedInviteUrl() {
- return encodeURI(this.inviteUrl);
- }
-
- /**
- * Is locked flag.
- * Delegates to room locker
- * @returns {Boolean} isLocked
- */
- isLocked() {
- return this.roomLocker.isLocked;
- }
-
- /**
- * Set flag locked from elsewhere to room locker.
- * @param isLocked
- */
- setLockedFromElsewhere(isLocked) {
- let oldLockState = this.roomLocker.lockedElsewhere;
- if (oldLockState !== isLocked) {
- this.roomLocker.lockedElsewhere = isLocked;
- APP.UI.emitEvent(UIEvents.TOGGLE_ROOM_LOCK);
- this.updateView();
- }
- }
- }
-
- export default Invite;
|