Clean up Conference component

This commit is contained in:
Ilya Daynatovich 2016-12-14 15:11:48 +02:00
parent f53fb3d814
commit a99bbe67ab
3 changed files with 112 additions and 88 deletions

View File

@ -0,0 +1,67 @@
/* global APP, config */
import ConferenceUrl from '../../../modules/URL/ConferenceUrl';
import BoshAddressChoice from '../../../modules/config/BoshAddressChoice';
import { obtainConfig, setTokenData } from './functions';
const logger = require('jitsi-meet-logger').getLogger(__filename);
/**
* If we have an HTTP endpoint for getting config.json configured
* we're going to read it and override properties from config.js and
* interfaceConfig.js. If there is no endpoint we'll just
* continue with initialization.
* Keep in mind that if the endpoint has been configured and we fail
* to obtain the config for any reason then the conference won't
* start and error message will be displayed to the user.
*
* @returns {Function}
*/
export function obtainConfigAndInit() {
return () => {
const room = APP.conference.roomName;
if (config.configLocation) {
const location = config.configLocation;
obtainConfig(location, room)
.then(_obtainConfigHandler)
.then(_initConference)
.catch(err => {
// Show obtain config error,
// pass the error object for report
APP.UI.messageHandler.openReportDialog(
null, 'dialog.connectError', err);
});
} else {
BoshAddressChoice.chooseAddress(config, room);
_initConference();
}
};
}
/**
* Obtain config handler.
*
* @returns {Promise}
* @private
*/
function _obtainConfigHandler() {
const now = window.performance.now();
APP.connectionTimes['configuration.fetched'] = now;
logger.log('(TIME) configuration fetched:\t', now);
return Promise.resolve();
}
/**
* Initialization of the app.
*
* @returns {void}
* @private
*/
function _initConference() {
setTokenData();
// Initialize the conference URL handler
APP.ConferenceUrl = new ConferenceUrl(window.location);
}

View File

@ -1,4 +1,4 @@
/* global APP, $, interfaceConfig, config */
/* global APP, $, interfaceConfig */
import React, { Component } from 'react';
import { connect as reactReduxConnect } from 'react-redux';
@ -7,11 +7,7 @@ import {
connect,
disconnect
} from '../../base/connection';
import ConferenceUrl from '../../../../modules/URL/ConferenceUrl';
import HttpConfigFetch from '../../../../modules/config/HttpConfigFetch';
import BoshAddressChoice from '../../../../modules/config/BoshAddressChoice';
const logger = require('jitsi-meet-logger').getLogger(__filename);
import { obtainConfigAndInit } from '../actions';
/**
* For legacy reasons, inline style for display none.
@ -33,88 +29,7 @@ class Conference extends Component {
* @inheritdoc
*/
componentDidMount() {
/**
* If JWT token data it will be used for local user settings.
*
* @returns {void}
*/
function setTokenData() {
const localUser = APP.tokenData.caller;
if (localUser) {
const email = localUser.getEmail();
const avatarUrl = localUser.getAvatarUrl();
const name = localUser.getName();
APP.settings.setEmail((email || '').trim(), true);
APP.settings.setAvatarUrl((avatarUrl || '').trim());
APP.settings.setDisplayName((name || '').trim(), true);
}
}
/**
* Initialization of the app.
*
* @returns {void}
*/
function init() {
setTokenData();
// Initialize the conference URL handler
APP.ConferenceUrl = new ConferenceUrl(window.location);
}
/**
* If we have an HTTP endpoint for getting config.json configured
* we're going to read it and override properties from config.js and
* interfaceConfig.js. If there is no endpoint we'll just
* continue with initialization.
* Keep in mind that if the endpoint has been configured and we fail
* to obtain the config for any reason then the conference won't
* start and error message will be displayed to the user.
*
* @returns {void}
*/
function obtainConfigAndInit() {
const room = APP.conference.roomName;
if (config.configLocation) {
const configFetch = HttpConfigFetch;
const location = config.configLocation;
configFetch.obtainConfig(location, room, obtainConfigHandler);
} else {
BoshAddressChoice.chooseAddress(config, room);
init();
}
}
/**
* Obtain config handler.
*
* @param {boolean} success - Equals to true if
* config has been obtained w/o errors.
* @param {Object} error - Error object if there is error occured
* while fetching config.
* @returns {void}
*/
function obtainConfigHandler(success, error) {
if (success) {
const now = window.performance.now();
APP.connectionTimes['configuration.fetched'] = now;
logger.log('(TIME) configuration fetched:\t', now);
init();
} else {
// Show obtain config error,
// pass the error object for report
APP.UI.messageHandler.openReportDialog(
null, 'dialog.connectError', error);
}
}
obtainConfigAndInit();
this.props.dispatch(obtainConfigAndInit());
APP.UI.start();
// XXX Temporary solution until we add React translation.

View File

@ -0,0 +1,42 @@
/* global APP */
import HttpConfigFetch from '../../../modules/config/HttpConfigFetch';
/**
* Promise wrapper on obtain config method.
* When HttpConfigFetch will be moved to React app
* it's better to use load config instead.
*
* @param {string} location - URL of the domain.
* @param {string} room - Room name.
* @returns {Promise}
*/
export function obtainConfig(location, room) {
return new Promise((resolve, reject) => {
HttpConfigFetch.obtainConfig(location, room, (success, error) => {
if (success) {
resolve();
} else {
reject(error);
}
});
});
}
/**
* If JWT token data it will be used for local user settings.
*
* @returns {void}
*/
export function setTokenData() {
const localUser = APP.tokenData.caller;
if (localUser) {
const email = localUser.getEmail();
const avatarUrl = localUser.getAvatarUrl();
const name = localUser.getName();
APP.settings.setEmail((email || '').trim(), true);
APP.settings.setAvatarUrl((avatarUrl || '').trim());
APP.settings.setDisplayName((name || '').trim(), true);
}
}