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 = '/' />
<Route
component = { Conference }
path = '/:domain?/:room' />
path = '/conference' />
</Switch>
</Router>
</AtlasKitThemeProvider>

View File

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

View File

@ -6,9 +6,9 @@ export default {
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.

View File

@ -1,5 +1,5 @@
// @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 { connect } from 'react-redux';
import { push } from 'react-router-redux';
import URL from 'url';
import { Navbar } from '../../navbar';
@ -109,18 +108,37 @@ class Welcome extends Component<Props, State> {
* @returns {void}
*/
_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 (url.host && url.path) {
// This will be triggered when the full url is present.
this.props.dispatch(push(url.host + url.path));
if (lastIndexOfSlash === -1) {
// This must be only the room name.
room = inputURL;
} else {
// Take the substring after last slash to be the room name.
room = inputURL.substring(lastIndexOfSlash + 1);
// Directly to the the path.
this.props.dispatch(push(url.path));
// Take the substring before last slash to be the Server URL.
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;