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

recording.js 4.0KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108
  1. /* global $, $iq, config, connection, focusJid, messageHandler, Moderator,
  2. Toolbar, Util */
  3. var Recording = (function (my) {
  4. var recordingToken = null;
  5. var recordingEnabled;
  6. my.setRecordingToken = function (token) {
  7. recordingToken = token;
  8. };
  9. // Sends a COLIBRI message which enables or disables (according to 'state')
  10. // the recording on the bridge. Waits for the result IQ and calls 'callback'
  11. // with the new recording state, according to the IQ.
  12. my.setRecording = function (state, token, callback) {
  13. var self = this;
  14. var elem = $iq({to: focusJid, type: 'set'});
  15. elem.c('conference', {
  16. xmlns: 'http://jitsi.org/protocol/colibri'
  17. });
  18. elem.c('recording', {state: state, token: token});
  19. elem.up();
  20. connection.sendIQ(elem,
  21. function (result) {
  22. console.log('Set recording "', state, '". Result:', result);
  23. var recordingElem = $(result).find('>conference>recording');
  24. var newState = ('true' === recordingElem.attr('state'));
  25. recordingEnabled = newState;
  26. callback(newState);
  27. },
  28. function (error) {
  29. console.warn(error);
  30. }
  31. );
  32. };
  33. my.toggleRecording = function () {
  34. if (!Moderator.isModerator()) {
  35. console.log(
  36. 'non-focus, or conference not yet organized:' +
  37. ' not enabling recording');
  38. return;
  39. }
  40. if (!recordingToken)
  41. {
  42. messageHandler.openTwoButtonDialog(null,
  43. '<h2>Enter recording token</h2>' +
  44. '<input id="recordingToken" type="text" placeholder="token" autofocus>',
  45. false,
  46. "Save",
  47. function (e, v, m, f) {
  48. if (v) {
  49. var token = document.getElementById('recordingToken');
  50. if (token.value) {
  51. my.setRecordingToken(
  52. Util.escapeHtml(token.value));
  53. my.toggleRecording();
  54. }
  55. }
  56. },
  57. function (event) {
  58. document.getElementById('recordingToken').focus();
  59. }
  60. );
  61. return;
  62. }
  63. var oldState = recordingEnabled;
  64. Toolbar.setRecordingButtonState(!oldState);
  65. my.setRecording(!oldState,
  66. recordingToken,
  67. function (state) {
  68. console.log("New recording state: ", state);
  69. if (state === oldState)
  70. {
  71. // FIXME: new focus:
  72. // this will not work when moderator changes
  73. // during active session. Then it will assume that
  74. // recording status has changed to true, but it might have
  75. // been already true(and we only received actual status from
  76. // the focus).
  77. //
  78. // SO we start with status null, so that it is initialized
  79. // here and will fail only after second click, so if invalid
  80. // token was used we have to press the button twice before
  81. // current status will be fetched and token will be reset.
  82. //
  83. // Reliable way would be to return authentication error.
  84. // Or status update when moderator connects.
  85. // Or we have to stop recording session when current
  86. // moderator leaves the room.
  87. // Failed to change, reset the token because it might
  88. // have been wrong
  89. my.setRecordingToken(null);
  90. }
  91. // Update with returned status
  92. Toolbar.setRecordingButtonState(state);
  93. }
  94. );
  95. };
  96. return my;
  97. }(Recording || {}));