2016-10-12 00:08:24 +00:00
|
|
|
/* global JitsiMeetJS, APP */
|
2016-11-11 15:00:54 +00:00
|
|
|
const logger = require("jitsi-meet-logger").getLogger(__filename);
|
2016-10-12 00:08:24 +00:00
|
|
|
|
|
|
|
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;
|
2016-10-21 14:46:09 +00:00
|
|
|
this.inviteUrl = APP.ConferenceUrl.getInviteUrl();
|
2016-10-12 00:08:24 +00:00
|
|
|
this.createRoomLocker(conference);
|
|
|
|
this.registerListeners();
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Registering listeners.
|
|
|
|
* Primarily listeners for conference events.
|
|
|
|
*/
|
|
|
|
registerListeners() {
|
|
|
|
|
|
|
|
this.conference.on(ConferenceEvents.LOCK_STATE_CHANGED,
|
|
|
|
(locked, error) => {
|
|
|
|
|
2016-11-11 15:00:54 +00:00
|
|
|
logger.log("Received channel password lock change: ", locked,
|
2016-10-12 00:08:24 +00:00
|
|
|
error);
|
|
|
|
|
|
|
|
if (!locked) {
|
2016-10-21 15:03:25 +00:00
|
|
|
this.getRoomLocker().resetPassword();
|
2016-10-12 00:08:24 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
this.setLockedFromElsewhere(locked);
|
|
|
|
});
|
|
|
|
|
2016-10-12 00:09:16 +00:00
|
|
|
this.conference.on(ConferenceEvents.USER_ROLE_CHANGED, (id) => {
|
2016-10-12 00:08:24 +00:00
|
|
|
if (APP.conference.isLocalId(id)
|
2016-10-31 19:01:22 +00:00
|
|
|
&& this.isModerator !== this.conference.isModerator()) {
|
2016-10-12 00:08:24 +00:00
|
|
|
|
2016-10-31 19:01:22 +00:00
|
|
|
this.setModerator(this.conference.isModerator());
|
2016-10-12 00:08:24 +00:00
|
|
|
}
|
|
|
|
});
|
|
|
|
|
|
|
|
APP.UI.addListener( UIEvents.INVITE_CLICKED,
|
|
|
|
() => { this.openLinkDialog(); });
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* 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.view = new InviteDialogView(this);
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Password getter
|
|
|
|
* @returns {String} password
|
|
|
|
*/
|
|
|
|
getPassword() {
|
2016-10-21 15:03:25 +00:00
|
|
|
return this.getRoomLocker().password;
|
2016-10-12 00:08:24 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* 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) {
|
2016-10-21 15:03:25 +00:00
|
|
|
this.getRoomLocker().lock().then(() => {
|
2016-10-12 00:08:24 +00:00
|
|
|
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;
|
2016-10-21 15:03:25 +00:00
|
|
|
if (isModerator && (newPass || !this.getRoomLocker().isLocked)) {
|
|
|
|
this.getRoomLocker().lock(newPass).then(() => {
|
2016-10-12 00:08:24 +00:00
|
|
|
APP.UI.emitEvent(UIEvents.TOGGLE_ROOM_LOCK);
|
|
|
|
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() {
|
2016-10-21 15:03:25 +00:00
|
|
|
return this.getRoomLocker().isLocked;
|
2016-10-12 00:08:24 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Set flag locked from elsewhere to room locker.
|
|
|
|
* @param isLocked
|
|
|
|
*/
|
|
|
|
setLockedFromElsewhere(isLocked) {
|
2016-10-21 15:03:25 +00:00
|
|
|
let roomLocker = this.getRoomLocker();
|
|
|
|
let oldLockState = roomLocker.isLocked;
|
2016-10-31 19:01:22 +00:00
|
|
|
if (oldLockState !== isLocked) {
|
2016-10-21 15:03:25 +00:00
|
|
|
roomLocker.lockedElsewhere = isLocked;
|
2016-10-12 00:08:24 +00:00
|
|
|
APP.UI.emitEvent(UIEvents.TOGGLE_ROOM_LOCK);
|
|
|
|
this.updateView();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
export default Invite;
|