diff --git a/react/features/app/actions.js b/react/features/app/actions.js index f2455ff47..c87bf0d2f 100644 --- a/react/features/app/actions.js +++ b/react/features/app/actions.js @@ -1,6 +1,7 @@ import { setRoom } from '../base/conference'; +import { setConfig } from '../base/config'; 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 { diff --git a/react/features/base/conference/actions.js b/react/features/base/conference/actions.js index 2696e2f67..538a23643 100644 --- a/react/features/base/conference/actions.js +++ b/react/features/base/conference/actions.js @@ -254,7 +254,7 @@ export function createConference() { dispatch(_conferenceWillJoin(room)); - const { config } = state['features/base/lib-jitsi-meet']; + const config = state['features/base/config']; const conference = connection.initJitsiConference( @@ -368,7 +368,7 @@ export function _setAudioOnlyVideoMuted(muted: boolean) { export function setLastN(lastN: ?number) { return (dispatch: Dispatch<*>, getState: Function) => { if (typeof lastN === 'undefined') { - const { config } = getState()['features/base/lib-jitsi-meet']; + const config = getState()['features/base/config']; /* eslint-disable no-param-reassign */ diff --git a/react/features/base/config/actionTypes.js b/react/features/base/config/actionTypes.js new file mode 100644 index 000000000..0f5898d5d --- /dev/null +++ b/react/features/base/config/actionTypes.js @@ -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'); diff --git a/react/features/base/config/actions.js b/react/features/base/config/actions.js new file mode 100644 index 000000000..a609c5ca5 --- /dev/null +++ b/react/features/base/config/actions.js @@ -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 + }; +} diff --git a/react/features/base/config/index.js b/react/features/base/config/index.js new file mode 100644 index 000000000..81e1e72ee --- /dev/null +++ b/react/features/base/config/index.js @@ -0,0 +1,4 @@ +export * from './actions'; +export * from './actionTypes'; + +import './reducer'; diff --git a/react/features/base/config/reducer.js b/react/features/base/config/reducer.js new file mode 100644 index 000000000..15877b0eb --- /dev/null +++ b/react/features/base/config/reducer.js @@ -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 + }; +} diff --git a/react/features/base/lib-jitsi-meet/actionTypes.js b/react/features/base/lib-jitsi-meet/actionTypes.js index 17ba367ff..eeaa07054 100644 --- a/react/features/base/lib-jitsi-meet/actionTypes.js +++ b/react/features/base/lib-jitsi-meet/actionTypes.js @@ -49,16 +49,6 @@ export const LIB_WILL_DISPOSE = Symbol('LIB_WILL_DISPOSE'); */ 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. * diff --git a/react/features/base/lib-jitsi-meet/actions.js b/react/features/base/lib-jitsi-meet/actions.js index 1cc10722a..a659fb770 100644 --- a/react/features/base/lib-jitsi-meet/actions.js +++ b/react/features/base/lib-jitsi-meet/actions.js @@ -7,7 +7,6 @@ import { LIB_INIT_ERROR, LIB_WILL_DISPOSE, LIB_WILL_INIT, - SET_CONFIG, SET_WEBRTC_READY } from './actionTypes'; @@ -42,7 +41,7 @@ export function disposeLib() { */ export function initLib() { return (dispatch: Dispatch<*>, getState: Function) => { - const { config } = getState()['features/base/lib-jitsi-meet']; + const config = getState()['features/base/config']; if (!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 * environments in which WebRTC is supported via a known plugin such diff --git a/react/features/base/lib-jitsi-meet/middleware.js b/react/features/base/lib-jitsi-meet/middleware.js index 0b60ac041..48a223ddd 100644 --- a/react/features/base/lib-jitsi-meet/middleware.js +++ b/react/features/base/lib-jitsi-meet/middleware.js @@ -1,8 +1,11 @@ +/* @flow */ + +import { SET_CONFIG } from '../config'; import { PARTICIPANT_LEFT } from '../participants'; import { MiddlewareRegistry } from '../redux'; 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'; /** diff --git a/react/features/base/lib-jitsi-meet/reducer.js b/react/features/base/lib-jitsi-meet/reducer.js index b85c544da..f4768ac62 100644 --- a/react/features/base/lib-jitsi-meet/reducer.js +++ b/react/features/base/lib-jitsi-meet/reducer.js @@ -4,44 +4,15 @@ import { LIB_DID_DISPOSE, LIB_DID_INIT, LIB_INIT_ERROR, - SET_CONFIG, SET_WEBRTC_READY } from './actionTypes'; /** - * The initial state of 'features/base/lib-jitsi-meet'. + * The initial state of the feature base/lib-jitsi-meet. * - * @type {{ - * config: Object - * }} + * @type {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} - */ - config: { - // 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 - } -}; +const INITIAL_STATE = {}; ReducerRegistry.register( 'features/base/lib-jitsi-meet', @@ -64,9 +35,6 @@ ReducerRegistry.register( initialized: false }; - case SET_CONFIG: - return _setConfig(state, action); - case SET_WEBRTC_READY: return { ...state, @@ -77,27 +45,3 @@ ReducerRegistry.register( 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 - } - }; -}