Skip to content

Jitsi Meet - Secure, Simple and Scalable Video Conferences that you use as a standalone app or embed in your web application.

[RN] Disconnect/hangup before joining a new URL

Lyubo Marinov7dbba59deefd
diff --git a/react/features/app/actions.js b/react/features/app/actions.js
index faa42bbc71..1d05b82ec4 100644
--- a/react/features/app/actions.js
+++ b/react/features/app/actions.js
@@ -4,7 +4,7 @@ import { setConfig } from '../base/config';
import { loadConfig } from '../base/lib-jitsi-meet';
import { APP_WILL_MOUNT, APP_WILL_UNMOUNT } from './actionTypes';
-import { _getRouteToRender, _parseURIString } from './functions';
+import { _parseURIString } from './functions';
declare var APP: Object;
@@ -50,7 +50,7 @@ function _appNavigateToMandatoryLocation(
if (oldHost === newHost) {
dispatchSetLocationURL();
- dispatchSetRoomAndNavigate();
+ dispatchSetRoom();
} else {
// If the host has changed, we need to load the config of the new host
// and set it, and only after that we can navigate to a different route.
@@ -58,7 +58,7 @@ function _appNavigateToMandatoryLocation(
.then(
config => configLoaded(/* err */ undefined, config),
err => configLoaded(err, /* config */ undefined))
- .then(dispatchSetRoomAndNavigate);
+ .then(dispatchSetRoom);
}
/**
@@ -110,8 +110,8 @@ function _appNavigateToMandatoryLocation(
*
* @returns {void}
*/
- function dispatchSetRoomAndNavigate() {
- dispatch(_setRoomAndNavigate(newLocation.room));
+ function dispatchSetRoom() {
+ dispatch(setRoom(newLocation.room));
}
}
@@ -219,32 +219,3 @@ function _loadConfig(location: Object) {
return loadConfig(protocol + location.host + (location.contextRoot || '/'));
}
-
-/**
- * Navigates to a route in accord with a specific redux state.
- *
- * @param {Object} state - The redux state which determines/identifies the route
- * to navigate to.
- * @private
- * @returns {void}
- */
-function _navigate(state) {
- const app = state['features/app'].app;
- const routeToRender = _getRouteToRender(state);
-
- app._navigate(routeToRender);
-}
-
-/**
- * Sets room and navigates to new route if needed.
- *
- * @param {string} newRoom - New room name.
- * @private
- * @returns {Function}
- */
-function _setRoomAndNavigate(newRoom) {
- return (dispatch, getState) => {
- dispatch(setRoom(newRoom));
- _navigate(getState());
- };
-}
diff --git a/react/features/app/components/App.web.js b/react/features/app/components/App.web.js
index c4b799b717..5113ceb6ac 100644
--- a/react/features/app/components/App.web.js
+++ b/react/features/app/components/App.web.js
@@ -65,22 +65,27 @@ export class App extends AbstractApp {
* @returns {void}
*/
_navigate(route) {
- let path = route.path;
- const store = this._getStore();
-
- // The syntax :room bellow is defined by react-router. It "matches a URL
- // segment up to the next /, ?, or #. The matched string is called a
- // param."
- path
- = path.replace(
- /:room/g,
- store.getState()['features/base/conference'].room);
- path = this._routePath2WindowLocationPathname(path);
+ let path;
+
+ if (route) {
+ path = route.path;
+
+ const store = this._getStore();
+
+ // The syntax :room bellow is defined by react-router. It "matches a
+ // URL segment up to the next /, ?, or #. The matched string is
+ // called a param."
+ path
+ = path.replace(
+ /:room/g,
+ store.getState()['features/base/conference'].room);
+ path = this._routePath2WindowLocationPathname(path);
+ }
// Navigate to the specified Route.
const windowLocation = this.getWindowLocation();
- if (windowLocation.pathname === path) {
+ if (!route || windowLocation.pathname === path) {
// The browser is at the specified path already and what remains is
// to make this App instance aware of the route to be rendered at
// the current location.
diff --git a/react/features/app/middleware.js b/react/features/app/middleware.js
index 72b97197b8..afb827bf28 100644
--- a/react/features/app/middleware.js
+++ b/react/features/app/middleware.js
@@ -1,6 +1,8 @@
+import { SET_ROOM } from '../base/conference';
import {
CONNECTION_ESTABLISHED,
- getURLWithoutParams
+ getURLWithoutParams,
+ SET_LOCATION_URL
} from '../base/connection';
import { MiddlewareRegistry } from '../base/redux';
@@ -8,6 +10,10 @@ MiddlewareRegistry.register(store => next => action => {
switch (action.type) {
case CONNECTION_ESTABLISHED:
return _connectionEstablished(store, next, action);
+
+ case SET_LOCATION_URL:
+ case SET_ROOM:
+ return _setLocationURLOrRoom(store, next, action);
}
return next(action);
@@ -53,3 +59,40 @@ function _connectionEstablished(store, next, action) {
return result;
}
+
+/**
+ * Navigates to a route in accord with a specific redux state.
+ *
+ * @param {Object} state - The redux state which determines/identifies the route
+ * to navigate to.
+ * @private
+ * @returns {void}
+ */
+function _navigate(state) {
+ const { app, getRouteToRender } = state['features/app'];
+ const routeToRender = getRouteToRender && getRouteToRender(state);
+
+ app._navigate(routeToRender);
+}
+
+/**
+ * Notifies the feature app that the action {@link SET_LOCATION_URL} or
+ * {@link SET_ROOM} 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} or
+ * {@code SET_ROOM} 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 _setLocationURLOrRoom({ getState }, next, action) {
+ const result = next(action);
+
+ _navigate(getState());
+
+ return result;
+}
diff --git a/react/features/app/reducer.js b/react/features/app/reducer.js
index 5f091d7e4d..a756348ab1 100644
--- a/react/features/app/reducer.js
+++ b/react/features/app/reducer.js
@@ -1,6 +1,10 @@
-import { ReducerRegistry } from '../base/redux';
+import { SET_ROOM } from '../base/conference';
+import { SET_LOCATION_URL } from '../base/connection';
+
+import { ReducerRegistry, set } from '../base/redux';
import { APP_WILL_MOUNT, APP_WILL_UNMOUNT } from './actionTypes';
+import { _getRouteToRender } from './functions';
ReducerRegistry.register('features/app', (state = {}, action) => {
switch (action.type) {
@@ -31,6 +35,12 @@ ReducerRegistry.register('features/app', (state = {}, action) => {
};
}
break;
+
+ case SET_LOCATION_URL:
+ return set(state, 'getRouteToRender', undefined);
+
+ case SET_ROOM:
+ return set(state, 'getRouteToRender', _getRouteToRender);
}
return state;