RealtimeServer.js 1.7 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364
  1. /* eslint-disable
  2. handle-callback-err,
  3. */
  4. // TODO: This file was created by bulk-decaffeinate.
  5. // Fix any style issues and re-enable lint.
  6. /*
  7. * decaffeinate suggestions:
  8. * DS101: Remove unnecessary use of Array.from
  9. * DS102: Remove unnecessary code created because of implicit returns
  10. * DS103: Rewrite code to no longer use __guard__
  11. * DS205: Consider reworking code to avoid use of IIFEs
  12. * DS207: Consider shorter variations of null checks
  13. * Full docs: https://github.com/decaffeinate/decaffeinate/blob/master/docs/suggestions.md
  14. */
  15. const app = require('../../../../app')
  16. const logger = require('logger-sharelatex')
  17. const Settings = require('settings-sharelatex')
  18. module.exports = {
  19. running: false,
  20. initing: false,
  21. callbacks: [],
  22. ensureRunning(callback) {
  23. if (callback == null) {
  24. callback = function (error) {}
  25. }
  26. if (this.running) {
  27. return callback()
  28. } else if (this.initing) {
  29. return this.callbacks.push(callback)
  30. } else {
  31. this.initing = true
  32. this.callbacks.push(callback)
  33. return app.listen(
  34. __guard__(
  35. Settings.internal != null ? Settings.internal.realtime : undefined,
  36. (x) => x.port
  37. ),
  38. 'localhost',
  39. (error) => {
  40. if (error != null) {
  41. throw error
  42. }
  43. this.running = true
  44. logger.log('clsi running in dev mode')
  45. return (() => {
  46. const result = []
  47. for (callback of Array.from(this.callbacks)) {
  48. result.push(callback())
  49. }
  50. return result
  51. })()
  52. }
  53. )
  54. }
  55. }
  56. }
  57. function __guard__(value, transform) {
  58. return typeof value !== 'undefined' && value !== null
  59. ? transform(value)
  60. : undefined
  61. }