From 71607499b3ffbf6cb46758fe93e6d300b62c6b88 Mon Sep 17 00:00:00 2001 From: isymchych Date: Wed, 9 Dec 2015 19:40:40 +0200 Subject: [PATCH] add methods to lock/unlock conference --- JitsiConference.js | 38 ++++++++++++++++++++++++++++++++++++-- JitsiConferenceErrors.js | 4 ++++ doc/API.md | 9 +++++++++ 3 files changed, 49 insertions(+), 2 deletions(-) diff --git a/JitsiConference.js b/JitsiConference.js index ff56d51b3..1f9685872 100644 --- a/JitsiConference.js +++ b/JitsiConference.js @@ -6,6 +6,7 @@ var XMPPEvents = require("./service/xmpp/XMPPEvents"); var RTCEvents = require("./service/RTC/RTCEvents"); var EventEmitter = require("events"); var JitsiConferenceEvents = require("./JitsiConferenceEvents"); +var JitsiConferenceErrors = require("./JitsiConferenceErrors"); var JitsiParticipant = require("./JitsiParticipant"); var Statistics = require("./modules/statistics/statistics"); var JitsiDTMFManager = require('./modules/DTMF/JitsiDTMFManager'); @@ -244,6 +245,36 @@ JitsiConference.prototype.isModerator = function () { return this.room.isModerator(); }; +/** + * Set password for the room. + * @param {string} password new password for the room. + * @returns {Promise} + */ +JitsiConference.prototype.lock = function (password) { + if (!this.isModerator()) { + return Promise.reject(); + } + + var conference = this; + return new Promise(function (resolve, reject) { + conference.xmpp.lockRoom(password, function () { + resolve(); + }, function (err) { + reject(err); + }, function () { + reject(JitsiConferenceErrors.PASSWORD_REQUIRED); + }); + }); +}; + +/** + * Remove password from the room. + * @returns {Promise} + */ +JitsiConference.prototype.unlock = function () { + return this.lock(undefined); +}; + /** * Elects the participant with the given id to be the selected participant or the speaker. * @param id the identifier of the participant @@ -288,7 +319,7 @@ JitsiConference.prototype.onMemberJoined = function (jid, email, nick) { var participant = new JitsiParticipant(id, this, nick); this.eventEmitter.emit(JitsiConferenceEvents.USER_JOINED, id); this.participants[id] = participant; - this.connection.xmpp.connection.disco.info( + this.xmpp.connection.disco.info( jid, "node", function(iq) { participant._supportsDTMF = $(iq).find( '>query>feature[var="urn:xmpp:jingle:dtmf:0"]').length > 0; @@ -396,7 +427,7 @@ JitsiConference.prototype.myUserId = function () { JitsiConference.prototype.sendTones = function (tones, duration, pause) { if (!this.dtmfManager) { - var connection = this.connection.xmpp.connection.jingle.activecall.peerconnection; + var connection = this.xmpp.connection.jingle.activecall.peerconnection; if (!connection) { logger.warn("cannot sendTones: no conneciton"); return; @@ -480,6 +511,9 @@ function setupListeners(conference) { conference.eventEmitter.emit(JitsiConferenceEvents.LAST_N_ENDPOINTS_CHANGED, lastNEndpoints, endpointsEnteringLastN); }); + conference.xmpp.addListener(XMPPEvents.PASSWORD_REQUIRED, function () { + conference.eventEmitter.emit(JitsiConferenceErrors.PASSWORD_REQUIRED); + }); if(conference.statistics) { //FIXME: Maybe remove event should not be associated with the conference. diff --git a/JitsiConferenceErrors.js b/JitsiConferenceErrors.js index 209aaf0f8..5d45bc97e 100644 --- a/JitsiConferenceErrors.js +++ b/JitsiConferenceErrors.js @@ -7,6 +7,10 @@ var JitsiConferenceErrors = { * Indicates that a password is required in order to join the conference. */ PASSWORD_REQUIRED: "conference.passwordRequired", + /** + * Indicates that password cannot be set for this conference. + */ + PASSWORD_NOT_SUPPORTED: "conference.passwordNotSupported", /** * Indicates that a connection error occurred when trying to join a * conference. diff --git a/doc/API.md b/doc/API.md index 22e954c01..81a7edebd 100644 --- a/doc/API.md +++ b/doc/API.md @@ -93,6 +93,7 @@ JitsiMeetJS.setLogLevel(JitsiMeetJS.logLevels.ERROR); 1. conference - CONNECTION_ERROR - the connection with the conference is lost. - PASSWORD_REQUIRED - that error can be passed when the connection to the conference failed. You should try to join the conference with password. + - PASSWORD_NOT_SUPPORTED - indicates that password cannot be set for this conference - VIDEOBRIDGE_NOT_AVAILABLE - video bridge issues. 2. connection - PASSWORD_REQUIRED - passed when the connection to the server failed. You should try to authenticate with password. @@ -225,6 +226,14 @@ The object represents a conference. We have the following methods to control the 21. isModerator() - checks if local user has "moderator" role +22. lock(password) - set password for the conference; returns Promise + - password - string password + + Note: available only for moderator + +23. unlock() - unset conference password; returns Promise + + Note: available only for moderator JitsiTrack ======