From 52b3eaacb5ca9c1470a51cb9717817166e7c9c6e Mon Sep 17 00:00:00 2001 From: Lyubomir Marinov Date: Thu, 16 Feb 2017 13:51:01 -0600 Subject: [PATCH] [RN] Fix passing config.js to JitsiMeetJS.init --- .../base/lib-jitsi-meet/middleware.js | 54 +++++++++++++------ 1 file changed, 37 insertions(+), 17 deletions(-) diff --git a/react/features/base/lib-jitsi-meet/middleware.js b/react/features/base/lib-jitsi-meet/middleware.js index 05ec87da6..00275dee9 100644 --- a/react/features/base/lib-jitsi-meet/middleware.js +++ b/react/features/base/lib-jitsi-meet/middleware.js @@ -22,24 +22,44 @@ MiddlewareRegistry.register(store => next => action => { action.participant.local && store.dispatch(disposeLib()); break; - case SET_CONFIG: { - const { dispatch, getState } = store; - const initialized - = getState()['features/base/lib-jitsi-meet'].initialized; - - // XXX If we already have config, that means new config is coming, which - // means that we should dispose instance of lib initialized with - // previous config first. - // TODO Currently 'disposeLib' actually does not dispose lib-jitsi-meet. - // This functionality should be implemented. - const promise - = initialized ? dispatch(disposeLib()) : Promise.resolve(); - - promise.then(dispatch(initLib())); - - break; - } + case SET_CONFIG: + return _setConfig(store, next, action); } return next(action); }); + +/** + * Notifies the feature base/lib-jitsi-meet that the action SET_CONFIG is being + * dispatched within a specific Redux store. + * + * @param {Store} store - The Redux store in which the specified action is being + * dispatched. + * @param {Dispatch} next - The Redux dispatch function to dispatch the + * specified action to the specified store. + * @param {Action} action - The Redux action SET_CONFIG which is being + * dispatched in the specified store. + * @private + * @returns {Object} The new state that is the result of the reduction of the + * specified action. + */ +function _setConfig(store, next, action) { + const { dispatch, getState } = store; + const { initialized } = getState()['features/base/lib-jitsi-meet']; + + // XXX Since the config is changing, the library lib-jitsi-meet must be + // initialized again with the new config. Consequntly, it may need to be + // disposed of first. + // TODO Currently, disposeLib actually does not dispose of lib-jitsi-meet + // because lib-jitsi-meet does not implement such functionality. + const disposeLIbPromise + = initialized ? dispatch(disposeLib()) : Promise.resolve(); + + // Let the new config into the Redux store (because initLib will read it + // from there). + const nextState = next(action); + + disposeLIbPromise.then(dispatch(initLib())); + + return nextState; +}