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.4KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117
  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, followEntity,
  26. callback, 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. "follow-entity": followEntity
  37. }).up();
  38. logger.log('Set jibri recording: '+state, iq.nodeTree);
  39. console.log(iq.nodeTree);
  40. this.connection.sendIQ(
  41. iq,
  42. function (result) {
  43. callback($(result).find('jibri').attr('state'),
  44. $(result).find('jibri').attr('url'));
  45. },
  46. function (error) {
  47. logger.log('Failed to start recording, error: ', error);
  48. errCallback(error);
  49. });
  50. };
  51. Recording.prototype.toggleRecording = function (token, followEntity) {
  52. var self = this;
  53. return new Promise(function(resolve, reject) {
  54. if (!token) {
  55. reject(new Error("No token passed!"));
  56. logger.error("No token passed!");
  57. return;
  58. }
  59. if(self.state === "on") {
  60. reject(new Error("Recording is already started!"));
  61. logger.error("Recording is already started!");
  62. return;
  63. }
  64. var oldState = self.state;
  65. var newState = (oldState === 'off' || !oldState) ? 'on' : 'off';
  66. self.setRecording(newState,
  67. token, followEntity,
  68. function (state, url) {
  69. logger.log("New recording state: ", state);
  70. if (state && state !== oldState) {
  71. self.state = state;
  72. self.url = url;
  73. resolve();
  74. } else {
  75. reject(new Error("State not changed!"));
  76. }
  77. },
  78. function (error) {
  79. reject(error);
  80. }
  81. );
  82. });
  83. };
  84. /**
  85. * Returns true if the recording is supproted and false if not.
  86. */
  87. Recording.prototype.isSupported = function () {
  88. return this._isSupported;
  89. };
  90. /**
  91. * Returns null if the recording is not supported, "on" if the recording started
  92. * and "off" if the recording is not started.
  93. */
  94. Recording.prototype.getState = function () {
  95. return this.state;
  96. };
  97. /**
  98. * Returns the url of the recorded video.
  99. */
  100. Recording.prototype.getURL = function () {
  101. return this.url;
  102. };
  103. module.exports = Recording;