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.web.js 5.8KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214
  1. /* global APP, JitsiMeetJS, loggingConfig */
  2. import { isRoomValid } from '../base/conference';
  3. import { RouteRegistry } from '../base/navigator';
  4. import { Conference } from '../conference';
  5. import { WelcomePage } from '../welcome';
  6. import getTokenData from '../../../modules/tokendata/TokenData';
  7. import settings from '../../../modules/settings/Settings';
  8. import URLProcessor from '../../../modules/config/URLProcessor';
  9. import JitsiMeetLogStorage from '../../../modules/util/JitsiMeetLogStorage';
  10. // eslint-disable-next-line max-len
  11. import KeyboardShortcut from '../../../modules/keyboardshortcut/keyboardshortcut';
  12. const Logger = require('jitsi-meet-logger');
  13. const LogCollector = Logger.LogCollector;
  14. /**
  15. * Gets room name and domain from URL object.
  16. *
  17. * @param {URL} url - URL object.
  18. * @private
  19. * @returns {{
  20. * domain: (string|undefined),
  21. * room: (string|undefined)
  22. * }}
  23. */
  24. function _getRoomAndDomainFromUrlObject(url) {
  25. let domain;
  26. let room;
  27. if (url) {
  28. domain = url.hostname;
  29. room = url.pathname.substr(1);
  30. // Convert empty string to undefined to simplify checks.
  31. if (room === '') {
  32. room = undefined;
  33. }
  34. if (domain === '') {
  35. domain = undefined;
  36. }
  37. }
  38. return {
  39. domain,
  40. room
  41. };
  42. }
  43. /**
  44. * Gets conference room name and connection domain from URL.
  45. *
  46. * @param {(string|undefined)} url - URL.
  47. * @returns {{
  48. * domain: (string|undefined),
  49. * room: (string|undefined)
  50. * }}
  51. */
  52. export function _getRoomAndDomainFromUrlString(url) {
  53. // Rewrite the specified URL in order to handle special cases such as
  54. // hipchat.com and enso.me which do not follow the common pattern of most
  55. // Jitsi Meet deployments.
  56. if (typeof url === 'string') {
  57. // hipchat.com
  58. let regex = /^(https?):\/\/hipchat.com\/video\/call\//gi;
  59. let match = regex.exec(url);
  60. if (!match) {
  61. // enso.me
  62. regex = /^(https?):\/\/enso\.me\/(?:call|meeting)\//gi;
  63. match = regex.exec(url);
  64. }
  65. if (match && match.length > 1) {
  66. /* eslint-disable no-param-reassign, prefer-template */
  67. url
  68. = match[1] /* URL protocol */
  69. + '://enso.hipchat.me/'
  70. + url.substring(regex.lastIndex);
  71. /* eslint-enable no-param-reassign, prefer-template */
  72. }
  73. }
  74. return _getRoomAndDomainFromUrlObject(_urlStringToObject(url));
  75. }
  76. /**
  77. * Determines which route is to be rendered in order to depict a specific Redux
  78. * store.
  79. *
  80. * @param {(Object|Function)} stateOrGetState - Redux state or Regux getState()
  81. * method.
  82. * @returns {Route}
  83. */
  84. export function _getRouteToRender(stateOrGetState) {
  85. const state
  86. = typeof stateOrGetState === 'function'
  87. ? stateOrGetState()
  88. : stateOrGetState;
  89. const room = state['features/base/conference'].room;
  90. const component = isRoomValid(room) ? Conference : WelcomePage;
  91. return RouteRegistry.getRouteByComponent(component);
  92. }
  93. /**
  94. * Parses a string into a URL (object).
  95. *
  96. * @param {(string|undefined)} url - The URL to parse.
  97. * @private
  98. * @returns {URL}
  99. */
  100. function _urlStringToObject(url) {
  101. let urlObj;
  102. if (url) {
  103. try {
  104. urlObj = new URL(url);
  105. } catch (ex) {
  106. // The return value will signal the failure & the logged
  107. // exception will provide the details to the developers.
  108. console.log(`${url} seems to be not a valid URL, but it's OK`, ex);
  109. }
  110. }
  111. return urlObj;
  112. }
  113. /**
  114. * Temporary solution. Later we'll get rid of global APP
  115. * and set its properties in redux store.
  116. *
  117. * @returns {void}
  118. */
  119. export function init() {
  120. _setConfigParametersFromUrl();
  121. _initLogging();
  122. APP.keyboardshortcut = KeyboardShortcut;
  123. APP.tokenData = getTokenData();
  124. APP.API.init(APP.tokenData.externalAPISettings);
  125. APP.translation.init(settings.getLanguage());
  126. }
  127. /**
  128. * Initializes logging in the app.
  129. *
  130. * @private
  131. * @returns {void}
  132. */
  133. function _initLogging() {
  134. // Adjust logging level
  135. configureLoggingLevels();
  136. // Create the LogCollector and register it as the global log transport.
  137. // It is done early to capture as much logs as possible. Captured logs
  138. // will be cached, before the JitsiMeetLogStorage gets ready (statistics
  139. // module is initialized).
  140. if (!APP.logCollector && !loggingConfig.disableLogCollector) {
  141. APP.logCollector = new LogCollector(new JitsiMeetLogStorage());
  142. Logger.addGlobalTransport(APP.logCollector);
  143. JitsiMeetJS.addGlobalLogTransport(APP.logCollector);
  144. }
  145. }
  146. /**
  147. * Adjusts the logging levels.
  148. *
  149. * @private
  150. * @returns {void}
  151. */
  152. function configureLoggingLevels() {
  153. // NOTE The library Logger is separated from
  154. // the app loggers, so the levels
  155. // have to be set in two places
  156. // Set default logging level
  157. const defaultLogLevel
  158. = loggingConfig.defaultLogLevel || JitsiMeetJS.logLevels.TRACE;
  159. Logger.setLogLevel(defaultLogLevel);
  160. JitsiMeetJS.setLogLevel(defaultLogLevel);
  161. // NOTE console was used on purpose here to go around the logging
  162. // and always print the default logging level to the console
  163. console.info(`Default logging level set to: ${defaultLogLevel}`);
  164. // Set log level for each logger
  165. if (loggingConfig) {
  166. Object.keys(loggingConfig).forEach(loggerName => {
  167. if (loggerName !== 'defaultLogLevel') {
  168. const level = loggingConfig[loggerName];
  169. Logger.setLogLevelById(level, loggerName);
  170. JitsiMeetJS.setLogLevelById(level, loggerName);
  171. }
  172. });
  173. }
  174. }
  175. /**
  176. * Sets config parameters from query string.
  177. *
  178. * @private
  179. * @returns {void}
  180. */
  181. function _setConfigParametersFromUrl() {
  182. URLProcessor.setConfigParametersFromUrl();
  183. }