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

Watermarks.js 7.3KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292
  1. /* @flow */
  2. import React, { Component } from 'react';
  3. import { translate } from '../../../i18n';
  4. import { connect } from '../../../redux';
  5. declare var interfaceConfig: Object;
  6. /**
  7. * The CSS style of the element with CSS class {@code rightwatermark}.
  8. *
  9. * @private
  10. */
  11. const _RIGHT_WATERMARK_STYLE = {
  12. backgroundImage: 'url(images/rightwatermark.png)'
  13. };
  14. /**
  15. * The type of the React {@code Component} props of {@link Watermarks}.
  16. */
  17. type Props = {
  18. /**
  19. * The user selected url used to navigate to on logo click.
  20. */
  21. _customLogoLink: string,
  22. /**
  23. * The url of the user selected logo.
  24. */
  25. _customLogoUrl: string,
  26. /**
  27. * Whether or not the current user is logged in through a JWT.
  28. */
  29. _isGuest: boolean,
  30. /**
  31. * Flag used to signal that the logo can be displayed.
  32. * It becomes true after the user customization options are fetched.
  33. */
  34. _readyToDisplayJitsiWatermark: boolean,
  35. /**
  36. * Invoked to obtain translated strings.
  37. */
  38. t: Function
  39. };
  40. /**
  41. * The type of the React {@code Component} state of {@link Watermarks}.
  42. */
  43. type State = {
  44. /**
  45. * The url to open when clicking the brand watermark.
  46. */
  47. brandWatermarkLink: string,
  48. /**
  49. * The url to open when clicking the Jitsi watermark.
  50. */
  51. jitsiWatermarkLink: string,
  52. /**
  53. * Whether or not the brand watermark should be displayed.
  54. */
  55. showBrandWatermark: boolean,
  56. /**
  57. * Whether or not the Jitsi watermark should be displayed.
  58. */
  59. showJitsiWatermark: boolean,
  60. /**
  61. * Whether or not the Jitsi watermark should be displayed for users not
  62. * logged in through a JWT.
  63. */
  64. showJitsiWatermarkForGuests: boolean,
  65. /**
  66. * Whether or not the show the "powered by Jitsi.org" link.
  67. */
  68. showPoweredBy: boolean
  69. };
  70. /**
  71. * A Web Component which renders watermarks such as Jits, brand, powered by,
  72. * etc.
  73. */
  74. class Watermarks extends Component<Props, State> {
  75. /**
  76. * Initializes a new Watermarks instance.
  77. *
  78. * @param {Object} props - The read-only properties with which the new
  79. * instance is to be initialized.
  80. */
  81. constructor(props: Props) {
  82. super(props);
  83. let showBrandWatermark;
  84. let showJitsiWatermark;
  85. let showJitsiWatermarkForGuests;
  86. if (interfaceConfig.filmStripOnly) {
  87. showBrandWatermark = false;
  88. showJitsiWatermark = false;
  89. showJitsiWatermarkForGuests = false;
  90. } else {
  91. showBrandWatermark = interfaceConfig.SHOW_BRAND_WATERMARK;
  92. showJitsiWatermark = interfaceConfig.SHOW_JITSI_WATERMARK;
  93. showJitsiWatermarkForGuests
  94. = interfaceConfig.SHOW_WATERMARK_FOR_GUESTS;
  95. }
  96. this.state = {
  97. brandWatermarkLink:
  98. showBrandWatermark ? interfaceConfig.BRAND_WATERMARK_LINK : '',
  99. jitsiWatermarkLink:
  100. showJitsiWatermark || showJitsiWatermarkForGuests
  101. ? interfaceConfig.JITSI_WATERMARK_LINK : '',
  102. showBrandWatermark,
  103. showJitsiWatermark,
  104. showJitsiWatermarkForGuests,
  105. showPoweredBy: interfaceConfig.SHOW_POWERED_BY
  106. };
  107. }
  108. /**
  109. * Implements React's {@link Component#render()}.
  110. *
  111. * @inheritdoc
  112. * @returns {ReactElement}
  113. */
  114. render() {
  115. return (
  116. <div>
  117. {
  118. this._renderJitsiWatermark()
  119. }
  120. {
  121. this._renderBrandWatermark()
  122. }
  123. {
  124. this._renderPoweredBy()
  125. }
  126. </div>
  127. );
  128. }
  129. /**
  130. * Returns true if the watermark is ready to be displayed.
  131. *
  132. * @private
  133. * @returns {boolean}
  134. */
  135. _canDisplayJitsiWatermark() {
  136. const {
  137. showJitsiWatermark,
  138. showJitsiWatermarkForGuests
  139. } = this.state;
  140. const {
  141. _isGuest,
  142. _readyToDisplayJitsiWatermark
  143. } = this.props;
  144. return _readyToDisplayJitsiWatermark
  145. && (showJitsiWatermark || (_isGuest && showJitsiWatermarkForGuests));
  146. }
  147. /**
  148. * Renders a brand watermark if it is enabled.
  149. *
  150. * @private
  151. * @returns {ReactElement|null} Watermark element or null.
  152. */
  153. _renderBrandWatermark() {
  154. let reactElement = null;
  155. if (this.state.showBrandWatermark) {
  156. reactElement = (
  157. <div
  158. className = 'watermark rightwatermark'
  159. style = { _RIGHT_WATERMARK_STYLE } />
  160. );
  161. const { brandWatermarkLink } = this.state;
  162. if (brandWatermarkLink) {
  163. reactElement = (
  164. <a
  165. href = { brandWatermarkLink }
  166. target = '_new'>
  167. { reactElement }
  168. </a>
  169. );
  170. }
  171. }
  172. return reactElement;
  173. }
  174. /**
  175. * Renders a Jitsi watermark if it is enabled.
  176. *
  177. * @private
  178. * @returns {ReactElement|null}
  179. */
  180. _renderJitsiWatermark() {
  181. let reactElement = null;
  182. const {
  183. _customLogoUrl,
  184. _customLogoLink
  185. } = this.props;
  186. if (this._canDisplayJitsiWatermark()) {
  187. const link = _customLogoLink || this.state.jitsiWatermarkLink;
  188. const style = {
  189. backgroundImage: `url(${_customLogoUrl || interfaceConfig.DEFAULT_LOGO_URL})`,
  190. maxWidth: 140,
  191. maxHeight: 70
  192. };
  193. reactElement = (<div
  194. className = 'watermark leftwatermark'
  195. style = { style } />);
  196. if (link) {
  197. reactElement = (
  198. <a
  199. href = { link }
  200. target = '_new'>
  201. { reactElement }
  202. </a>
  203. );
  204. }
  205. }
  206. return reactElement;
  207. }
  208. /**
  209. * Renders a powered by block if it is enabled.
  210. *
  211. * @private
  212. * @returns {ReactElement|null}
  213. */
  214. _renderPoweredBy() {
  215. if (this.state.showPoweredBy) {
  216. const { t } = this.props;
  217. return (
  218. <a
  219. className = 'poweredby'
  220. href = 'http://jitsi.org'
  221. target = '_new'>
  222. <span>{ t('poweredby') } jitsi.org</span>
  223. </a>
  224. );
  225. }
  226. return null;
  227. }
  228. }
  229. /**
  230. * Maps parts of Redux store to component prop types.
  231. *
  232. * @param {Object} state - Snapshot of Redux store.
  233. * @returns {Props}
  234. */
  235. function _mapStateToProps(state) {
  236. const { isGuest } = state['features/base/jwt'];
  237. const { customizationReady, logoClickUrl, logoImageUrl } = state['features/dynamic-branding'];
  238. return {
  239. /**
  240. * The indicator which determines whether the local participant is a
  241. * guest in the conference.
  242. *
  243. * @private
  244. * @type {boolean}
  245. */
  246. _customLogoLink: logoClickUrl,
  247. _customLogoUrl: logoImageUrl,
  248. _isGuest: isGuest,
  249. _readyToDisplayJitsiWatermark: customizationReady
  250. };
  251. }
  252. export default connect(_mapStateToProps)(translate(Watermarks));