jiti-meet/react/features/deep-linking/components/DeepLinkingMobilePage.web.js

239 lines
6.6 KiB
JavaScript
Raw Normal View History

// @flow
2017-02-07 14:45:51 +00:00
import PropTypes from 'prop-types';
2016-12-23 16:21:51 +00:00
import React, { Component } from 'react';
import { connect } from 'react-redux';
2017-01-13 22:37:53 +00:00
import { createDeepLinkingPageEvent, sendAnalytics } from '../../analytics';
2017-03-01 02:55:12 +00:00
import { translate, translateToHTML } from '../../base/i18n';
import { Platform } from '../../base/react';
import { DialInSummary } from '../../invite';
2017-02-16 20:00:54 +00:00
import { _TNS } from '../constants';
import { generateDeepLinkingURL } from '../functions';
declare var interfaceConfig: Object;
2017-03-01 02:55:12 +00:00
/**
* The namespace of the CSS styles of DeepLinkingMobilePage.
2017-03-01 02:55:12 +00:00
*
* @private
* @type {string}
*/
const _SNS = 'deep-linking-mobile';
2017-03-01 02:55:12 +00:00
/**
* The map of platforms to URLs at which the mobile app for the associated
* platform is available for download.
2017-02-01 04:25:09 +00:00
*
* @private
2017-03-01 02:55:12 +00:00
* @type {Array<string>}
*/
2017-02-01 04:25:09 +00:00
const _URLS = {
android: interfaceConfig.MOBILE_DOWNLOAD_LINK_ANDROID,
ios: interfaceConfig.MOBILE_DOWNLOAD_LINK_IOS
2016-12-23 16:21:51 +00:00
};
/**
2017-01-19 15:47:22 +00:00
* React component representing mobile browser page.
2016-12-23 16:21:51 +00:00
*
* @class DeepLinkingMobilePage
2016-12-23 16:21:51 +00:00
*/
class DeepLinkingMobilePage extends Component<*, *> {
2017-02-07 14:45:51 +00:00
state: Object;
2017-01-25 22:11:44 +00:00
/**
* DeepLinkingMobilePage component's property types.
2017-01-25 22:11:44 +00:00
*
* @static
*/
static propTypes = {
/**
* The name of the conference attempting to being joined.
*/
_room: PropTypes.string,
2017-03-01 02:55:12 +00:00
/**
* The function to translate human-readable text.
*
* @public
* @type {Function}
*/
t: PropTypes.func
};
2017-01-18 12:21:30 +00:00
/**
* Initializes a new {@code DeepLinkingMobilePage} instance.
*
* @param {Object} props - The read-only React {@code Component} props with
* which the new instance is to be initialized.
*/
constructor(props) {
super(props);
// Bind event handlers so they are only bound once per instance.
this._onDownloadApp = this._onDownloadApp.bind(this);
this._onOpenApp = this._onOpenApp.bind(this);
}
2017-01-18 12:21:30 +00:00
/**
2017-02-01 04:25:09 +00:00
* Initializes the text and URL of the `Start a conference` / `Join the
* conversation` button which takes the user to the mobile app.
2017-01-18 12:21:30 +00:00
*
2017-02-01 04:25:09 +00:00
* @inheritdoc
2016-12-23 16:21:51 +00:00
*/
componentWillMount() {
this.setState({
joinURL: generateDeepLinkingURL()
2016-12-23 16:21:51 +00:00
});
}
/**
* Implements the Component's componentDidMount method.
*
* @inheritdoc
*/
componentDidMount() {
sendAnalytics(
createDeepLinkingPageEvent(
'displayed', 'DeepLinkingMobile', { isMobileBrowser: true }));
}
2016-12-23 16:21:51 +00:00
/**
2017-02-01 04:25:09 +00:00
* Implements React's {@link Component#render()}.
2016-12-23 16:21:51 +00:00
*
2017-02-01 04:25:09 +00:00
* @inheritdoc
2016-12-23 16:21:51 +00:00
* @returns {ReactElement}
*/
render() {
const { _room, t } = this.props;
const { NATIVE_APP_NAME, SHOW_DEEP_LINKING_IMAGE } = interfaceConfig;
const downloadButtonClassName
2017-03-01 02:55:12 +00:00
= `${_SNS}__button ${_SNS}__button_primary`;
2016-12-23 16:21:51 +00:00
return (
2017-03-01 02:55:12 +00:00
<div className = { _SNS }>
<div className = 'header'>
2016-12-23 16:21:51 +00:00
<img
className = 'logo'
src = 'images/logo-deep-linking.png' />
</div>
<div className = { `${_SNS}__body` }>
{
SHOW_DEEP_LINKING_IMAGE
? <img
className = 'image'
src = 'images/deep-linking-image.png' />
: null
}
2017-03-01 02:55:12 +00:00
<p className = { `${_SNS}__text` }>
{
translateToHTML(
t,
`${_TNS}.appNotInstalled`,
{ app: NATIVE_APP_NAME })
2017-03-01 02:55:12 +00:00
}
2016-12-23 16:21:51 +00:00
</p>
<a
href = { this._generateDownloadURL() }
onClick = { this._onDownloadApp } >
<button className = { downloadButtonClassName }>
{ t(`${_TNS}.downloadApp`) }
2017-02-01 04:25:09 +00:00
</button>
</a>
<a
className = { `${_SNS}__href` }
href = { this.state.joinURL }
onClick = { this._onOpenApp }>
{/* <button className = { `${_SNS}__button` }> */}
{ t(`${_TNS}.openApp`) }
{/* </button> */}
</a>
<DialInSummary
className = 'deep-linking-dial-in'
clickableNumbers = { true }
room = { _room } />
2016-12-23 16:21:51 +00:00
</div>
</div>
);
}
/**
* Generates the URL for downloading the app.
*
* @private
* @returns {string} - The URL for downloading the app.
*/
_generateDownloadURL() {
const url = _URLS[Platform.OS];
if (url) {
return url;
}
// For information about the properties of
// interfaceConfig.MOBILE_DYNAMIC_LINK check:
// https://firebase.google.com/docs/dynamic-links/create-manually
const {
APN = 'org.jitsi.meet',
APP_CODE = 'w2atb',
IBI = 'com.atlassian.JitsiMeet.ios',
ISI = '1165103905'
} = interfaceConfig.MOBILE_DYNAMIC_LINK || {};
const IUS = interfaceConfig.APP_SCHEME || 'org.jitsi.meet';
return `https://${APP_CODE}.app.goo.gl/?link=${
encodeURIComponent(window.location.href)}&apn=${
APN}&ibi=${
IBI}&isi=${
ISI}&ius=${
IUS}&efr=1`;
}
_onDownloadApp: () => {};
/**
* Handles download app button clicks.
*
* @private
* @returns {void}
*/
_onDownloadApp() {
sendAnalytics(
createDeepLinkingPageEvent(
'clicked', 'downloadAppButton', { isMobileBrowser: true }));
}
_onOpenApp: () => {};
/**
* Handles open app button clicks.
*
* @private
* @returns {void}
*/
_onOpenApp() {
sendAnalytics(
createDeepLinkingPageEvent(
'clicked', 'openAppButton', { isMobileBrowser: true }));
}
2016-12-23 16:21:51 +00:00
}
/**
* Maps (parts of) the Redux state to the associated props for the
* {@code DeepLinkingMobilePage} component.
*
* @param {Object} state - The Redux state.
* @private
* @returns {{
* _room: string
* }}
*/
function _mapStateToProps(state) {
return {
_room: state['features/base/conference'].room
};
}
export default translate(connect(_mapStateToProps)(DeepLinkingMobilePage));