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.

Watermarks.js 6.5KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268
  1. /* @flow */
  2. import React, { Component } from 'react';
  3. import { isVpaasMeeting } from '../../../../jaas/functions';
  4. import { translate } from '../../../i18n';
  5. import { connect } from '../../../redux';
  6. declare var interfaceConfig: Object;
  7. /**
  8. * The CSS style of the element with CSS class {@code rightwatermark}.
  9. *
  10. * @private
  11. */
  12. const _RIGHT_WATERMARK_STYLE = {
  13. backgroundImage: 'url(images/rightwatermark.png)'
  14. };
  15. /**
  16. * The type of the React {@code Component} props of {@link Watermarks}.
  17. */
  18. type Props = {
  19. /**
  20. * The link used to navigate to on logo click.
  21. */
  22. _logoLink: string,
  23. /**
  24. * The url for the logo.
  25. */
  26. _logoUrl: string,
  27. /**
  28. * If the Jitsi watermark should be displayed or not.
  29. */
  30. _showJitsiWatermark: boolean,
  31. /**
  32. * The default value for the Jitsi logo URL.
  33. */
  34. defaultJitsiLogoURL: ?string,
  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. * Whether or not the brand watermark should be displayed.
  50. */
  51. showBrandWatermark: boolean,
  52. /**
  53. * Whether or not the show the "powered by Jitsi.org" link.
  54. */
  55. showPoweredBy: boolean
  56. };
  57. /**
  58. * A Web Component which renders watermarks such as Jits, brand, powered by,
  59. * etc.
  60. */
  61. class Watermarks extends Component<Props, State> {
  62. /**
  63. * Initializes a new Watermarks instance.
  64. *
  65. * @param {Object} props - The read-only properties with which the new
  66. * instance is to be initialized.
  67. */
  68. constructor(props: Props) {
  69. super(props);
  70. const showBrandWatermark = interfaceConfig.SHOW_BRAND_WATERMARK;
  71. this.state = {
  72. brandWatermarkLink:
  73. showBrandWatermark ? interfaceConfig.BRAND_WATERMARK_LINK : '',
  74. showBrandWatermark,
  75. showPoweredBy: interfaceConfig.SHOW_POWERED_BY
  76. };
  77. }
  78. /**
  79. * Implements React's {@link Component#render()}.
  80. *
  81. * @inheritdoc
  82. * @returns {ReactElement}
  83. */
  84. render() {
  85. return (
  86. <div>
  87. {
  88. this._renderJitsiWatermark()
  89. }
  90. {
  91. this._renderBrandWatermark()
  92. }
  93. {
  94. this._renderPoweredBy()
  95. }
  96. </div>
  97. );
  98. }
  99. /**
  100. * Renders a brand watermark if it is enabled.
  101. *
  102. * @private
  103. * @returns {ReactElement|null} Watermark element or null.
  104. */
  105. _renderBrandWatermark() {
  106. let reactElement = null;
  107. if (this.state.showBrandWatermark) {
  108. reactElement = (
  109. <div
  110. className = 'watermark rightwatermark'
  111. style = { _RIGHT_WATERMARK_STYLE } />
  112. );
  113. const { brandWatermarkLink } = this.state;
  114. if (brandWatermarkLink) {
  115. reactElement = (
  116. <a
  117. href = { brandWatermarkLink }
  118. target = '_new'>
  119. { reactElement }
  120. </a>
  121. );
  122. }
  123. }
  124. return reactElement;
  125. }
  126. /**
  127. * Renders a Jitsi watermark if it is enabled.
  128. *
  129. * @private
  130. * @returns {ReactElement|null}
  131. */
  132. _renderJitsiWatermark() {
  133. const {
  134. _logoLink,
  135. _logoUrl,
  136. _showJitsiWatermark
  137. } = this.props;
  138. const { t } = this.props;
  139. let reactElement = null;
  140. if (_showJitsiWatermark) {
  141. const style = {
  142. backgroundImage: `url(${_logoUrl})`,
  143. maxWidth: 140,
  144. maxHeight: 70,
  145. position: _logoLink ? 'static' : 'absolute'
  146. };
  147. reactElement = (<div
  148. className = 'watermark leftwatermark'
  149. style = { style } />);
  150. if (_logoLink) {
  151. reactElement = (
  152. <a
  153. aria-label = { t('jitsiHome', { logo: interfaceConfig.APP_NAME }) }
  154. className = 'watermark leftwatermark'
  155. href = { _logoLink }
  156. target = '_new'>
  157. { reactElement }
  158. </a>
  159. );
  160. }
  161. }
  162. return reactElement;
  163. }
  164. /**
  165. * Renders a powered by block if it is enabled.
  166. *
  167. * @private
  168. * @returns {ReactElement|null}
  169. */
  170. _renderPoweredBy() {
  171. if (this.state.showPoweredBy) {
  172. const { t } = this.props;
  173. return (
  174. <a
  175. className = 'poweredby'
  176. href = 'http://jitsi.org'
  177. target = '_new'>
  178. <span>{ t('poweredby') } jitsi.org</span>
  179. </a>
  180. );
  181. }
  182. return null;
  183. }
  184. }
  185. /**
  186. * Maps parts of Redux store to component prop types.
  187. *
  188. * @param {Object} state - Snapshot of Redux store.
  189. * @param {Object} ownProps - Component's own props.
  190. * @returns {Props}
  191. */
  192. function _mapStateToProps(state, ownProps) {
  193. const {
  194. customizationReady,
  195. customizationFailed,
  196. defaultBranding,
  197. useDynamicBrandingData,
  198. logoClickUrl,
  199. logoImageUrl
  200. } = state['features/dynamic-branding'];
  201. const isValidRoom = state['features/base/conference'].room;
  202. const {
  203. DEFAULT_LOGO_URL,
  204. JITSI_WATERMARK_LINK,
  205. SHOW_JITSI_WATERMARK
  206. } = interfaceConfig;
  207. let _showJitsiWatermark = (
  208. customizationReady && !customizationFailed
  209. && SHOW_JITSI_WATERMARK)
  210. || !isValidRoom;
  211. let _logoUrl = logoImageUrl;
  212. let _logoLink = logoClickUrl;
  213. if (useDynamicBrandingData) {
  214. if (isVpaasMeeting(state)) {
  215. // don't show logo if request fails or no logo set for vpaas meetings
  216. _showJitsiWatermark = !customizationFailed && Boolean(logoImageUrl);
  217. } else if (defaultBranding) {
  218. _logoUrl = DEFAULT_LOGO_URL;
  219. _logoLink = JITSI_WATERMARK_LINK;
  220. }
  221. } else {
  222. // When there is no custom branding data use defaults
  223. _logoUrl = ownProps.defaultJitsiLogoURL || DEFAULT_LOGO_URL;
  224. _logoLink = JITSI_WATERMARK_LINK;
  225. }
  226. return {
  227. _logoLink,
  228. _logoUrl,
  229. _showJitsiWatermark
  230. };
  231. }
  232. export default connect(_mapStateToProps)(translate(Watermarks));