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 1.9KB

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 { getDynamicBrandingUrl } 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 { customizationReady } = state['features/dynamic-branding'];
  22. if (!customizationReady) {
  23. const url = getDynamicBrandingUrl(state);
  24. if (url) {
  25. try {
  26. const res = await doGetJSON(url);
  27. return dispatch(setDynamicBrandingData(res));
  28. } catch (err) {
  29. logger.error('Error fetching branding data', err);
  30. return dispatch(setDynamicBrandingFailed());
  31. }
  32. }
  33. dispatch(setDynamicBrandingReady());
  34. }
  35. };
  36. }
  37. /**
  38. * Action used to set the user customizations.
  39. *
  40. * @param {Object} value - The custom data to be set.
  41. * @returns {Object}
  42. */
  43. function setDynamicBrandingData(value) {
  44. return {
  45. type: SET_DYNAMIC_BRANDING_DATA,
  46. value
  47. };
  48. }
  49. /**
  50. * Action used to signal the branding elements are ready to be displayed.
  51. *
  52. * @returns {Object}
  53. */
  54. function setDynamicBrandingReady() {
  55. return {
  56. type: SET_DYNAMIC_BRANDING_READY
  57. };
  58. }
  59. /**
  60. * Action used to signal the branding request failed.
  61. *
  62. * @returns {Object}
  63. */
  64. function setDynamicBrandingFailed() {
  65. return {
  66. type: SET_DYNAMIC_BRANDING_FAILED
  67. };
  68. }