Skip to content

Commit

Permalink
Bundle external API
Browse files Browse the repository at this point in the history
We use very little functionality of it anyway.
  • Loading branch information
saghul committed Jun 11, 2020
1 parent d12611d commit c4aefb0
Show file tree
Hide file tree
Showing 3 changed files with 42 additions and 48 deletions.
85 changes: 37 additions & 48 deletions app/features/conference/components/Conference.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,8 @@ import config from '../../config';
import { getSetting, setEmail, setName } from '../../settings';

import { conferenceEnded, conferenceJoined } from '../actions';
import JitsiMeetExternalAPI from '../external_api';
import { LoadingIndicator, Wrapper } from '../styled';
import { getExternalApiURL } from '../../utils';

type Props = {

Expand Down Expand Up @@ -118,7 +118,6 @@ class Conference extends Component<Props, State> {
* @returns {void}
*/
componentDidMount() {
const parentNode = this._ref.current;
const room = this.props.location.state.room;
const serverTimeout = this.props._serverTimeout || config.defaultServerTimeout;
const serverURL = this.props.location.state.serverURL
Expand All @@ -130,15 +129,7 @@ class Conference extends Component<Props, State> {
serverURL
};

const script = document.createElement('script');

script.async = true;
script.onload = () => this._onScriptLoad(parentNode);
script.onerror = (event: Event) =>
this._navigateToHome(event, room, serverURL);
script.src = getExternalApiURL(serverURL);

this._ref.current.appendChild(script);
this._loadConference();

// Set a timer for a timeout duration, if we haven't loaded the iframe by then,
// give up.
Expand Down Expand Up @@ -200,45 +191,12 @@ class Conference extends Component<Props, State> {
}

/**
* It renders a loading indicator, if appropriate.
*
* @returns {?ReactElement}
*/
_maybeRenderLoadingIndicator() {
if (this.state.isLoading) {
return (
<LoadingIndicator>
<Spinner size = 'large' />
</LoadingIndicator>
);
}
}

/**
* Navigates to home screen (Welcome).
*
* @param {Event} event - Event by which the function is called.
* @param {string} room - Room name.
* @param {string} serverURL - Server URL.
* @returns {void}
*/
_navigateToHome(event: Event, room: ?string, serverURL: ?string) {
this.props.dispatch(push('/', {
error: event.type === 'error',
room,
serverURL
}));
}

/**
* When the script is loaded create the iframe element in this component
* and attach utils from jitsi-meet-electron-utils.
* Load the conference by creating the iframe element in this component
* and attaching utils from jitsi-meet-electron-utils.
*
* @param {Object} parentNode - Node to which iframe has to be attached.
* @returns {void}
*/
_onScriptLoad(parentNode: Object) {
const JitsiMeetExternalAPI = window.JitsiMeetExternalAPI;
_loadConference() {
const url = new URL(this._conference.room, this._conference.serverURL);
const roomName = url.pathname.split('/').pop();
const host = this._conference.serverURL.replace(/https?:\/\//, '');
Expand All @@ -253,7 +211,7 @@ class Conference extends Component<Props, State> {
const options = {
configOverwrite,
onload: this._onIframeLoad,
parentNode,
parentNode: this._ref.current,
roomName
};

Expand Down Expand Up @@ -296,6 +254,37 @@ class Conference extends Component<Props, State> {
setupPowerMonitorRender(this._api);
}

/**
* It renders a loading indicator, if appropriate.
*
* @returns {?ReactElement}
*/
_maybeRenderLoadingIndicator() {
if (this.state.isLoading) {
return (
<LoadingIndicator>
<Spinner size = 'large' />
</LoadingIndicator>
);
}
}

/**
* Navigates to home screen (Welcome).
*
* @param {Event} event - Event by which the function is called.
* @param {string} room - Room name.
* @param {string} serverURL - Server URL.
* @returns {void}
*/
_navigateToHome(event: Event, room: ?string, serverURL: ?string) {
this.props.dispatch(push('/', {
error: event.type === 'error',
room,
serverURL
}));
}

_onVideoConferenceEnded: (*) => void;

/**
Expand Down
Loading

0 comments on commit c4aefb0

Please sign in to comment.