Converse converse.js

Source: headless/shared/_converse.js

  1. import i18n from './i18n.js';
  2. import log from '../log.js';
  3. import pluggable from 'pluggable.js/src/pluggable.js';
  4. import { Events } from '@converse/skeletor/src/events.js';
  5. import { Router } from '@converse/skeletor/src/router.js';
  6. import { createStore, getDefaultStore } from '../utils/storage.js';
  7. import { getInitSettings } from './settings/utils.js';
  8. import { getOpenPromise } from '@converse/openpromise';
  9. import { shouldClearCache } from '../utils/core.js';
  10. import {
  11. ACTIVE,
  12. ANONYMOUS,
  13. CHATROOMS_TYPE,
  14. CLOSED,
  15. COMPOSING,
  16. CONTROLBOX_TYPE,
  17. DEFAULT_IMAGE,
  18. DEFAULT_IMAGE_TYPE,
  19. EXTERNAL,
  20. FAILURE,
  21. GONE,
  22. HEADLINES_TYPE,
  23. INACTIVE,
  24. LOGIN,
  25. LOGOUT,
  26. OPENED,
  27. PAUSED,
  28. PREBIND,
  29. PRIVATE_CHAT_TYPE,
  30. SUCCESS,
  31. VERSION_NAME
  32. } from './constants';
  33. /**
  34. * A private, closured object containing the private api (via {@link _converse.api})
  35. * as well as private methods and internal data-structures.
  36. * @global
  37. * @namespace _converse
  38. */
  39. const _converse = {
  40. log,
  41. shouldClearCache, // TODO: Should be moved to utils with next major release
  42. VERSION_NAME,
  43. templates: {},
  44. promises: {
  45. 'initialized': getOpenPromise()
  46. },
  47. // TODO: remove constants in next major release
  48. ANONYMOUS,
  49. CLOSED,
  50. EXTERNAL,
  51. LOGIN,
  52. LOGOUT,
  53. OPENED,
  54. PREBIND,
  55. SUCCESS,
  56. FAILURE,
  57. DEFAULT_IMAGE_TYPE,
  58. DEFAULT_IMAGE,
  59. INACTIVE,
  60. ACTIVE,
  61. COMPOSING,
  62. PAUSED,
  63. GONE,
  64. PRIVATE_CHAT_TYPE,
  65. CHATROOMS_TYPE,
  66. HEADLINES_TYPE,
  67. CONTROLBOX_TYPE,
  68. // Set as module attr so that we can override in tests.
  69. // TODO: replace with config settings
  70. TIMEOUTS: {
  71. PAUSED: 10000,
  72. INACTIVE: 90000
  73. },
  74. default_connection_options: {'explicitResourceBinding': true},
  75. router: new Router(),
  76. isTestEnv: () => {
  77. return getInitSettings()['bosh_service_url'] === 'montague.lit/http-bind';
  78. },
  79. getDefaultStore,
  80. createStore,
  81. /**
  82. * Translate the given string based on the current locale.
  83. * @method __
  84. * @private
  85. * @memberOf _converse
  86. * @param { String } str
  87. */
  88. '__': (...args) => i18n.__(...args),
  89. /**
  90. * A no-op method which is used to signal to gettext that the passed in string
  91. * should be included in the pot translation file.
  92. *
  93. * In contrast to the double-underscore method, the triple underscore method
  94. * doesn't actually translate the strings.
  95. *
  96. * One reason for this method might be because we're using strings we cannot
  97. * send to the translation function because they require variable interpolation
  98. * and we don't yet have the variables at scan time.
  99. *
  100. * @method ___
  101. * @private
  102. * @memberOf _converse
  103. * @param { String } str
  104. */
  105. '___': str => str
  106. }
  107. // Make _converse an event emitter
  108. Object.assign(_converse, Events);
  109. // Make _converse pluggable
  110. pluggable.enable(_converse, '_converse', 'pluggable');
  111. export default _converse;