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.

functions.js 3.0KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117
  1. import { isRoomValid } from '../base/conference';
  2. import { RouteRegistry } from '../base/navigator';
  3. import { Conference } from '../conference';
  4. import { WelcomePage } from '../welcome';
  5. /**
  6. * Gets room name and domain from URL object.
  7. *
  8. * @param {URL} url - URL object.
  9. * @private
  10. * @returns {{
  11. * domain: (string|undefined),
  12. * room: (string|undefined)
  13. * }}
  14. */
  15. function _getRoomAndDomainFromUrlObject(url) {
  16. let domain;
  17. let room;
  18. if (url) {
  19. domain = url.hostname;
  20. room = url.pathname.substr(1).toLowerCase();
  21. // Convert empty string to undefined to simplify checks.
  22. if (room === '') {
  23. room = undefined;
  24. }
  25. if (domain === '') {
  26. domain = undefined;
  27. }
  28. }
  29. return {
  30. domain,
  31. room
  32. };
  33. }
  34. /**
  35. * Gets conference room name and connection domain from URL.
  36. *
  37. * @param {(string|undefined)} url - URL.
  38. * @returns {{
  39. * domain: (string|undefined),
  40. * room: (string|undefined)
  41. * }}
  42. */
  43. export function _getRoomAndDomainFromUrlString(url) {
  44. // Rewrite the specified URL in order to handle special cases such as
  45. // hipchat.com and enso.me which do not follow the common pattern of most
  46. // Jitsi Meet deployments.
  47. if (typeof url === 'string') {
  48. // hipchat.com
  49. let regex = /^(https?):\/\/hipchat.com\/video\/call\//gi;
  50. let match = regex.exec(url);
  51. if (!match) {
  52. // enso.me
  53. regex = /^(https?):\/\/enso\.me\/(?:call|meeting)\//gi;
  54. match = regex.exec(url);
  55. }
  56. if (match && match.length > 1) {
  57. /* eslint-disable no-param-reassign, prefer-template */
  58. url
  59. = match[1] /* URL protocol */
  60. + '://enso.hipchat.me/'
  61. + url.substring(regex.lastIndex);
  62. /* eslint-enable no-param-reassign, prefer-template */
  63. }
  64. }
  65. return _getRoomAndDomainFromUrlObject(_urlStringToObject(url));
  66. }
  67. /**
  68. * Determines which route is to be rendered in order to depict a specific Redux
  69. * store.
  70. *
  71. * @param {(Object|Function)} stateOrGetState - Redux state or Regux getState()
  72. * method.
  73. * @returns {Route}
  74. */
  75. export function _getRouteToRender(stateOrGetState) {
  76. const state
  77. = typeof stateOrGetState === 'function'
  78. ? stateOrGetState()
  79. : stateOrGetState;
  80. const room = state['features/base/conference'].room;
  81. const component = isRoomValid(room) ? Conference : WelcomePage;
  82. return RouteRegistry.getRouteByComponent(component);
  83. }
  84. /**
  85. * Parses a string into a URL (object).
  86. *
  87. * @param {(string|undefined)} url - The URL to parse.
  88. * @private
  89. * @returns {URL}
  90. */
  91. function _urlStringToObject(url) {
  92. let urlObj;
  93. if (url) {
  94. try {
  95. urlObj = new URL(url);
  96. } catch (ex) {
  97. // The return value will signal the failure & the logged
  98. // exception will provide the details to the developers.
  99. console.log(`${url} seems to be not a valid URL, but it's OK`, ex);
  100. }
  101. }
  102. return urlObj;
  103. }