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

reducer.ts 5.7KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254
  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. showGiphyIntegration?: boolean;
  141. useDynamicBrandingData: boolean;
  142. virtualBackgrounds: Array<Image>;
  143. }
  144. /**
  145. * Reduces redux actions for the purposes of the feature {@code dynamic-branding}.
  146. */
  147. ReducerRegistry.register<IDynamicBrandingState>(STORE_NAME, (state = DEFAULT_STATE, action): IDynamicBrandingState => {
  148. switch (action.type) {
  149. case SET_DYNAMIC_BRANDING_DATA: {
  150. const {
  151. avatarBackgrounds,
  152. backgroundColor,
  153. backgroundImageUrl,
  154. brandedIcons,
  155. defaultBranding,
  156. didPageUrl,
  157. inviteDomain,
  158. labels,
  159. logoClickUrl,
  160. logoImageUrl,
  161. muiBrandedTheme,
  162. premeetingBackground,
  163. showGiphyIntegration,
  164. virtualBackgrounds
  165. } = action.value;
  166. return {
  167. avatarBackgrounds,
  168. backgroundColor,
  169. backgroundImageUrl,
  170. brandedIcons,
  171. defaultBranding,
  172. didPageUrl,
  173. inviteDomain,
  174. labels,
  175. logoClickUrl,
  176. logoImageUrl,
  177. muiBrandedTheme,
  178. premeetingBackground,
  179. showGiphyIntegration,
  180. customizationFailed: false,
  181. customizationReady: true,
  182. useDynamicBrandingData: true,
  183. virtualBackgrounds: formatImages(virtualBackgrounds || [])
  184. };
  185. }
  186. case SET_DYNAMIC_BRANDING_FAILED: {
  187. return {
  188. ...state,
  189. customizationReady: true,
  190. customizationFailed: true,
  191. useDynamicBrandingData: true
  192. };
  193. }
  194. case SET_DYNAMIC_BRANDING_READY:
  195. return {
  196. ...state,
  197. customizationReady: true
  198. };
  199. case UNSET_DYNAMIC_BRANDING:
  200. return DEFAULT_STATE;
  201. }
  202. return state;
  203. });
  204. /**
  205. * Transforms the branding images into an array of Images objects ready
  206. * to be used as virtual backgrounds.
  207. *
  208. * @param {Array<string>} images -
  209. * @private
  210. * @returns {{Props}}
  211. */
  212. function formatImages(images: Array<string> | Array<{ src: string; tooltip?: string; }>): Array<Image> {
  213. return images.map((img, i) => {
  214. let src;
  215. let tooltip;
  216. if (typeof img === 'object') {
  217. ({ src, tooltip } = img);
  218. } else {
  219. src = img;
  220. }
  221. return {
  222. id: `branding-${i}`,
  223. src,
  224. tooltip
  225. };
  226. });
  227. }