Files
jitsi-meet/react/features/deep-linking/components/DeepLinkingDesktopPage.web.js
Saúl Ibarra Corretgé 155e02bbfb core: refactor routing
Unfortunately, as the Jitsi Meet development evolved the routing mechanism
became more complex and thre logic ended up spread across multiple parts of the
codebase, which made it hard to follow and extend.

This change aims to fix that by rewriting the routing logic and centralizing it
in (pretty much) a single place, with no implicit inter-dependencies.

In order to arrive there, however, some extra changes were needed, which were
not caught early enough and are thus part of this change:

- JitsiMeetJS initialization is now synchronous: there is nothing async about
  it, and the only async requirement (Temasys support) was lifted. See [0].
- WebRTC support can be detected early: building on top of the above, WebRTC
  support can now be detected immediately, so take advantage of this to simplify
  how we handle unsupported browsers. See [0].

The new router takes decissions based on the Redux state at the time of
invocation. A route can be represented by either a component or a URl reference,
with the latter taking precedence. On mobile, obviously, there is no concept of
URL reference so routing is based solely on components.

[0]: https://github.com/jitsi/lib-jitsi-meet/pull/779
2018-07-11 22:58:41 -05:00

176 lines
5.4 KiB
JavaScript

/* @flow */
import Button, { ButtonGroup } from '@atlaskit/button';
import { AtlasKitThemeProvider } from '@atlaskit/theme';
import React, { Component } from 'react';
import { connect } from 'react-redux';
import { createDeepLinkingPageEvent, sendAnalytics } from '../../analytics';
import { translate } from '../../base/i18n';
import {
openWebApp,
openDesktopApp
} from '../actions';
import { _TNS } from '../constants';
declare var interfaceConfig: Object;
/**
* The type of the React {@code Component} props of
* {@link DeepLinkingDesktopPage}.
*/
type Props = {
/**
* Used to dispatch actions from the buttons.
*/
dispatch: Dispatch<*>,
/**
* Used to obtain translations.
*/
t: Function
};
/**
* React component representing the deep linking page.
*
* @class DeepLinkingDesktopPage
*/
class DeepLinkingDesktopPage<P : Props> extends Component<P> {
/**
* Initializes a new {@code DeepLinkingDesktopPage} instance.
*
* @param {Object} props - The read-only React {@code Component} props with
* which the new instance is to be initialized.
*/
constructor(props: P) {
super(props);
// Bind event handlers so they are only bound once per instance.
this._openDesktopApp = this._openDesktopApp.bind(this);
this._onLaunchWeb = this._onLaunchWeb.bind(this);
this._onTryAgain = this._onTryAgain.bind(this);
}
/**
* Implements the Component's componentDidMount method.
*
* @inheritdoc
*/
componentDidMount() {
this._openDesktopApp();
sendAnalytics(
createDeepLinkingPageEvent(
'displayed', 'DeepLinkingDesktop', { isMobileBrowser: false }));
}
/**
* Renders the component.
*
* @returns {ReactElement}
*/
render() {
const { t } = this.props;
const { NATIVE_APP_NAME, SHOW_DEEP_LINKING_IMAGE } = interfaceConfig;
const rightColumnStyle
= SHOW_DEEP_LINKING_IMAGE ? null : { width: '100%' };
return (
// Enabling light theme because of the color of the buttons.
<AtlasKitThemeProvider mode = 'light'>
<div className = 'deep-linking-desktop'>
<div className = 'header'>
<img
className = 'logo'
src = 'images/logo-deep-linking.png' />
</div>
<div className = 'content'>
{
SHOW_DEEP_LINKING_IMAGE
? <div className = 'leftColumn'>
<div className = 'leftColumnContent'>
<div className = 'image' />
</div>
</div> : null
}
<div
className = 'rightColumn'
style = { rightColumnStyle }>
<div className = 'rightColumnContent'>
<h1 className = 'title'>
{
t(`${_TNS}.title`,
{ app: NATIVE_APP_NAME })
}
</h1>
<p className = 'description'>
{
t(`${_TNS}.description`,
{ app: NATIVE_APP_NAME })
}
</p>
<div className = 'buttons'>
<ButtonGroup>
<Button
appearance = 'default'
onClick = { this._onTryAgain }>
{ t(`${_TNS}.tryAgainButton`) }
</Button>
<Button onClick = { this._onLaunchWeb }>
{ t(`${_TNS}.launchWebButton`) }
</Button>
</ButtonGroup>
</div>
</div>
</div>
</div>
</div>
</AtlasKitThemeProvider>
);
}
_openDesktopApp: () => {}
/**
* Dispatches the <tt>openDesktopApp</tt> action.
*
* @returns {void}
*/
_openDesktopApp() {
this.props.dispatch(openDesktopApp());
}
_onTryAgain: () => {}
/**
* Handles try again button clicks.
*
* @returns {void}
*/
_onTryAgain() {
sendAnalytics(
createDeepLinkingPageEvent(
'clicked', 'tryAgainButton', { isMobileBrowser: false }));
this._openDesktopApp();
}
_onLaunchWeb: () => {}
/**
* Handles launch web button clicks.
*
* @returns {void}
*/
_onLaunchWeb() {
sendAnalytics(
createDeepLinkingPageEvent(
'clicked', 'launchWebButton', { isMobileBrowser: false }));
this.props.dispatch(openWebApp());
}
}
export default translate(connect()(DeepLinkingDesktopPage));