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.

reducer.js 4.4KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206
  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. * The custom url used when the user clicks the logo.
  76. *
  77. * @public
  78. * @type {string}
  79. */
  80. logoClickUrl: '',
  81. /**
  82. * The custom logo (JitisWatermark).
  83. *
  84. * @public
  85. * @type {string}
  86. */
  87. logoImageUrl: '',
  88. /**
  89. * The lobby/prejoin background.
  90. *
  91. * @public
  92. * @type {string}
  93. */
  94. premeetingBackground: '',
  95. /**
  96. * Flag used to signal if the app should use a custom logo or not
  97. *
  98. * @public
  99. * @type {boolean}
  100. */
  101. useDynamicBrandingData: false,
  102. /**
  103. * An array of images to be used as virtual backgrounds instead of the default ones.
  104. *
  105. * @public
  106. * @type {Array<Object>}
  107. */
  108. virtualBackgrounds: []
  109. };
  110. /**
  111. * Reduces redux actions for the purposes of the feature {@code dynamic-branding}.
  112. */
  113. ReducerRegistry.register(STORE_NAME, (state = DEFAULT_STATE, action) => {
  114. switch (action.type) {
  115. case SET_DYNAMIC_BRANDING_DATA: {
  116. const {
  117. avatarBackgrounds,
  118. backgroundColor,
  119. backgroundImageUrl,
  120. defaultBranding,
  121. didPageUrl,
  122. inviteDomain,
  123. logoClickUrl,
  124. logoImageUrl,
  125. premeetingBackground,
  126. virtualBackgrounds
  127. } = action.value;
  128. return {
  129. avatarBackgrounds,
  130. backgroundColor,
  131. backgroundImageUrl,
  132. defaultBranding,
  133. didPageUrl,
  134. inviteDomain,
  135. logoClickUrl,
  136. logoImageUrl,
  137. premeetingBackground,
  138. customizationFailed: false,
  139. customizationReady: true,
  140. useDynamicBrandingData: true,
  141. virtualBackgrounds: formatImages(virtualBackgrounds || [])
  142. };
  143. }
  144. case SET_DYNAMIC_BRANDING_FAILED: {
  145. return {
  146. ...state,
  147. customizationReady: true,
  148. customizationFailed: true,
  149. useDynamicBrandingData: true
  150. };
  151. }
  152. case SET_DYNAMIC_BRANDING_READY:
  153. return {
  154. ...state,
  155. customizationReady: true
  156. };
  157. }
  158. return state;
  159. });
  160. /**
  161. * Transforms the branding images into an array of Images objects ready
  162. * to be used as virtual backgrounds.
  163. *
  164. * @param {Array<string>} images -
  165. * @private
  166. * @returns {{Props}}
  167. */
  168. function formatImages(images: Array<string> | Array<Object>): Array<Image> {
  169. return images.map((img, i) => {
  170. let src;
  171. let tooltip;
  172. if (typeof img === 'object') {
  173. ({ src, tooltip } = img);
  174. } else {
  175. src = img;
  176. }
  177. return {
  178. id: `branding-${i}`,
  179. src,
  180. tooltip
  181. };
  182. });
  183. }