2017-07-06 18:39:59 +00:00
|
|
|
import { SET_ROOM } from '../base/conference';
|
2017-06-01 18:43:57 +00:00
|
|
|
import {
|
|
|
|
CONNECTION_ESTABLISHED,
|
2017-07-06 18:39:59 +00:00
|
|
|
getURLWithoutParams,
|
|
|
|
SET_LOCATION_URL
|
2017-06-01 18:43:57 +00:00
|
|
|
} from '../base/connection';
|
|
|
|
import { MiddlewareRegistry } from '../base/redux';
|
2017-07-12 12:22:23 +00:00
|
|
|
import { createInitialLocalTracks, destroyLocalTracks } from '../base/tracks';
|
2017-06-01 18:43:57 +00:00
|
|
|
|
|
|
|
MiddlewareRegistry.register(store => next => action => {
|
|
|
|
switch (action.type) {
|
|
|
|
case CONNECTION_ESTABLISHED:
|
|
|
|
return _connectionEstablished(store, next, action);
|
2017-07-06 18:39:59 +00:00
|
|
|
|
|
|
|
case SET_LOCATION_URL:
|
2017-07-12 12:22:23 +00:00
|
|
|
return _setLocationURL(store, next, action);
|
|
|
|
|
2017-07-06 18:39:59 +00:00
|
|
|
case SET_ROOM:
|
2017-07-12 12:22:23 +00:00
|
|
|
return _setRoom(store, next, action);
|
2017-06-01 18:43:57 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
return next(action);
|
|
|
|
});
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Notifies the feature app that the action {@link CONNECTION_ESTABLISHED} is
|
2017-07-06 18:24:24 +00:00
|
|
|
* being dispatched within a specific redux {@code store}.
|
2017-06-01 18:43:57 +00:00
|
|
|
*
|
2017-07-06 18:24:24 +00:00
|
|
|
* @param {Store} store - The redux store in which the specified {@code action}
|
2017-06-01 18:43:57 +00:00
|
|
|
* is being dispatched.
|
2017-07-06 18:24:24 +00:00
|
|
|
* @param {Dispatch} next - The redux {@code dispatch} function to dispatch the
|
2017-06-01 18:43:57 +00:00
|
|
|
* specified {@code action} to the specified {@code store}.
|
2017-07-06 18:24:24 +00:00
|
|
|
* @param {Action} action - The redux action {@code CONNECTION_ESTABLISHED}
|
2017-06-01 18:43:57 +00:00
|
|
|
* which is being dispatched in the specified {@code store}.
|
|
|
|
* @private
|
|
|
|
* @returns {Object} The new state that is the result of the reduction of the
|
|
|
|
* specified {@code action}.
|
|
|
|
*/
|
|
|
|
function _connectionEstablished(store, next, action) {
|
|
|
|
const result = next(action);
|
|
|
|
|
|
|
|
// In the Web app we explicitly do not want to display the hash and
|
|
|
|
// query/search URL params. Unfortunately, window.location and, more
|
|
|
|
// importantly, its params are used not only in jitsi-meet but also in
|
|
|
|
// lib-jitsi-meet. Consequenlty, the time to remove the params is
|
|
|
|
// determined by when no one needs them anymore.
|
|
|
|
const { history, location } = window;
|
|
|
|
|
|
|
|
if (history
|
|
|
|
&& location
|
|
|
|
&& history.length
|
|
|
|
&& typeof history.replaceState === 'function') {
|
|
|
|
const replacement = getURLWithoutParams(location);
|
|
|
|
|
|
|
|
if (location !== replacement) {
|
|
|
|
history.replaceState(
|
|
|
|
history.state,
|
|
|
|
(document && document.title) || '',
|
|
|
|
replacement);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return result;
|
|
|
|
}
|
2017-07-06 18:39:59 +00:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Navigates to a route in accord with a specific redux state.
|
|
|
|
*
|
2017-07-12 12:22:23 +00:00
|
|
|
* @param {Store} store - The redux store which determines/identifies the route
|
2017-07-06 18:39:59 +00:00
|
|
|
* to navigate to.
|
|
|
|
* @private
|
|
|
|
* @returns {void}
|
|
|
|
*/
|
2017-07-12 12:22:23 +00:00
|
|
|
function _navigate({ dispatch, getState }) {
|
|
|
|
const state = getState();
|
2017-07-06 18:39:59 +00:00
|
|
|
const { app, getRouteToRender } = state['features/app'];
|
|
|
|
const routeToRender = getRouteToRender && getRouteToRender(state);
|
|
|
|
|
2017-07-19 04:42:08 +00:00
|
|
|
// FIXME The following is logic specific to the user experience of the
|
|
|
|
// mobile/React Native app. Firstly, I don't like that it's here at all.
|
|
|
|
// Secondly, I copied the mobile/React Native detection from
|
|
|
|
// react/features/base/config/reducer.js because I couldn't iron out an
|
|
|
|
// abstraction. Because of the first point, I'm leaving the second point
|
|
|
|
// unresolved to attract attention to the fact that the following needs more
|
|
|
|
// thinking.
|
2017-07-19 08:51:07 +00:00
|
|
|
if (navigator.product === 'ReactNative') {
|
2017-07-19 04:42:08 +00:00
|
|
|
// Create/destroy the local tracks as needed: create them the first time
|
|
|
|
// we are going to render an actual route (be that the WelcomePage or
|
|
|
|
// the Conference).
|
|
|
|
//
|
|
|
|
// When the WelcomePage is disabled, the app will transition to the
|
|
|
|
// null/undefined route. Detect these transitions and create/destroy the
|
|
|
|
// local tracks so the camera doesn't stay open if the app is not
|
|
|
|
// rendering any component.
|
|
|
|
if (typeof routeToRender === 'undefined' || routeToRender === null) {
|
|
|
|
// Destroy the local tracks if there is no route to render and there
|
|
|
|
// is no WelcomePage.
|
|
|
|
app.props.welcomePageEnabled || dispatch(destroyLocalTracks());
|
|
|
|
} else {
|
|
|
|
// Create the local tracks if they haven't been created yet.
|
|
|
|
state['features/base/tracks'].some(t => t.local)
|
|
|
|
|| dispatch(createInitialLocalTracks());
|
|
|
|
}
|
2017-07-12 12:22:23 +00:00
|
|
|
}
|
|
|
|
|
2017-08-01 00:34:19 +00:00
|
|
|
return app._navigate(routeToRender);
|
2017-07-06 18:39:59 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
2017-07-12 12:22:23 +00:00
|
|
|
* Notifies the feature app that the action {@link SET_LOCATION_URL} is being
|
|
|
|
* dispatched within a specific redux {@code store}.
|
|
|
|
*
|
|
|
|
* @param {Store} store - The redux store in which the specified {@code action}
|
|
|
|
* is being dispatched.
|
|
|
|
* @param {Dispatch} next - The redux {@code dispatch} function to dispatch the
|
|
|
|
* specified {@code action} to the specified {@code store}.
|
|
|
|
* @param {Action} action - The redux action, {@code SET_LOCATION_URL}, which is
|
|
|
|
* being dispatched in the specified {@code store}.
|
|
|
|
* @private
|
|
|
|
* @returns {Object} The new state that is the result of the reduction of the
|
|
|
|
* specified {@code action}.
|
|
|
|
*/
|
|
|
|
function _setLocationURL({ getState }, next, action) {
|
2017-08-01 00:34:19 +00:00
|
|
|
return (
|
|
|
|
getState()['features/app'].app._navigate(undefined)
|
|
|
|
.then(() => next(action)));
|
2017-07-12 12:22:23 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Notifies the feature app that the action {@link SET_ROOM} is being dispatched
|
|
|
|
* within a specific redux {@code store}.
|
2017-07-06 18:39:59 +00:00
|
|
|
*
|
|
|
|
* @param {Store} store - The redux store in which the specified {@code action}
|
|
|
|
* is being dispatched.
|
|
|
|
* @param {Dispatch} next - The redux {@code dispatch} function to dispatch the
|
|
|
|
* specified {@code action} to the specified {@code store}.
|
2017-07-12 12:22:23 +00:00
|
|
|
* @param {Action} action - The redux action, {@code SET_ROOM}, which is being
|
|
|
|
* dispatched in the specified {@code store}.
|
2017-07-06 18:39:59 +00:00
|
|
|
* @private
|
|
|
|
* @returns {Object} The new state that is the result of the reduction of the
|
|
|
|
* specified {@code action}.
|
|
|
|
*/
|
2017-07-12 12:22:23 +00:00
|
|
|
function _setRoom(store, next, action) {
|
2017-07-06 18:39:59 +00:00
|
|
|
const result = next(action);
|
|
|
|
|
2017-07-12 12:22:23 +00:00
|
|
|
_navigate(store);
|
2017-07-06 18:39:59 +00:00
|
|
|
|
|
|
|
return result;
|
|
|
|
}
|