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.

setup.web.js 2.4KB

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