Introduce features/base/config

The config object defined by lib-jitsi-meet is not used by
lib-jitsi-meet only, jitsi-meet respects its values as well.
Moreover, jitsi-meet defined classes and/or functions which manipulate
that config object. Consequently, it makes sense to move the config
object and the associated classes and functions in a dedicated feature.
This commit is contained in:
Lyubo Marinov 2017-04-23 15:14:02 -05:00
parent bce1610794
commit 92e765ea21
10 changed files with 115 additions and 92 deletions

View File

@ -1,6 +1,7 @@
import { setRoom } from '../base/conference'; import { setRoom } from '../base/conference';
import { setConfig } from '../base/config';
import { getDomain, setDomain } from '../base/connection'; import { getDomain, setDomain } from '../base/connection';
import { loadConfig, setConfig } from '../base/lib-jitsi-meet'; import { loadConfig } from '../base/lib-jitsi-meet';
import { APP_WILL_MOUNT, APP_WILL_UNMOUNT } from './actionTypes'; import { APP_WILL_MOUNT, APP_WILL_UNMOUNT } from './actionTypes';
import { import {

View File

@ -254,7 +254,7 @@ export function createConference() {
dispatch(_conferenceWillJoin(room)); dispatch(_conferenceWillJoin(room));
const { config } = state['features/base/lib-jitsi-meet']; const config = state['features/base/config'];
const conference const conference
= connection.initJitsiConference( = connection.initJitsiConference(
@ -368,7 +368,7 @@ export function _setAudioOnlyVideoMuted(muted: boolean) {
export function setLastN(lastN: ?number) { export function setLastN(lastN: ?number) {
return (dispatch: Dispatch<*>, getState: Function) => { return (dispatch: Dispatch<*>, getState: Function) => {
if (typeof lastN === 'undefined') { if (typeof lastN === 'undefined') {
const { config } = getState()['features/base/lib-jitsi-meet']; const config = getState()['features/base/config'];
/* eslint-disable no-param-reassign */ /* eslint-disable no-param-reassign */

View File

@ -0,0 +1,14 @@
import { Symbol } from '../react';
/**
* The redux action which sets the configuration represented by the feature
* base/config. The configuration is defined and consumed by the library
* lib-jitsi-meet but some of its properties are consumed by the application
* jitsi-meet as well.
*
* {
* type: SET_CONFIG,
* config: Object
* }
*/
export const SET_CONFIG = Symbol('SET_CONFIG');

View File

@ -0,0 +1,22 @@
/* @flow */
import { SET_CONFIG } from './actionTypes';
/**
* Sets the configuration represented by the feature base/config. The
* configuration is defined and consumed by the library lib-jitsi-meet but some
* of its properties are consumed by the application jitsi-meet as well.
*
* @param {Object} config - The configuration to be represented by the feature
* base/config.
* @returns {{
* type: SET_CONFIG,
* config: Object
* }}
*/
export function setConfig(config: Object) {
return {
type: SET_CONFIG,
config
};
}

View File

@ -0,0 +1,4 @@
export * from './actions';
export * from './actionTypes';
import './reducer';

View File

@ -0,0 +1,63 @@
import { ReducerRegistry } from '../redux';
import { SET_CONFIG } from './actionTypes';
/**
* The initial state of the feature base/config. The mandatory configuration to
* be passed to JitsiMeetJS#init(). The app will download config.js from the
* Jitsi Meet deployment and take its values into account but the values bellow
* will be enforced (because they are essential to the correct execution of the
* application).
*
* @type {Object}
*/
const INITIAL_STATE = {
// FIXME The support for audio levels in lib-jitsi-meet polls the statistics
// of WebRTC at a short interval multiple times a second. Unfortunately,
// React Native is slow to fetch these statistics from the native WebRTC
// API, through the React Native bridge and eventually to JavaScript.
// Because the audio levels are of no interest to the mobile app, it is
// fastest to merely disable them.
disableAudioLevels: true,
// FIXME Lib-jitsi-meet uses HTML script elements to asynchronously load
// certain pieces of JavaScript. Unfortunately, the technique doesn't work
// on React Native (because there are no HTML elements in the first place).
// Fortunately, these pieces of JavaScript currently involve third parties
// and we can temporarily disable them (until we implement an alternative to
// async script elements on React Native).
disableThirdPartyRequests: true
};
ReducerRegistry.register(
'features/base/config',
(state = INITIAL_STATE, action) => {
switch (action.type) {
case SET_CONFIG:
return _setConfig(state, action);
default:
return state;
}
});
/**
* Reduces a specific Redux action SET_CONFIG of the feature
* base/lib-jitsi-meet.
*
* @param {Object} state - The Redux state of the feature base/lib-jitsi-meet.
* @param {Action} action - The Redux action SET_CONFIG to reduce.
* @private
* @returns {Object} The new state of the feature base/lib-jitsi-meet after the
* reduction of the specified action.
*/
function _setConfig(state, action) {
return {
...action.config,
// The config of INITIAL_STATE is meant to override the config
// downloaded from the Jitsi Meet deployment because the former contains
// values that are mandatory.
...INITIAL_STATE
};
}

View File

@ -49,16 +49,6 @@ export const LIB_WILL_DISPOSE = Symbol('LIB_WILL_DISPOSE');
*/ */
export const LIB_WILL_INIT = Symbol('LIB_WILL_INIT'); export const LIB_WILL_INIT = Symbol('LIB_WILL_INIT');
/**
* Action to signal that config was set.
*
* {
* type: SET_CONFIG,
* config: Object
* }
*/
export const SET_CONFIG = Symbol('SET_CONFIG');
/** /**
* The type of Redux action which indicates whether WebRTC is ready. * The type of Redux action which indicates whether WebRTC is ready.
* *

View File

@ -7,7 +7,6 @@ import {
LIB_INIT_ERROR, LIB_INIT_ERROR,
LIB_WILL_DISPOSE, LIB_WILL_DISPOSE,
LIB_WILL_INIT, LIB_WILL_INIT,
SET_CONFIG,
SET_WEBRTC_READY SET_WEBRTC_READY
} from './actionTypes'; } from './actionTypes';
@ -42,7 +41,7 @@ export function disposeLib() {
*/ */
export function initLib() { export function initLib() {
return (dispatch: Dispatch<*>, getState: Function) => { return (dispatch: Dispatch<*>, getState: Function) => {
const { config } = getState()['features/base/lib-jitsi-meet']; const config = getState()['features/base/config'];
if (!config) { if (!config) {
throw new Error('Cannot init lib-jitsi-meet without config'); throw new Error('Cannot init lib-jitsi-meet without config');
@ -85,23 +84,6 @@ export function libInitError(error: Error) {
}; };
} }
/**
* Sets config.
*
* @param {Object} config - The config(uration) object in the format accepted by
* the JitsiMeetJS.init() method.
* @returns {{
* type: SET_CONFIG,
* config: Object
* }}
*/
export function setConfig(config: Object) {
return {
type: SET_CONFIG,
config
};
}
/** /**
* Sets the indicator which determines whether WebRTC is ready. In execution * Sets the indicator which determines whether WebRTC is ready. In execution
* environments in which WebRTC is supported via a known plugin such * environments in which WebRTC is supported via a known plugin such

View File

@ -1,8 +1,11 @@
/* @flow */
import { SET_CONFIG } from '../config';
import { PARTICIPANT_LEFT } from '../participants'; import { PARTICIPANT_LEFT } from '../participants';
import { MiddlewareRegistry } from '../redux'; import { MiddlewareRegistry } from '../redux';
import { disposeLib, initLib, setWebRTCReady } from './actions'; import { disposeLib, initLib, setWebRTCReady } from './actions';
import { LIB_DID_INIT, LIB_INIT_ERROR, SET_CONFIG } from './actionTypes'; import { LIB_DID_INIT, LIB_INIT_ERROR } from './actionTypes';
import { WEBRTC_NOT_READY, WEBRTC_NOT_SUPPORTED } from './constants'; import { WEBRTC_NOT_READY, WEBRTC_NOT_SUPPORTED } from './constants';
/** /**

View File

@ -4,44 +4,15 @@ import {
LIB_DID_DISPOSE, LIB_DID_DISPOSE,
LIB_DID_INIT, LIB_DID_INIT,
LIB_INIT_ERROR, LIB_INIT_ERROR,
SET_CONFIG,
SET_WEBRTC_READY SET_WEBRTC_READY
} from './actionTypes'; } from './actionTypes';
/** /**
* The initial state of 'features/base/lib-jitsi-meet'. * The initial state of the feature base/lib-jitsi-meet.
*
* @type {{
* config: Object
* }}
*/
const INITIAL_STATE = {
/**
* The mandatory configuration to be passed to JitsiMeetJS#init(). The app
* will download config.js from the Jitsi Meet deployment and taks its
* values into account but the values bellow will be enforced (because they
* are essential to the correct execution of the application).
* *
* @type {Object} * @type {Object}
*/ */
config: { const INITIAL_STATE = {};
// FIXME The support for audio levels in lib-jitsi-meet polls the
// statistics of WebRTC at a short interval multiple times a second.
// Unfortunately, React Native is slow to fetch these statistics from
// the native WebRTC API, through the React Native bridge and eventually
// to JavaScript. Because the audio levels are of no interest to the
// mobile app, it is fastest to merely disable them.
disableAudioLevels: true,
// FIXME Lib-jitsi-meet uses HTML script elements to asynchronously load
// certain pieces of JavaScript. Unfortunately, the technique doesn't
// work on React Native (because there are no HTML elements in the first
// place). Fortunately, these pieces of JavaScript currently involve
// third parties and we can temporarily disable them (until we implement
// an alternative to async script elements on React Native).
disableThirdPartyRequests: true
}
};
ReducerRegistry.register( ReducerRegistry.register(
'features/base/lib-jitsi-meet', 'features/base/lib-jitsi-meet',
@ -64,9 +35,6 @@ ReducerRegistry.register(
initialized: false initialized: false
}; };
case SET_CONFIG:
return _setConfig(state, action);
case SET_WEBRTC_READY: case SET_WEBRTC_READY:
return { return {
...state, ...state,
@ -77,27 +45,3 @@ ReducerRegistry.register(
return state; return state;
} }
}); });
/**
* Reduces a specific Redux action SET_CONFIG of the feature
* base/lib-jitsi-meet.
*
* @param {Object} state - The Redux state of the feature base/lib-jitsi-meet.
* @param {Action} action - The Redux action SET_CONFIG to reduce.
* @private
* @returns {Object} The new state of the feature base/lib-jitsi-meet after the
* reduction of the specified action.
*/
function _setConfig(state, action) {
return {
...state,
config: {
...action.config,
// The config of INITIAL_STATE is meant to override the config
// downloaded from the Jitsi Meet deployment because the former
// contains values that are mandatory.
...INITIAL_STATE.config
}
};
}