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

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091
  1. /* global $, $iq, config, connection, focusJid, messageHandler, Moderator,
  2. Toolbar, Util */
  3. var Recording = (function (my) {
  4. var status = false;
  5. var recordingToken = null;
  6. var recordingEnabled = false;
  7. my.setRecordingToken = function (token) {
  8. recordingToken = token;
  9. };
  10. // Sends a COLIBRI message which enables or disables (according to 'state')
  11. // the recording on the bridge. Waits for the result IQ and calls 'callback'
  12. // with the new recording state, according to the IQ.
  13. my.setRecording = function (state, token, callback) {
  14. var self = this;
  15. var elem = $iq({to: focusJid, type: 'set'});
  16. elem.c('conference', {
  17. xmlns: 'http://jitsi.org/protocol/colibri'
  18. });
  19. elem.c('recording', {state: state, token: token});
  20. elem.up();
  21. connection.sendIQ(elem,
  22. function (result) {
  23. console.log('Set recording "', state, '". Result:', result);
  24. var recordingElem = $(result).find('>conference>recording');
  25. var newState = ('true' === recordingElem.attr('state'));
  26. recordingEnabled = newState;
  27. callback(newState);
  28. },
  29. function (error) {
  30. console.warn(error);
  31. }
  32. );
  33. };
  34. my.toggleRecording = function () {
  35. if (!Moderator.isModerator()) {
  36. console.log(
  37. 'non-focus, or conference not yet organized:' +
  38. ' not enabling recording');
  39. return;
  40. }
  41. if (!recordingToken)
  42. {
  43. messageHandler.openTwoButtonDialog(null,
  44. '<h2>Enter recording token</h2>' +
  45. '<input id="recordingToken" type="text" placeholder="token" autofocus>',
  46. false,
  47. "Save",
  48. function (e, v, m, f) {
  49. if (v) {
  50. var token = document.getElementById('recordingToken');
  51. if (token.value) {
  52. my.setRecordingToken(
  53. Util.escapeHtml(token.value));
  54. my.toggleRecording();
  55. }
  56. }
  57. },
  58. function (event) {
  59. document.getElementById('recordingToken').focus();
  60. }
  61. );
  62. return;
  63. }
  64. var oldState = recordingEnabled;
  65. Toolbar.toggleRecordingButtonState();
  66. my.setRecording(!oldState,
  67. recordingToken,
  68. function (state) {
  69. console.log("New recording state: ", state);
  70. if (state == oldState)
  71. {
  72. // Failed to change, reset the token because it might
  73. // have been wrong
  74. Toolbar.toggleRecordingButtonState();
  75. my.setRecordingToken(null);
  76. }
  77. }
  78. );
  79. };
  80. return my;
  81. }(Recording || {}));