diff --git a/JitsiConference.js b/JitsiConference.js index e30c13de3..6b0d18ad9 100644 --- a/JitsiConference.js +++ b/JitsiConference.js @@ -449,7 +449,9 @@ JitsiConference.prototype.getRecordingURL = function () { */ JitsiConference.prototype.toggleRecording = function (token) { if(this.room) - this.room.toggleRecording(token); + return this.room.toggleRecording(token); + return new Promise(function(resolve, reject){ + reject(new Error("The conference is not created yet!"))}); } /** diff --git a/lib-jitsi-meet.js b/lib-jitsi-meet.js index be6cb8313..b5512337c 100644 --- a/lib-jitsi-meet.js +++ b/lib-jitsi-meet.js @@ -451,7 +451,9 @@ JitsiConference.prototype.getRecordingURL = function () { */ JitsiConference.prototype.toggleRecording = function (token) { if(this.room) - this.room.toggleRecording(token); + return this.room.toggleRecording(token); + return new Promise(function(resolve, reject){ + reject(new Error("The conference is not created yet!"))}); } /** @@ -6439,7 +6441,10 @@ ChatRoom.prototype.getRecordingURL = function () { */ ChatRoom.prototype.toggleRecording = function (token) { if(this.recording/** && this.isModerator()**/) - this.recording.toggleRecording(token); + return this.recording.toggleRecording(token); + + return new Promise(function(resolve, reject){ + reject(new Error("The conference is not created yet!"))}); } module.exports = ChatRoom; @@ -10578,7 +10583,7 @@ module.exports = Moderator; }).call(this,"/modules/xmpp/moderator.js") },{"../../service/authentication/AuthenticationEvents":87,"../../service/xmpp/XMPPEvents":91,"../settings/Settings":21,"jitsi-meet-logger":48}],35:[function(require,module,exports){ /* global $, $iq, config, connection, focusMucJid, messageHandler, - Toolbar, Util */ + Toolbar, Util, Promise */ var XMPPEvents = require("../../service/XMPP/XMPPEvents"); function Recording(ee, connection, focusMucJid) { @@ -10595,7 +10600,8 @@ Recording.prototype.handleJibriPresence = function (jibri) { if(!attributes) return; - this._isSupported = (attributes.status && attributes.status !== "undefined"); + this._isSupported = + (attributes.status && attributes.status !== "undefined"); if(this._isSupported) { this.url = attributes.url || null; this.state = attributes.status || "off"; @@ -10603,7 +10609,8 @@ Recording.prototype.handleJibriPresence = function (jibri) { this.eventEmitter.emit(XMPPEvents.RECORDING_STATE_CHANGED); }; -Recording.prototype.setRecording = function (state, streamId, callback){ +Recording.prototype.setRecording = function (state, streamId, callback, + errCallback){ if (state == this.state){ return; } @@ -10620,37 +10627,43 @@ Recording.prototype.setRecording = function (state, streamId, callback){ this.connection.sendIQ( iq, function (result) { - var recordingEnabled = $(result).find('jibri').attr('state'); - console.log('Jibri recording is now: ' + recordingEnabled); - //TODO hook us up to further jibri IQs so we can update the status - callback(recordingEnabled); + callback($(result).find('jibri').attr('state'), + $(result).find('jibri').attr('url')); }, function (error) { console.log('Failed to start recording, error: ', error); - callback(this.state); + errCallback(error); }); }; Recording.prototype.toggleRecording = function (token) { - // Jirecon does not (currently) support a token. - if (!token) { - console.error("No token passed!"); - return; - } - - var oldState = this.state; - var newState = (oldState === 'off' || !oldState) ? 'on' : 'off'; var self = this; - this.setRecording(newState, - token, - function (state) { - console.log("New recording state: ", state); - if (state && state !== oldState) { - self.state = state; - self.eventEmitter.emit(XMPPEvents.RECORDING_STATE_CHANGED); - } + return new Promise(function(resolve, reject) { + if (!token) { + console.error("No token passed!"); + reject(new Error("No token passed!")); } - ); + + var oldState = self.state; + var newState = (oldState === 'off' || !oldState) ? 'on' : 'off'; + + self.setRecording(newState, + token, + function (state, url) { + console.log("New recording state: ", state); + if (state && state !== oldState) { + self.state = state; + self.url = url; + resolve(); + } else { + reject(new Error("State not changed!")); + } + }, + function (error) { + reject(error); + } + ); + }); }; /** diff --git a/modules/xmpp/ChatRoom.js b/modules/xmpp/ChatRoom.js index 60859291b..3c1044488 100644 --- a/modules/xmpp/ChatRoom.js +++ b/modules/xmpp/ChatRoom.js @@ -691,7 +691,10 @@ ChatRoom.prototype.getRecordingURL = function () { */ ChatRoom.prototype.toggleRecording = function (token) { if(this.recording/** && this.isModerator()**/) - this.recording.toggleRecording(token); + return this.recording.toggleRecording(token); + + return new Promise(function(resolve, reject){ + reject(new Error("The conference is not created yet!"))}); } module.exports = ChatRoom; diff --git a/modules/xmpp/recording.js b/modules/xmpp/recording.js index b496156ff..e9cac09f0 100644 --- a/modules/xmpp/recording.js +++ b/modules/xmpp/recording.js @@ -1,5 +1,5 @@ /* global $, $iq, config, connection, focusMucJid, messageHandler, - Toolbar, Util */ + Toolbar, Util, Promise */ var XMPPEvents = require("../../service/XMPP/XMPPEvents"); function Recording(ee, connection, focusMucJid) { @@ -25,7 +25,8 @@ Recording.prototype.handleJibriPresence = function (jibri) { this.eventEmitter.emit(XMPPEvents.RECORDING_STATE_CHANGED); }; -Recording.prototype.setRecording = function (state, streamId, callback){ +Recording.prototype.setRecording = function (state, streamId, callback, + errCallback){ if (state == this.state){ return; } @@ -42,37 +43,43 @@ Recording.prototype.setRecording = function (state, streamId, callback){ this.connection.sendIQ( iq, function (result) { - var recordingEnabled = $(result).find('jibri').attr('state'); - console.log('Jibri recording is now: ' + recordingEnabled); - //TODO hook us up to further jibri IQs so we can update the status - callback(recordingEnabled); + callback($(result).find('jibri').attr('state'), + $(result).find('jibri').attr('url')); }, function (error) { console.log('Failed to start recording, error: ', error); - callback(this.state); + errCallback(error); }); }; Recording.prototype.toggleRecording = function (token) { - // Jirecon does not (currently) support a token. - if (!token) { - console.error("No token passed!"); - return; - } - - var oldState = this.state; - var newState = (oldState === 'off' || !oldState) ? 'on' : 'off'; var self = this; - this.setRecording(newState, - token, - function (state) { - console.log("New recording state: ", state); - if (state && state !== oldState) { - self.state = state; - self.eventEmitter.emit(XMPPEvents.RECORDING_STATE_CHANGED); - } + return new Promise(function(resolve, reject) { + if (!token) { + console.error("No token passed!"); + reject(new Error("No token passed!")); } - ); + + var oldState = self.state; + var newState = (oldState === 'off' || !oldState) ? 'on' : 'off'; + + self.setRecording(newState, + token, + function (state, url) { + console.log("New recording state: ", state); + if (state && state !== oldState) { + self.state = state; + self.url = url; + resolve(); + } else { + reject(new Error("State not changed!")); + } + }, + function (error) { + reject(error); + } + ); + }); }; /**