您最多选择25个主题 主题必须以字母或数字开头,可以包含连字符 (-),并且长度不得超过35个字符

recording.js 2.8KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101
  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.isSupported = false;
  12. }
  13. Recording.prototype.handleJibriPresence = function (jibri) {
  14. var attributes = jibri.attributes;
  15. if(!attributes)
  16. return;
  17. this.isSupported = (attributes.status && attributes.status !== "undefined");
  18. if(this.isSupported) {
  19. this.url = attributes.url || null;
  20. this.state = attributes.status || "off";
  21. }
  22. this.eventEmitter.emit(XMPPEvents.RECORDING_STATE_CHANGED);
  23. };
  24. Recording.prototype.setRecording = function (state, streamId, callback){
  25. if (state == this.state){
  26. return;
  27. }
  28. var iq = $iq({to: this.focusMucJid, type: 'set'})
  29. .c('jibri', {
  30. xmlns: 'http://jitsi.org/protocol/jibri',
  31. action: (state === 'on') ? 'start' : 'stop',
  32. streamId: streamId
  33. }).up();
  34. console.log('Set jibri recording: '+state, iq);
  35. this.connection.sendIQ(
  36. iq,
  37. function (result) {
  38. var recordingEnabled = $(result).find('jibri').attr('state');
  39. console.log('Jibri recording is now: ' + recordingEnabled);
  40. //TODO hook us up to further jibri IQs so we can update the status
  41. callback(recordingEnabled);
  42. },
  43. function (error) {
  44. console.log('Failed to start recording, error: ', error);
  45. callback(this.state);
  46. });
  47. };
  48. Recording.prototype.toggleRecording = function (token) {
  49. // Jirecon does not (currently) support a token.
  50. if (!token) {
  51. console.error("No token passed!");
  52. return;
  53. }
  54. var oldState = this.state;
  55. var newState = (oldState === 'off' || !oldState) ? 'on' : 'off';
  56. this.setRecording(newState,
  57. token,
  58. function (state) {
  59. console.log("New recording state: ", state);
  60. if (state !== oldState) {
  61. this.state = state;
  62. this.eventEmitter.emit(XMPPEvents.RECORDING_STATE_CHANGED,
  63. state);
  64. }
  65. }
  66. );
  67. };
  68. /**
  69. * Returns true if the recording is supproted and false if not.
  70. */
  71. Recording.prototype.isSupported = function () {
  72. return this.isSupported;
  73. };
  74. /**
  75. * Returns null if the recording is not supported, "on" if the recording started
  76. * and "off" if the recording is not started.
  77. */
  78. Recording.prototype.getState = function () {
  79. return this.state;
  80. }
  81. /**
  82. * Returns the url of the recorded video.
  83. */
  84. Recording.prototype.getURL = function () {
  85. return this.url;
  86. }
  87. module.exports = Recording;