From d73f80e7bffdfbbd3e5263033697640303957ba7 Mon Sep 17 00:00:00 2001 From: Akshit Kr Nagpal Date: Mon, 25 Jun 2018 13:52:15 +0530 Subject: [PATCH] Refactor handling of domain Use the concept of a "server URL", since it's URLs we are dealing with, not actul domains. --- app/features/app/components/App.js | 2 +- .../conference/components/Conference.js | 23 ++++++------ app/features/config/index.js | 4 +-- app/features/router/history.js | 4 +-- app/features/welcome/components/Welcome.js | 36 ++++++++++++++----- 5 files changed, 45 insertions(+), 24 deletions(-) diff --git a/app/features/app/components/App.js b/app/features/app/components/App.js index 392cd78..b934ddf 100644 --- a/app/features/app/components/App.js +++ b/app/features/app/components/App.js @@ -43,7 +43,7 @@ export default class App extends Component<*> { path = '/' /> + path = '/conference' /> diff --git a/app/features/conference/components/Conference.js b/app/features/conference/components/Conference.js index f308ef0..49950fb 100644 --- a/app/features/conference/components/Conference.js +++ b/app/features/conference/components/Conference.js @@ -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 component. + * React Router location object. */ - match: Object; + location: Object; /** * Avatar URL. @@ -80,15 +80,16 @@ class Conference extends Component { */ 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 { * * @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 }); diff --git a/app/features/config/index.js b/app/features/config/index.js index 6da1239..4be9486 100644 --- a/app/features/config/index.js +++ b/app/features/config/index.js @@ -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. diff --git a/app/features/router/history.js b/app/features/router/history.js index 051b1d1..9434d7c 100644 --- a/app/features/router/history.js +++ b/app/features/router/history.js @@ -1,5 +1,5 @@ // @flow -import { createHashHistory } from 'history'; +import { createMemoryHistory as createHistory } from 'history'; -export default createHashHistory(); +export default createHistory(); diff --git a/app/features/welcome/components/Welcome.js b/app/features/welcome/components/Welcome.js index 63f79c5..663bc80 100644 --- a/app/features/welcome/components/Welcome.js +++ b/app/features/welcome/components/Welcome.js @@ -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 { * @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;