RealtimeServer.js 1.7 KB

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