Du kannst nicht mehr als 25 Themen auswählen Themen müssen mit entweder einem Buchstaben oder einer Ziffer beginnen. Sie können Bindestriche („-“) enthalten und bis zu 35 Zeichen lang sein.

ChromeExtensionBanner.web.js 8.6KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283
  1. // @flow
  2. import React, { PureComponent } from 'react';
  3. import { connect } from '../../base/redux';
  4. import { Icon, IconClose } from '../../base/icons';
  5. import { translate } from '../../base/i18n';
  6. import { getCurrentConference } from '../../base/conference/functions';
  7. import { browser } from '../../base/lib-jitsi-meet';
  8. import {
  9. checkChromeExtensionsInstalled,
  10. isMobileBrowser
  11. } from '../../base/environment/utils';
  12. import logger from '../logger';
  13. import {
  14. createChromeExtensionBannerEvent,
  15. sendAnalytics
  16. } from '../../analytics';
  17. declare var interfaceConfig: Object;
  18. const emptyObject = {};
  19. /**
  20. * Local storage key name for flag telling if user checked 'Don't show again' checkbox on the banner
  21. * If the user checks this before closing the banner, next time he will access a jitsi domain
  22. * the banner will not be shown regardless of extensions being installed or not.
  23. */
  24. const DONT_SHOW_AGAIN_CHECKED = 'hide_chrome_extension_banner';
  25. /**
  26. * The type of the React {@code PureComponent} props of {@link ChromeExtensionBanner}.
  27. */
  28. type Props = {
  29. /**
  30. * Contains info about installed/to be installed chrome extension(s).
  31. */
  32. bannerCfg: Object,
  33. /**
  34. * Conference data, if any
  35. */
  36. conference: Object,
  37. /**
  38. * Whether I am the current recorder.
  39. */
  40. iAmRecorder: boolean,
  41. /**
  42. * Invoked to obtain translated strings.
  43. */
  44. t: Function,
  45. };
  46. /**
  47. * The type of the React {@link PureComponent} state of {@link ChromeExtensionBanner}.
  48. */
  49. type State = {
  50. /**
  51. * Keeps the current value of dont show again checkbox
  52. */
  53. dontShowAgainChecked: boolean,
  54. /**
  55. * Tells whether user pressed install extension or close button.
  56. */
  57. closePressed: boolean,
  58. /**
  59. * Tells whether should show the banner or not based on extension being installed or not.
  60. */
  61. shouldShow: boolean,
  62. };
  63. /**
  64. * Implements a React {@link PureComponent} which displays a banner having a link to the chrome extension.
  65. * @class ChromeExtensionBanner
  66. * @extends PureComponent
  67. */
  68. class ChromeExtensionBanner extends PureComponent<Props, State> {
  69. /**
  70. * Initializes a new {@code ChromeExtensionBanner} instance.
  71. *
  72. * @param {Object} props - The read-only React {@code PureComponent} props with
  73. * which the new instance is to be initialized.
  74. */
  75. constructor(props: Props) {
  76. super(props);
  77. this.state = {
  78. dontShowAgainChecked: false,
  79. closePressed: false,
  80. shouldShow: false
  81. };
  82. this._onClosePressed = this._onClosePressed.bind(this);
  83. this._onInstallExtensionClick = this._onInstallExtensionClick.bind(this);
  84. this._shouldNotRender = this._shouldNotRender.bind(this);
  85. this._onDontShowAgainChange = this._onDontShowAgainChange.bind(this);
  86. }
  87. /**
  88. * Executed on component update.
  89. * Checks whether any chrome extension from the config is installed.
  90. *
  91. * @inheritdoc
  92. */
  93. async componentDidUpdate(prevProps) {
  94. if (!this._isSupportedEnvironment()) {
  95. return;
  96. }
  97. const { bannerCfg } = this.props;
  98. const prevBannerCfg = prevProps.bannerCfg;
  99. if (bannerCfg.url && !prevBannerCfg.url) {
  100. logger.info('Chrome extension URL found.');
  101. }
  102. if ((bannerCfg.chromeExtensionsInfo || []).length && !(prevBannerCfg.chromeExtensionsInfo || []).length) {
  103. logger.info('Chrome extension(s) info found.');
  104. }
  105. const hasExtensions = await checkChromeExtensionsInstalled(this.props.bannerCfg);
  106. if (
  107. hasExtensions
  108. && hasExtensions.length
  109. && hasExtensions.every(ext => !ext)
  110. && !this.state.shouldShow
  111. ) {
  112. this.setState({ shouldShow: true }); // eslint-disable-line
  113. }
  114. }
  115. /**
  116. * Checks whether the feature is enabled and whether the environment(browser/os)
  117. * supports it.
  118. *
  119. * @returns {boolean}
  120. */
  121. _isSupportedEnvironment() {
  122. return interfaceConfig.SHOW_CHROME_EXTENSION_BANNER
  123. && browser.isChrome()
  124. && !isMobileBrowser();
  125. }
  126. _onClosePressed: () => void;
  127. /**
  128. * Closes the banner for the current session.
  129. *
  130. * @returns {void}
  131. */
  132. _onClosePressed() {
  133. sendAnalytics(createChromeExtensionBannerEvent(false));
  134. this.setState({ closePressed: true });
  135. }
  136. _onInstallExtensionClick: () => void;
  137. /**
  138. * Opens the chrome extension page.
  139. *
  140. * @returns {void}
  141. */
  142. _onInstallExtensionClick() {
  143. sendAnalytics(createChromeExtensionBannerEvent(true));
  144. window.open(this.props.bannerCfg.url);
  145. this.setState({ closePressed: true });
  146. }
  147. _shouldNotRender: () => boolean;
  148. /**
  149. * Checks whether the banner should not be rendered.
  150. *
  151. * @returns {boolean} Whether to show the banner or not.
  152. */
  153. _shouldNotRender() {
  154. if (!this._isSupportedEnvironment()) {
  155. return true;
  156. }
  157. const dontShowAgain = localStorage.getItem(DONT_SHOW_AGAIN_CHECKED) === 'true';
  158. return !this.props.bannerCfg.url
  159. || dontShowAgain
  160. || this.state.closePressed
  161. || !this.state.shouldShow
  162. || this.props.iAmRecorder;
  163. }
  164. _onDontShowAgainChange: (object: Object) => void;
  165. /**
  166. * Handles the current `don't show again` checkbox state.
  167. *
  168. * @param {Object} event - Input change event.
  169. * @returns {void}
  170. */
  171. _onDontShowAgainChange(event) {
  172. this.setState({ dontShowAgainChecked: event.target.checked });
  173. }
  174. /**
  175. * Implements React's {@link PureComponent#render()}.
  176. *
  177. * @inheritdoc
  178. * @returns {ReactElement}
  179. */
  180. render() {
  181. if (this._shouldNotRender()) {
  182. if (this.state.dontShowAgainChecked) {
  183. localStorage.setItem(DONT_SHOW_AGAIN_CHECKED, 'true');
  184. }
  185. return null;
  186. }
  187. const { t } = this.props;
  188. const mainClassNames = this.props.conference
  189. ? 'chrome-extension-banner chrome-extension-banner__pos_in_meeting'
  190. : 'chrome-extension-banner';
  191. return (
  192. <div className = { mainClassNames }>
  193. <div className = 'chrome-extension-banner__container'>
  194. <div
  195. className = 'chrome-extension-banner__icon-container' />
  196. <div
  197. className = 'chrome-extension-banner__text-container'>
  198. { t('chromeExtensionBanner.installExtensionText') }
  199. </div>
  200. <div
  201. className = 'chrome-extension-banner__close-container'
  202. onClick = { this._onClosePressed }>
  203. <Icon
  204. className = 'gray'
  205. size = { 12 }
  206. src = { IconClose } />
  207. </div>
  208. </div>
  209. <div
  210. className = 'chrome-extension-banner__button-container'>
  211. <div
  212. className = 'chrome-extension-banner__button-open-url'
  213. onClick = { this._onInstallExtensionClick }>
  214. <div
  215. className = 'chrome-extension-banner__button-text'>
  216. { t('chromeExtensionBanner.buttonText') }
  217. </div>
  218. </div>
  219. </div>
  220. <div className = 'chrome-extension-banner__checkbox-container'>
  221. <label className = 'chrome-extension-banner__checkbox-label'>
  222. <input
  223. checked = { this.state.dontShowAgainChecked }
  224. onChange = { this._onDontShowAgainChange }
  225. type = 'checkbox' />
  226. &nbsp;{ t('chromeExtensionBanner.dontShowAgain') }
  227. </label>
  228. </div>
  229. </div>
  230. );
  231. }
  232. }
  233. /**
  234. * Function that maps parts of Redux state tree into component props.
  235. *
  236. * @param {Object} state - Redux state.
  237. * @returns {Object}
  238. */
  239. const _mapStateToProps = state => {
  240. return {
  241. // Using emptyObject so that we don't change the reference every time when _mapStateToProps is called.
  242. bannerCfg: state['features/base/config'].chromeExtensionBanner || emptyObject,
  243. conference: getCurrentConference(state),
  244. iAmRecorder: state['features/base/config'].iAmRecorder
  245. };
  246. };
  247. export default translate(connect(_mapStateToProps)(ChromeExtensionBanner));