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.

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