Refactor handling of domain

Use the concept of a "server URL", since it's URLs we are dealing with,
not actul domains.
This commit is contained in:
Akshit Kr Nagpal 2018-06-25 13:52:15 +05:30 committed by Saúl Ibarra Corretgé
parent f886f033f2
commit d73f80e7bf
5 changed files with 45 additions and 24 deletions

View file

@ -43,7 +43,7 @@ export default class App extends Component<*> {
path = '/' /> path = '/' />
<Route <Route
component = { Conference } component = { Conference }
path = '/:domain?/:room' /> path = '/conference' />
</Switch> </Switch>
</Router> </Router>
</AtlasKitThemeProvider> </AtlasKitThemeProvider>

View file

@ -4,6 +4,7 @@ import React, { Component } from 'react';
import type { Dispatch } from 'redux'; import type { Dispatch } from 'redux';
import { connect } from 'react-redux'; import { connect } from 'react-redux';
import { push } from 'react-router-redux'; import { push } from 'react-router-redux';
import URL from 'url';
import { import {
RemoteControl, RemoteControl,
@ -26,10 +27,9 @@ type Props = {
dispatch: Dispatch<*>; dispatch: Dispatch<*>;
/** /**
* React Router match object. * React Router location object.
* This contains parameters passed through <Route /> component.
*/ */
match: Object; location: Object;
/** /**
* Avatar URL. * Avatar URL.
@ -80,15 +80,16 @@ class Conference extends Component<Props, *> {
*/ */
componentDidMount() { componentDidMount() {
const parentNode = this._ref.current; const parentNode = this._ref.current;
const room = this.props.match.params.room; const room = this.props.location.state.room;
const domain = this.props.match.params.domain || config.defaultDomain; const serverURL = this.props.location.state.serverURL
|| config.defaultServerURL;
const script = document.createElement('script'); const script = document.createElement('script');
script.async = true; script.async = true;
script.onload = () => this._onScriptLoad(parentNode, room, domain); script.onload = () => this._onScriptLoad(parentNode, room, serverURL);
script.onerror = () => this._navigateToHome(); script.onerror = () => this._navigateToHome();
script.src = `https://${domain}/external_api.js`; script.src = `${serverURL}/external_api.js`;
this._ref.current.appendChild(script); this._ref.current.appendChild(script);
} }
@ -148,13 +149,15 @@ class Conference extends Component<Props, *> {
* *
* @param {Object} parentNode - Node to which iframe has to be attached. * @param {Object} parentNode - Node to which iframe has to be attached.
* @param {string} roomName - Conference room name to be joined. * @param {string} roomName - Conference room name to be joined.
* @param {string} domain - Jitsi Meet server domain. * @param {string} serverURL - Jitsi Meet server url.
* @returns {void} * @returns {void}
*/ */
_onScriptLoad(parentNode: Object, roomName: string, domain: string) { _onScriptLoad(parentNode: Object, roomName: string, serverURL: string) {
const JitsiMeetExternalAPI = window.JitsiMeetExternalAPI; const JitsiMeetExternalAPI = window.JitsiMeetExternalAPI;
this._api = new JitsiMeetExternalAPI(domain, { const { host } = URL.parse(serverURL);
this._api = new JitsiMeetExternalAPI(host, {
parentNode, parentNode,
roomName roomName
}); });

View file

@ -6,9 +6,9 @@ export default {
appName: 'Jitsi Meet', appName: 'Jitsi Meet',
/** /**
* The domain of the Jitsi Meet deployment that will be used. * The default server URL of Jitsi Meet Deployment that will be used.
*/ */
defaultDomain: 'meet.jit.si', defaultServerURL: 'https://meet.jit.si/',
/** /**
* URL to send feedback. * URL to send feedback.

View file

@ -1,5 +1,5 @@
// @flow // @flow
import { createHashHistory } from 'history'; import { createMemoryHistory as createHistory } from 'history';
export default createHashHistory(); export default createHistory();

View file

@ -9,7 +9,6 @@ import React, { Component } from 'react';
import type { Dispatch } from 'redux'; import type { Dispatch } from 'redux';
import { connect } from 'react-redux'; import { connect } from 'react-redux';
import { push } from 'react-router-redux'; import { push } from 'react-router-redux';
import URL from 'url';
import { Navbar } from '../../navbar'; import { Navbar } from '../../navbar';
@ -109,18 +108,37 @@ class Welcome extends Component<Props, State> {
* @returns {void} * @returns {void}
*/ */
_onJoin() { _onJoin() {
const url = URL.parse(this.state.url); const inputURL = this.state.url;
const lastIndexOfSlash = inputURL.lastIndexOf('/');
let room;
let serverURL;
// Check if the parsed url is a full url or just room name. if (lastIndexOfSlash === -1) {
if (url.host && url.path) { // This must be only the room name.
room = inputURL;
// This will be triggered when the full url is present.
this.props.dispatch(push(url.host + url.path));
} else { } else {
// Take the substring after last slash to be the room name.
room = inputURL.substring(lastIndexOfSlash + 1);
// Directly to the the path. // Take the substring before last slash to be the Server URL.
this.props.dispatch(push(url.path)); serverURL = inputURL.substring(0, lastIndexOfSlash);
// If no protocol is specified in the input we assume and append
// the HTTPS protocol scheme.
if (serverURL.indexOf('://') === -1) {
serverURL = `https://${serverURL}`;
}
} }
// Don't navigate if no room was specified.
if (!room) {
return;
}
this.props.dispatch(push('/conference', {
room,
serverURL
}));
} }
_onURLChange: (*) => void; _onURLChange: (*) => void;