Vous ne pouvez pas sélectionner plus de 25 sujets Les noms de sujets doivent commencer par une lettre ou un nombre, peuvent contenir des tirets ('-') et peuvent comporter jusqu'à 35 caractères.

reducer.ts 6.0KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260
  1. import ReducerRegistry from '../base/redux/ReducerRegistry';
  2. import { type Image } from '../virtual-background/constants';
  3. import {
  4. SET_DYNAMIC_BRANDING_DATA,
  5. SET_DYNAMIC_BRANDING_FAILED,
  6. SET_DYNAMIC_BRANDING_READY,
  7. UNSET_DYNAMIC_BRANDING
  8. } from './actionTypes';
  9. /**
  10. * The name of the redux store/state property which is the root of the redux
  11. * state of the feature {@code dynamic-branding}.
  12. */
  13. const STORE_NAME = 'features/dynamic-branding';
  14. const DEFAULT_STATE = {
  15. /**
  16. * The pool of avatar backgrounds.
  17. *
  18. * @public
  19. * @type {Array<string>}
  20. */
  21. avatarBackgrounds: [],
  22. /**
  23. * The custom background color for the LargeVideo.
  24. *
  25. * @public
  26. * @type {string}
  27. */
  28. backgroundColor: '',
  29. /**
  30. * The custom background image used on the LargeVideo.
  31. *
  32. * @public
  33. * @type {string}
  34. */
  35. backgroundImageUrl: '',
  36. /**
  37. * Flag indicating that the branding data can be displayed.
  38. * This is used in order to avoid image flickering / text changing(blipping).
  39. *
  40. * @public
  41. * @type {boolean}
  42. */
  43. customizationReady: false,
  44. /**
  45. * Flag indicating that the dynamic branding data request has failed.
  46. * When the request fails there is no logo (JitsiWatermark) displayed.
  47. *
  48. * @public
  49. * @type {boolean}
  50. */
  51. customizationFailed: false,
  52. /**
  53. * Flag indicating that the dynamic branding has not been modified and should use
  54. * the default options.
  55. *
  56. * @public
  57. * @type {boolean}
  58. */
  59. defaultBranding: true,
  60. /**
  61. * Url for a custom page for DID numbers list.
  62. *
  63. * @public
  64. * @type {string}
  65. */
  66. didPageUrl: '',
  67. /**
  68. * The custom invite domain.
  69. *
  70. * @public
  71. * @type {string}
  72. */
  73. inviteDomain: '',
  74. /**
  75. * An object containing the mapping between the language and url where the translation
  76. * bundle is hosted.
  77. *
  78. * @public
  79. * @type {Object}
  80. */
  81. labels: null,
  82. /**
  83. * The custom url used when the user clicks the logo.
  84. *
  85. * @public
  86. * @type {string}
  87. */
  88. logoClickUrl: '',
  89. /**
  90. * The custom logo (JitisWatermark).
  91. *
  92. * @public
  93. * @type {string}
  94. */
  95. logoImageUrl: '',
  96. /**
  97. * The generated MUI branded theme based on the custom theme json.
  98. *
  99. * @public
  100. * @type {boolean}
  101. */
  102. muiBrandedTheme: undefined,
  103. /**
  104. * The lobby/prejoin background.
  105. *
  106. * @public
  107. * @type {string}
  108. */
  109. premeetingBackground: '',
  110. /**
  111. * Flag used to signal if the app should use a custom logo or not.
  112. *
  113. * @public
  114. * @type {boolean}
  115. */
  116. useDynamicBrandingData: false,
  117. /**
  118. * An array of images to be used as virtual backgrounds instead of the default ones.
  119. *
  120. * @public
  121. * @type {Array<Object>}
  122. */
  123. virtualBackgrounds: []
  124. };
  125. export interface IDynamicBrandingState {
  126. avatarBackgrounds: string[];
  127. backgroundColor: string;
  128. backgroundImageUrl: string;
  129. brandedIcons?: Record<string, string>;
  130. customizationFailed: boolean;
  131. customizationReady: boolean;
  132. defaultBranding: boolean;
  133. didPageUrl: string;
  134. inviteDomain: string;
  135. labels: Object | null;
  136. logoClickUrl: string;
  137. logoImageUrl: string;
  138. muiBrandedTheme?: boolean;
  139. premeetingBackground: string;
  140. sharedVideoAllowedURLDomains?: Array<string>;
  141. showGiphyIntegration?: boolean;
  142. supportUrl?: string;
  143. useDynamicBrandingData: boolean;
  144. virtualBackgrounds: Array<Image>;
  145. }
  146. /**
  147. * Reduces redux actions for the purposes of the feature {@code dynamic-branding}.
  148. */
  149. ReducerRegistry.register<IDynamicBrandingState>(STORE_NAME, (state = DEFAULT_STATE, action): IDynamicBrandingState => {
  150. switch (action.type) {
  151. case SET_DYNAMIC_BRANDING_DATA: {
  152. const {
  153. avatarBackgrounds,
  154. backgroundColor,
  155. backgroundImageUrl,
  156. brandedIcons,
  157. defaultBranding,
  158. didPageUrl,
  159. inviteDomain,
  160. labels,
  161. logoClickUrl,
  162. logoImageUrl,
  163. muiBrandedTheme,
  164. premeetingBackground,
  165. sharedVideoAllowedURLDomains,
  166. showGiphyIntegration,
  167. supportUrl,
  168. virtualBackgrounds
  169. } = action.value;
  170. return {
  171. avatarBackgrounds,
  172. backgroundColor,
  173. backgroundImageUrl,
  174. brandedIcons,
  175. defaultBranding,
  176. didPageUrl,
  177. inviteDomain,
  178. labels,
  179. logoClickUrl,
  180. logoImageUrl,
  181. muiBrandedTheme,
  182. premeetingBackground,
  183. sharedVideoAllowedURLDomains,
  184. showGiphyIntegration,
  185. supportUrl,
  186. customizationFailed: false,
  187. customizationReady: true,
  188. useDynamicBrandingData: true,
  189. virtualBackgrounds: formatImages(virtualBackgrounds || [])
  190. };
  191. }
  192. case SET_DYNAMIC_BRANDING_FAILED: {
  193. return {
  194. ...state,
  195. customizationReady: true,
  196. customizationFailed: true,
  197. useDynamicBrandingData: true
  198. };
  199. }
  200. case SET_DYNAMIC_BRANDING_READY:
  201. return {
  202. ...state,
  203. customizationReady: true
  204. };
  205. case UNSET_DYNAMIC_BRANDING:
  206. return DEFAULT_STATE;
  207. }
  208. return state;
  209. });
  210. /**
  211. * Transforms the branding images into an array of Images objects ready
  212. * to be used as virtual backgrounds.
  213. *
  214. * @param {Array<string>} images - The branding images.
  215. * @private
  216. * @returns {{Props}}
  217. */
  218. function formatImages(images: Array<string> | Array<{ src: string; tooltip?: string; }>): Array<Image> {
  219. return images.map((img, i) => {
  220. let src;
  221. let tooltip;
  222. if (typeof img === 'object') {
  223. ({ src, tooltip } = img);
  224. } else {
  225. src = img;
  226. }
  227. return {
  228. id: `branding-${i}`,
  229. src,
  230. tooltip
  231. };
  232. });
  233. }