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 3.2KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116
  1. /* global $, $iq, config, connection, focusMucJid, messageHandler,
  2. Toolbar, Util, Promise */
  3. var XMPPEvents = require("../../service/XMPP/XMPPEvents");
  4. var logger = require("jitsi-meet-logger").getLogger(__filename);
  5. function Recording(ee, connection, focusMucJid) {
  6. this.eventEmitter = ee;
  7. this.connection = connection;
  8. this.state = "off";
  9. this.focusMucJid = focusMucJid;
  10. this.url = null;
  11. this._isSupported = false;
  12. }
  13. Recording.prototype.handleJibriPresence = function (jibri) {
  14. var attributes = jibri.attributes;
  15. if(!attributes)
  16. return;
  17. this._isSupported =
  18. (attributes.status && attributes.status !== "undefined");
  19. if(this._isSupported) {
  20. this.url = attributes.url || null;
  21. this.state = attributes.status || "off";
  22. }
  23. this.eventEmitter.emit(XMPPEvents.RECORDING_STATE_CHANGED);
  24. };
  25. Recording.prototype.setRecording = function (state, streamId, callback,
  26. errCallback){
  27. if (state == this.state){
  28. return;
  29. }
  30. // FIXME jibri does not accept IQ without 'url' attribute set ?
  31. var iq = $iq({to: this.focusMucJid, type: 'set'})
  32. .c('jibri', {
  33. xmlns: 'http://jitsi.org/protocol/jibri',
  34. action: (state === 'on') ? 'start' : 'stop',
  35. streamid: streamId
  36. }).up();
  37. logger.log('Set jibri recording: '+state, iq);
  38. this.connection.sendIQ(
  39. iq,
  40. function (result) {
  41. callback($(result).find('jibri').attr('state'),
  42. $(result).find('jibri').attr('url'));
  43. },
  44. function (error) {
  45. logger.log('Failed to start recording, error: ', error);
  46. errCallback(error);
  47. });
  48. };
  49. Recording.prototype.toggleRecording = function (token) {
  50. var self = this;
  51. return new Promise(function(resolve, reject) {
  52. if (!token) {
  53. reject(new Error("No token passed!"));
  54. logger.error("No token passed!");
  55. return;
  56. }
  57. if(self.state === "on") {
  58. reject(new Error("Recording is already started!"));
  59. logger.error("Recording is already started!");
  60. return;
  61. }
  62. var oldState = self.state;
  63. var newState = (oldState === 'off' || !oldState) ? 'on' : 'off';
  64. self.setRecording(newState,
  65. token,
  66. function (state, url) {
  67. logger.log("New recording state: ", state);
  68. if (state && state !== oldState) {
  69. self.state = state;
  70. self.url = url;
  71. resolve();
  72. } else {
  73. reject(new Error("State not changed!"));
  74. }
  75. },
  76. function (error) {
  77. reject(error);
  78. }
  79. );
  80. });
  81. };
  82. /**
  83. * Returns true if the recording is supproted and false if not.
  84. */
  85. Recording.prototype.isSupported = function () {
  86. return this._isSupported;
  87. };
  88. /**
  89. * Returns null if the recording is not supported, "on" if the recording started
  90. * and "off" if the recording is not started.
  91. */
  92. Recording.prototype.getState = function () {
  93. return this.state;
  94. };
  95. /**
  96. * Returns the url of the recorded video.
  97. */
  98. Recording.prototype.getURL = function () {
  99. return this.url;
  100. };
  101. module.exports = Recording;