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

reducer.ts 5.7KB

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