You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

recording.js 2.2KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273
  1. /* global $, $iq, config, connection, focusMucJid, messageHandler,
  2. Toolbar, Util */
  3. var XMPPEvents = require("../../service/XMPP/XMPPEvents");
  4. function Recording(ee, connection, focusMucJid) {
  5. this.eventEmitter = ee;
  6. this.connection = connection;
  7. this.connection.jibri.setHandler(this.handleJibriIq);
  8. this.state = "off";
  9. this.focusMucJid = focusMucJid;
  10. this.url = null;
  11. this.isRecordingSupported = false;
  12. };
  13. Recording.prototype.handleJibriPresence = function (jibri) {
  14. this.eventEmitter.emit(XMPPEvents.RECORDING_STATE_CHANGED);
  15. }
  16. Recording.prototype.setRecording = function (state, streamId, callback){
  17. if (state == this.state){
  18. return;
  19. }
  20. var iq = $iq({to: this.focusMucJid, type: 'set'})
  21. .c('jibri', {
  22. xmlns: 'http://jitsi.org/protocol/jibri',
  23. action: (state === 'on') ? 'start' : 'stop',
  24. streamId: streamId
  25. }).up();
  26. console.log('Set jibri recording: '+state, iq);
  27. this.connection.sendIQ(
  28. iq,
  29. function (result) {
  30. var recordingEnabled = $(result).find('jibri').attr('state');
  31. console.log('Jibri recording is now: ' + recordingEnabled);
  32. //TODO hook us up to further jibri IQs so we can update the status
  33. callback(recordingEnabled);
  34. },
  35. function (error) {
  36. console.log('Failed to start recording, error: ', error);
  37. callback(recordingEnabled);
  38. });
  39. }
  40. Recording.prototype.toggleRecording = function (token) {
  41. // Jirecon does not (currently) support a token.
  42. if (!token) {
  43. console.error("No token passed!");
  44. return;
  45. }
  46. var oldState = this.state;
  47. var newState = (oldState === 'off' || !oldState) ? 'on' : 'off';
  48. this.setRecording(newState,
  49. token,
  50. function (state) {
  51. console.log("New recording state: ", state);
  52. if (state !== oldState) {
  53. this.state = state;
  54. this.eventEmitter.emit(XMPPEvents.RECORDING_STATE_CHANGED, state);
  55. }
  56. }
  57. );
  58. }
  59. };
  60. module.exports = Recording;