您最多选择25个主题 主题必须以字母或数字开头,可以包含连字符 (-),并且长度不得超过35个字符

setup.web.js 2.5KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980
  1. // @flow
  2. import Bourne from '@hapi/bourne';
  3. import { jitsiLocalStorage } from '@jitsi/js-utils/jitsi-local-storage';
  4. import { browser } from '../lib-jitsi-meet';
  5. import { inIframe } from '../util/iframeUtils';
  6. import { parseURLParams } from '../util/parseURLParams';
  7. import logger from './logger';
  8. declare var APP: Object;
  9. declare var config: Object;
  10. /**
  11. * Handles changes of the fake local storage.
  12. *
  13. * @returns {void}
  14. */
  15. function onFakeLocalStorageChanged() {
  16. APP.API.notifyLocalStorageChanged(jitsiLocalStorage.serialize());
  17. }
  18. /**
  19. * Checks if the local storage of the host page needs to be used instead jitsi-meet's local storage.
  20. *
  21. * @param {Object} urlParams - Object with parsed URL params.
  22. * @returns {boolean} - True if the local storage of the host page needs to be used instead jitsi-meet's local storage
  23. * and false otherwise.
  24. */
  25. function shouldUseHostPageLocalStorage(urlParams) {
  26. // NOTE: normally the url params and the config will be merged into the redux store. But we want to setup the local
  27. // storage as soon as possible, the store is not created yet and the merging of the URL params and the config
  28. // haven't been executed yet. That's why we need to manually parse the URL params and also access the config through
  29. // the global variable.
  30. if (urlParams['config.useHostPageLocalStorage'] === true
  31. || (typeof config === 'object' && config.useHostPageLocalStorage)) {
  32. return true;
  33. }
  34. if (jitsiLocalStorage.isLocalStorageDisabled()) { // We have detected that ou own local storage is not working.
  35. return true;
  36. }
  37. if (browser.isWebKitBased() && inIframe()) {
  38. // WebKit browsers don't persist local storage for third-party iframes.
  39. return true;
  40. }
  41. return false;
  42. }
  43. /**
  44. * Performs initial setup of the jitsiLocalStorage.
  45. *
  46. * @returns {void}
  47. */
  48. function setupJitsiLocalStorage() {
  49. const urlParams = parseURLParams(window.location);
  50. if (shouldUseHostPageLocalStorage(urlParams)) {
  51. try {
  52. const localStorageContent = Bourne.parse(urlParams['appData.localStorageContent']);
  53. if (typeof localStorageContent === 'object') {
  54. Object.keys(localStorageContent).forEach(key => {
  55. jitsiLocalStorage.setItem(key, localStorageContent[key]);
  56. });
  57. }
  58. } catch (error) {
  59. logger.error('Can\'t parse localStorageContent.', error);
  60. }
  61. jitsiLocalStorage.on('changed', onFakeLocalStorageChanged);
  62. }
  63. }
  64. setupJitsiLocalStorage();