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.

actions.js 2.0KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182
  1. // @flow
  2. import { getLogger } from 'jitsi-meet-logger';
  3. import { doGetJSON } from '../base/util';
  4. import {
  5. SET_DYNAMIC_BRANDING_DATA,
  6. SET_DYNAMIC_BRANDING_FAILED,
  7. SET_DYNAMIC_BRANDING_READY
  8. } from './actionTypes';
  9. import { extractFqnFromPath } from './functions';
  10. const logger = getLogger(__filename);
  11. /**
  12. * Fetches custom branding data.
  13. * If there is no data or the request fails, sets the `customizationReady` flag
  14. * so the defaults can be displayed.
  15. *
  16. * @returns {Function}
  17. */
  18. export function fetchCustomBrandingData() {
  19. return async function(dispatch: Function, getState: Function) {
  20. const state = getState();
  21. const baseUrl = state['features/base/config'].brandingDataUrl;
  22. const { customizationReady } = state['features/dynamic-branding'];
  23. if (!customizationReady) {
  24. const fqn = extractFqnFromPath(state['features/base/connection'].locationURL.pathname);
  25. if (baseUrl && fqn) {
  26. try {
  27. const res = await doGetJSON(`${baseUrl}?conferenceFqn=${encodeURIComponent(fqn)}`);
  28. return dispatch(setDynamicBrandingData(res));
  29. } catch (err) {
  30. logger.error('Error fetching branding data', err);
  31. return dispatch(setDynamicBrandingFailed());
  32. }
  33. }
  34. dispatch(setDynamicBrandingReady());
  35. }
  36. };
  37. }
  38. /**
  39. * Action used to set the user customizations.
  40. *
  41. * @param {Object} value - The custom data to be set.
  42. * @returns {Object}
  43. */
  44. function setDynamicBrandingData(value) {
  45. return {
  46. type: SET_DYNAMIC_BRANDING_DATA,
  47. value
  48. };
  49. }
  50. /**
  51. * Action used to signal the branding elements are ready to be displayed.
  52. *
  53. * @returns {Object}
  54. */
  55. function setDynamicBrandingReady() {
  56. return {
  57. type: SET_DYNAMIC_BRANDING_READY
  58. };
  59. }
  60. /**
  61. * Action used to signal the branding request failed.
  62. *
  63. * @returns {Object}
  64. */
  65. function setDynamicBrandingFailed() {
  66. return {
  67. type: SET_DYNAMIC_BRANDING_FAILED
  68. };
  69. }