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.

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