Du kan inte välja fler än 25 ämnen Ämnen måste starta med en bokstav eller siffra, kan innehålla bindestreck ('-') och vara max 35 tecken långa.

DeepLinkingMobilePage.web.js 9.3KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307
  1. // @flow
  2. import React, { Component } from 'react';
  3. import type { Dispatch } from 'redux';
  4. import { createDeepLinkingPageEvent, sendAnalytics } from '../../analytics';
  5. import { IDeeplinkingConfig, IDeeplinkingMobileConfig } from '../../base/config/configType';
  6. import { isSupportedMobileBrowser } from '../../base/environment';
  7. import { translate } from '../../base/i18n';
  8. import { Platform } from '../../base/react';
  9. import { connect } from '../../base/redux';
  10. import { DialInSummary } from '../../invite';
  11. import { openWebApp } from '../actions';
  12. import { _TNS } from '../constants';
  13. import { generateDeepLinkingURL } from '../functions';
  14. import { renderPromotionalFooter } from '../renderPromotionalFooter';
  15. /**
  16. * The namespace of the CSS styles of DeepLinkingMobilePage.
  17. *
  18. * @private
  19. * @type {string}
  20. */
  21. const _SNS = 'deep-linking-mobile';
  22. /**
  23. * The type of the React {@code Component} props of
  24. * {@link DeepLinkingMobilePage}.
  25. */
  26. type Props = {
  27. /**
  28. * The deeplinking config.
  29. */
  30. _deeplinkingCfg: IDeeplinkingConfig,
  31. /**
  32. * Application mobile deeplinking config.
  33. */
  34. _mobileConfig: IDeeplinkingMobileConfig,
  35. /**
  36. * The deeplinking url.
  37. */
  38. _deepLinkingUrl: string,
  39. /**
  40. * The name of the conference attempting to being joined.
  41. */
  42. _room: string,
  43. /**
  44. * The page current url.
  45. */
  46. _url: URL,
  47. /**
  48. * Used to dispatch actions from the buttons.
  49. */
  50. dispatch: Dispatch<any>,
  51. /**
  52. * The function to translate human-readable text.
  53. */
  54. t: Function
  55. };
  56. /**
  57. * React component representing mobile browser page.
  58. *
  59. * @class DeepLinkingMobilePage
  60. */
  61. class DeepLinkingMobilePage extends Component<Props> {
  62. /**
  63. * Initializes a new {@code DeepLinkingMobilePage} instance.
  64. *
  65. * @param {Object} props - The read-only React {@code Component} props with
  66. * which the new instance is to be initialized.
  67. */
  68. constructor(props: Props) {
  69. super(props);
  70. // Bind event handlers so they are only bound once per instance.
  71. this._onDownloadApp = this._onDownloadApp.bind(this);
  72. this._onLaunchWeb = this._onLaunchWeb.bind(this);
  73. this._onOpenApp = this._onOpenApp.bind(this);
  74. }
  75. /**
  76. * Implements the Component's componentDidMount method.
  77. *
  78. * @inheritdoc
  79. */
  80. componentDidMount() {
  81. sendAnalytics(
  82. createDeepLinkingPageEvent(
  83. 'displayed', 'DeepLinkingMobile', { isMobileBrowser: true }));
  84. }
  85. /**
  86. * Implements React's {@link Component#render()}.
  87. *
  88. * @inheritdoc
  89. * @returns {ReactElement}
  90. */
  91. render() {
  92. const {
  93. _deeplinkingCfg: { hideLogo, showImage },
  94. _mobileConfig: { downloadLink, appName },
  95. _room,
  96. t,
  97. _url,
  98. _deepLinkingUrl
  99. } = this.props;
  100. const downloadButtonClassName
  101. = `${_SNS}__button ${_SNS}__button_primary`;
  102. const onOpenLinkProperties = downloadLink
  103. ? {
  104. // When opening a link to the download page, we want to let the
  105. // OS itself handle intercepting and opening the appropriate
  106. // app store. This avoids potential issues with browsers, such
  107. // as iOS Chrome, not opening the store properly.
  108. }
  109. : {
  110. // When falling back to another URL (Firebase) let the page be
  111. // opened in a new window. This helps prevent the user getting
  112. // trapped in an app-open-cycle where going back to the mobile
  113. // browser re-triggers the app-open behavior.
  114. target: '_blank',
  115. rel: 'noopener noreferrer'
  116. };
  117. return (
  118. <div className = { _SNS }>
  119. <div className = 'header'>
  120. {
  121. hideLogo
  122. ? null
  123. : <img
  124. alt = { t('welcomepage.logo.logoDeepLinking') }
  125. className = 'logo'
  126. src = 'images/logo-deep-linking.png' />
  127. }
  128. </div>
  129. <div className = { `${_SNS}__body` }>
  130. {
  131. showImage
  132. ? <img
  133. alt = { t('welcomepage.logo.logoDeepLinking') }
  134. className = 'image'
  135. src = 'images/deep-linking-image.png' />
  136. : null
  137. }
  138. <p className = { `${_SNS}__text` }>
  139. { t(`${_TNS}.appNotInstalled`, { app: appName }) }
  140. </p>
  141. <p className = { `${_SNS}__text` }>
  142. { t(`${_TNS}.ifHaveApp`) }
  143. </p>
  144. <a
  145. { ...onOpenLinkProperties }
  146. className = { `${_SNS}__href` }
  147. href = { _deepLinkingUrl }
  148. onClick = { this._onOpenApp }
  149. target = '_top'>
  150. <button className = { `${_SNS}__button ${_SNS}__button_primary` }>
  151. { t(`${_TNS}.joinInApp`) }
  152. </button>
  153. </a>
  154. <p className = { `${_SNS}__text` }>
  155. { t(`${_TNS}.ifDoNotHaveApp`) }
  156. </p>
  157. <a
  158. { ...onOpenLinkProperties }
  159. href = { this._generateDownloadURL() }
  160. onClick = { this._onDownloadApp }
  161. target = '_top'>
  162. <button className = { downloadButtonClassName }>
  163. { t(`${_TNS}.downloadApp`) }
  164. </button>
  165. </a>
  166. {
  167. isSupportedMobileBrowser()
  168. ? (
  169. <a
  170. onClick = { this._onLaunchWeb }
  171. target = '_top'>
  172. <button className = { downloadButtonClassName }>
  173. { t(`${_TNS}.launchWebButton`) }
  174. </button>
  175. </a>
  176. ) : (
  177. <b>
  178. { t(`${_TNS}.unsupportedBrowser`) }
  179. </b>
  180. )
  181. }
  182. { renderPromotionalFooter() }
  183. <DialInSummary
  184. className = 'deep-linking-dial-in'
  185. clickableNumbers = { true }
  186. room = { _room }
  187. url = { _url } />
  188. </div>
  189. </div>
  190. );
  191. }
  192. /**
  193. * Generates the URL for downloading the app.
  194. *
  195. * @private
  196. * @returns {string} - The URL for downloading the app.
  197. */
  198. _generateDownloadURL() {
  199. const { _mobileConfig: { downloadLink, dynamicLink, appScheme } } = this.props;
  200. if (downloadLink && typeof dynamicLink === 'undefined') {
  201. return downloadLink;
  202. }
  203. const {
  204. apn,
  205. appCode,
  206. customDomain,
  207. ibi,
  208. isi
  209. } = dynamicLink || {};
  210. const domain = customDomain ?? `https://${appCode}.app.goo.gl`;
  211. return `${domain}/?link=${
  212. encodeURIComponent(window.location.href)}&apn=${
  213. apn}&ibi=${
  214. ibi}&isi=${
  215. isi}&ius=${
  216. appScheme}&efr=1`;
  217. }
  218. _onDownloadApp: () => void;
  219. /**
  220. * Handles download app button clicks.
  221. *
  222. * @private
  223. * @returns {void}
  224. */
  225. _onDownloadApp() {
  226. sendAnalytics(
  227. createDeepLinkingPageEvent(
  228. 'clicked', 'downloadAppButton', { isMobileBrowser: true }));
  229. }
  230. _onLaunchWeb: () => void;
  231. /**
  232. * Handles launch web button clicks.
  233. *
  234. * @returns {void}
  235. */
  236. _onLaunchWeb() {
  237. sendAnalytics(
  238. createDeepLinkingPageEvent(
  239. 'clicked', 'launchWebButton', { isMobileBrowser: true }));
  240. this.props.dispatch(openWebApp());
  241. }
  242. _onOpenApp: () => void;
  243. /**
  244. * Handles open app button clicks.
  245. *
  246. * @private
  247. * @returns {void}
  248. */
  249. _onOpenApp() {
  250. sendAnalytics(
  251. createDeepLinkingPageEvent(
  252. 'clicked', 'openAppButton', { isMobileBrowser: true }));
  253. }
  254. }
  255. /**
  256. * Maps (parts of) the Redux state to the associated props for the
  257. * {@code DeepLinkingMobilePage} component.
  258. *
  259. * @param {Object} state - The Redux state.
  260. * @private
  261. * @returns {Props}
  262. */
  263. function _mapStateToProps(state) {
  264. const { locationURL = {} } = state['features/base/connection'];
  265. const { deeplinking } = state['features/base/config'];
  266. const mobileConfig = deeplinking?.[Platform.OS] || {};
  267. return {
  268. _deeplinkingCfg: deeplinking || {},
  269. _mobileConfig: mobileConfig,
  270. _room: decodeURIComponent(state['features/base/conference'].room),
  271. _url: locationURL,
  272. _deepLinkingUrl: generateDeepLinkingURL(state)
  273. };
  274. }
  275. export default translate(connect(_mapStateToProps)(DeepLinkingMobilePage));