Вы не можете выбрать более 25 тем Темы должны начинаться с буквы или цифры, могут содержать дефисы(-) и должны содержать не более 35 символов.

reducer.js 4.9KB

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