Show:
  1. 'use strict';
  2.  
  3. const debug = require('debug')('Cantabile');
  4. const EndPoint = require('./EndPoint');
  5. const fetch = require('node-fetch');
  6.  
  7. /**
  8. * Provides access to Cantabile's engine object for start/stop control
  9. *
  10. * Access this object via the {{#crossLink "Cantabile/engine:property"}}{{/crossLink}} property.
  11. *
  12. * @class Engine
  13. * @extends EndPoint
  14. */
  15. class Engine
  16. {
  17. constructor(owner)
  18. {
  19. this.owner = owner;
  20. }
  21.  
  22. /**
  23. * Returns a promise to provide the started state of Cantabile's audio engine.
  24. *
  25. * This API is only available via AJAX, and not WebSocket
  26. *
  27. * @method isStarted
  28. * @type {Promise|Boolean}
  29. */
  30. async isStarted()
  31. {
  32. let f = await fetch(EndPoint.joinPath(this.owner.hostUrl, "api/engine/")).then(r => r.json());
  33. return f.isStarted;
  34. }
  35.  
  36. /**
  37. * Starts Cantabile's audio engine
  38. *
  39. * This API is only available via AJAX, and not WebSocket
  40. *
  41. * @method start
  42. * @type {Promise}
  43. */
  44. async start()
  45. {
  46. await fetch(EndPoint.joinPath(this.owner.hostUrl, "api/engine/start"), { method: "POST" });
  47. }
  48.  
  49. /**
  50. * Stops Cantabile's audio engine
  51. *
  52. * This API is only available via AJAX, and not WebSocket
  53. *
  54. * @method start
  55. * @type {Promise}
  56. */
  57. async stop()
  58. {
  59. await fetch(EndPoint.joinPath(this.owner.hostUrl, "api/engine/stop"), { method: "POST" });
  60. }
  61.  
  62. /**
  63. * Restarts Cantabile's audio engine
  64. *
  65. * This API is only available via AJAX, and not WebSocket
  66. *
  67. * @method restart
  68. * @type {Promise}
  69. */
  70. async restart()
  71. {
  72. await fetch(EndPoint.joinPath(this.owner.hostUrl, "api/engine/restart"), { method: "POST" });
  73. }
  74. /**
  75. * Toggles the audio engine between started and stopped
  76. *
  77. * This API is only available via AJAX, and not WebSocket
  78. *
  79. * @method restart
  80. * @type {Promise}
  81. */
  82. async startStop()
  83. {
  84. await fetch(EndPoint.joinPath(this.owner.hostUrl, "api/engine/startStop"), { method: "POST" });
  85. }
  86. }
  87.  
  88.  
  89.  
  90. module.exports = Engine;