Add support for jirecon and colibri in the recording

This commit is contained in:
hristoterezov 2015-12-30 17:15:11 -06:00
parent 6deea8bca2
commit 6b754e1937
6 changed files with 280 additions and 93 deletions

View File

@ -568,11 +568,10 @@ JitsiConference.prototype.getRecordingURL = function () {
/**
* Starts/stops the recording
* @param token a token for authentication.
*/
JitsiConference.prototype.toggleRecording = function (token, followEntity) {
JitsiConference.prototype.toggleRecording = function (options) {
if(this.room)
return this.room.toggleRecording(token, followEntity);
return this.room.toggleRecording(options);
return new Promise(function(resolve, reject){
reject(new Error("The conference is not created yet!"))});
}

View File

@ -150,6 +150,8 @@ This objects represents the server connection. You can create new ```JitsiConnec
2. resolution - the prefered resolution for the local video.
3. openSctp - boolean property. Enables/disables datachannel support. **NOTE: we recommend to set that option to true**
4. disableAudioLevels - boolean property. Enables/disables audio levels.
5. recordingType - the type of recording to be used
6. jirecon
5. addEventListener(event, listener) - Subscribes the passed listener to the event.
- event - one of the events from ```JitsiMeetJS.events.connection``` object.

File diff suppressed because one or more lines are too long

24
lib-jitsi-meet.min.js vendored

File diff suppressed because one or more lines are too long

View File

@ -284,8 +284,9 @@ ChatRoom.prototype.onPresence = function (pres) {
if (member.isFocus) {
this.focusMucJid = from;
if(!this.recording) {
this.recording = new Recorder(this.eventEmitter, this.connection,
this.focusMucJid);
this.recording = new Recorder(this.options.recordingType,
this.eventEmitter, this.connection, this.focusMucJid,
this.options.jirecon, this.roomjid);
if(this.lastJibri)
this.recording.handleJibriPresence(this.lastJibri);
}
@ -698,9 +699,9 @@ ChatRoom.prototype.getRecordingURL = function () {
* Starts/stops the recording
* @param token token for authentication
*/
ChatRoom.prototype.toggleRecording = function (token, followEntity) {
ChatRoom.prototype.toggleRecording = function (options) {
if(this.recording)
return this.recording.toggleRecording(token, followEntity);
return this.recording.toggleRecording(options);
return new Promise(function(resolve, reject){
reject(new Error("The conference is not created yet!"))});

View File

@ -3,15 +3,31 @@
var XMPPEvents = require("../../service/XMPP/XMPPEvents");
var logger = require("jitsi-meet-logger").getLogger(__filename);
function Recording(ee, connection, focusMucJid) {
this.eventEmitter = ee;
function Recording(type, eventEmitter, connection, focusMucJid, jirecon,
roomjid) {
this.eventEmitter = eventEmitter;
this.connection = connection;
this.state = "off";
this.focusMucJid = focusMucJid;
this.jirecon = jirecon;
this.url = null;
this.type = type;
this._isSupported = false;
/**
* The ID of the jirecon recording session. Jirecon generates it when we
* initially start recording, and it needs to be used in subsequent requests
* to jirecon.
*/
this.jireconRid = null;
this.roomjid = roomjid;
}
Recording.types = {
COLIBRI: "colibri",
JIRECON: "jirecon",
JIBRI: "jibri"
};
Recording.prototype.handleJibriPresence = function (jibri) {
var attributes = jibri.attributes;
if(!attributes)
@ -26,20 +42,20 @@ Recording.prototype.handleJibriPresence = function (jibri) {
this.eventEmitter.emit(XMPPEvents.RECORDING_STATE_CHANGED);
};
Recording.prototype.setRecording = function (state, streamId, followEntity,
callback, errCallback){
Recording.prototype.setRecordingJibri = function (state, callback, errCallback,
options) {
if (state == this.state){
return;
errCallback(new Error("Invalid state!"));
}
options = options || {};
// FIXME jibri does not accept IQ without 'url' attribute set ?
var iq = $iq({to: this.focusMucJid, type: 'set'})
.c('jibri', {
"xmlns": 'http://jitsi.org/protocol/jibri',
"action": (state === 'on') ? 'start' : 'stop',
"streamid": streamId,
"follow-entity": followEntity
"streamid": options.streamId,
"follow-entity": options.followEntity
}).up();
logger.log('Set jibri recording: '+state, iq.nodeTree);
@ -56,39 +72,130 @@ Recording.prototype.setRecording = function (state, streamId, followEntity,
});
};
Recording.prototype.toggleRecording = function (token, followEntity) {
Recording.prototype.setRecordingJirecon =
function (state, callback, errCallback, options) {
if (state == this.state){
errCallback(new Error("Invalid state!"));
}
var iq = $iq({to: this.jirecon, type: 'set'})
.c('recording', {xmlns: 'http://jitsi.org/protocol/jirecon',
action: (state === 'on') ? 'start' : 'stop',
mucjid: this.roomjid});
if (state === 'off'){
iq.attrs({rid: this.jireconRid});
}
console.log('Start recording');
var self = this;
this.connection.sendIQ(
iq,
function (result) {
// TODO wait for an IQ with the real status, since this is
// provisional?
self.jireconRid = $(result).find('recording').attr('rid');
console.log('Recording ' +
((state === 'on') ? 'started' : 'stopped') +
'(jirecon)' + result);
self.state = state;
if (state === 'off'){
self.jireconRid = null;
}
callback(state);
},
function (error) {
console.log('Failed to start recording, error: ', error);
errCallback(error);
});
};
// Sends a COLIBRI message which enables or disables (according to 'state')
// the recording on the bridge. Waits for the result IQ and calls 'callback'
// with the new recording state, according to the IQ.
Recording.prototype.setRecordingColibri =
function (state, callback, errCallback, options) {
var elem = $iq({to: this.focusMucJid, type: 'set'});
elem.c('conference', {
xmlns: 'http://jitsi.org/protocol/colibri'
});
elem.c('recording', {state: state, token: options.token});
var self = this;
this.connection.sendIQ(elem,
function (result) {
console.log('Set recording "', state, '". Result:', result);
var recordingElem = $(result).find('>conference>recording');
var newState = recordingElem.attr('state');
self.state = newState;
callback(newState);
if (newState === 'pending') {
connection.addHandler(function(iq){
var state = $(iq).find('recording').attr('state');
if (state) {
self.state = newState;
callback(state);
}
}, 'http://jitsi.org/protocol/colibri', 'iq', null, null, null);
}
},
function (error) {
console.warn(error);
errCallback(error);
}
);
};
Recording.prototype.setRecording =
function (state, callback, errCallback, options) {
switch(this.type){
case Recording.types.JIRECON:
this.setRecordingJirecon(state, callback, errCallback, options);
break;
case Recording.types.COLIBRI:
this.setRecordingColibri(state, callback, errCallback, options);
break;
case Recording.types.JIBRI:
this.setRecordingJibri(state, callback, errCallback, options);
break;
default:
console.error("Unknown recording type!");
return;
}
};
Recording.prototype.toggleRecording = function (options) {
var self = this;
return new Promise(function(resolve, reject) {
if (!token) {
if ((!options.token && self.type === Recording.types.COLIBRI) ||
(!options.streamId && self.type === Recording.types.JIBRI)){
reject(new Error("No token passed!"));
logger.error("No token passed!");
return;
}
if(self.state === "on") {
reject(new Error("Recording is already started!"));
logger.error("Recording is already started!");
return;
}
var oldState = self.state;
var newState = (oldState === 'off' || !oldState) ? 'on' : 'off';
self.setRecording(newState,
token, followEntity,
function (state, url) {
logger.log("New recording state: ", state);
if (state && state !== oldState) {
if(state !== "on" && state !== "off") {
//state === "pending" we are waiting for the real state
return;
}
self.state = state;
self.url = url;
resolve();
} else {
reject(new Error("State not changed!"));
}
},
function (error) {
}, function (error) {
reject(error);
}
);
}, options);
});
};