Browse Source

[RN] Disconnect/hangup before joining a new URL

master
Lyubo Marinov 8 years ago
parent
commit
7dbba59dee

+ 5
- 34
react/features/app/actions.js View File

@@ -4,7 +4,7 @@ import { setConfig } from '../base/config';
4 4
 import { loadConfig } from '../base/lib-jitsi-meet';
5 5
 
6 6
 import { APP_WILL_MOUNT, APP_WILL_UNMOUNT } from './actionTypes';
7
-import { _getRouteToRender, _parseURIString } from './functions';
7
+import { _parseURIString } from './functions';
8 8
 
9 9
 declare var APP: Object;
10 10
 
@@ -50,7 +50,7 @@ function _appNavigateToMandatoryLocation(
50 50
 
51 51
     if (oldHost === newHost) {
52 52
         dispatchSetLocationURL();
53
-        dispatchSetRoomAndNavigate();
53
+        dispatchSetRoom();
54 54
     } else {
55 55
         // If the host has changed, we need to load the config of the new host
56 56
         // and set it, and only after that we can navigate to a different route.
@@ -58,7 +58,7 @@ function _appNavigateToMandatoryLocation(
58 58
             .then(
59 59
                 config => configLoaded(/* err */ undefined, config),
60 60
                 err => configLoaded(err, /* config */ undefined))
61
-            .then(dispatchSetRoomAndNavigate);
61
+            .then(dispatchSetRoom);
62 62
     }
63 63
 
64 64
     /**
@@ -110,8 +110,8 @@ function _appNavigateToMandatoryLocation(
110 110
      *
111 111
      * @returns {void}
112 112
      */
113
-    function dispatchSetRoomAndNavigate() {
114
-        dispatch(_setRoomAndNavigate(newLocation.room));
113
+    function dispatchSetRoom() {
114
+        dispatch(setRoom(newLocation.room));
115 115
     }
116 116
 }
117 117
 
@@ -219,32 +219,3 @@ function _loadConfig(location: Object) {
219 219
 
220 220
     return loadConfig(protocol + location.host + (location.contextRoot || '/'));
221 221
 }
222
-
223
-/**
224
- * Navigates to a route in accord with a specific redux state.
225
- *
226
- * @param {Object} state - The redux state which determines/identifies the route
227
- * to navigate to.
228
- * @private
229
- * @returns {void}
230
- */
231
-function _navigate(state) {
232
-    const app = state['features/app'].app;
233
-    const routeToRender = _getRouteToRender(state);
234
-
235
-    app._navigate(routeToRender);
236
-}
237
-
238
-/**
239
- * Sets room and navigates to new route if needed.
240
- *
241
- * @param {string} newRoom - New room name.
242
- * @private
243
- * @returns {Function}
244
- */
245
-function _setRoomAndNavigate(newRoom) {
246
-    return (dispatch, getState) => {
247
-        dispatch(setRoom(newRoom));
248
-        _navigate(getState());
249
-    };
250
-}

+ 17
- 12
react/features/app/components/App.web.js View File

@@ -65,22 +65,27 @@ export class App extends AbstractApp {
65 65
      * @returns {void}
66 66
      */
67 67
     _navigate(route) {
68
-        let path = route.path;
69
-        const store = this._getStore();
70
-
71
-        // The syntax :room bellow is defined by react-router. It "matches a URL
72
-        // segment up to the next /, ?, or #. The matched string is called a
73
-        // param."
74
-        path
75
-            = path.replace(
76
-                /:room/g,
77
-                store.getState()['features/base/conference'].room);
78
-        path = this._routePath2WindowLocationPathname(path);
68
+        let path;
69
+
70
+        if (route) {
71
+            path = route.path;
72
+
73
+            const store = this._getStore();
74
+
75
+            // The syntax :room bellow is defined by react-router. It "matches a
76
+            // URL segment up to the next /, ?, or #. The matched string is
77
+            // called a param."
78
+            path
79
+                = path.replace(
80
+                    /:room/g,
81
+                    store.getState()['features/base/conference'].room);
82
+            path = this._routePath2WindowLocationPathname(path);
83
+        }
79 84
 
80 85
         // Navigate to the specified Route.
81 86
         const windowLocation = this.getWindowLocation();
82 87
 
83
-        if (windowLocation.pathname === path) {
88
+        if (!route || windowLocation.pathname === path) {
84 89
             // The browser is at the specified path already and what remains is
85 90
             // to make this App instance aware of the route to be rendered at
86 91
             // the current location.

+ 44
- 1
react/features/app/middleware.js View File

@@ -1,6 +1,8 @@
1
+import { SET_ROOM } from '../base/conference';
1 2
 import {
2 3
     CONNECTION_ESTABLISHED,
3
-    getURLWithoutParams
4
+    getURLWithoutParams,
5
+    SET_LOCATION_URL
4 6
 } from '../base/connection';
5 7
 import { MiddlewareRegistry } from '../base/redux';
6 8
 
@@ -8,6 +10,10 @@ MiddlewareRegistry.register(store => next => action => {
8 10
     switch (action.type) {
9 11
     case CONNECTION_ESTABLISHED:
10 12
         return _connectionEstablished(store, next, action);
13
+
14
+    case SET_LOCATION_URL:
15
+    case SET_ROOM:
16
+        return _setLocationURLOrRoom(store, next, action);
11 17
     }
12 18
 
13 19
     return next(action);
@@ -53,3 +59,40 @@ function _connectionEstablished(store, next, action) {
53 59
 
54 60
     return result;
55 61
 }
62
+
63
+/**
64
+ * Navigates to a route in accord with a specific redux state.
65
+ *
66
+ * @param {Object} state - The redux state which determines/identifies the route
67
+ * to navigate to.
68
+ * @private
69
+ * @returns {void}
70
+ */
71
+function _navigate(state) {
72
+    const { app, getRouteToRender } = state['features/app'];
73
+    const routeToRender = getRouteToRender && getRouteToRender(state);
74
+
75
+    app._navigate(routeToRender);
76
+}
77
+
78
+/**
79
+ * Notifies the feature app that the action {@link SET_LOCATION_URL} or
80
+ * {@link SET_ROOM} is being dispatched within a specific redux {@code store}.
81
+ *
82
+ * @param {Store} store - The redux store in which the specified {@code action}
83
+ * is being dispatched.
84
+ * @param {Dispatch} next - The redux {@code dispatch} function to dispatch the
85
+ * specified {@code action} to the specified {@code store}.
86
+ * @param {Action} action - The redux action {@code SET_LOCATION_URL} or
87
+ * {@code SET_ROOM} which is being dispatched in the specified {@code store}.
88
+ * @private
89
+ * @returns {Object} The new state that is the result of the reduction of the
90
+ * specified {@code action}.
91
+ */
92
+function _setLocationURLOrRoom({ getState }, next, action) {
93
+    const result = next(action);
94
+
95
+    _navigate(getState());
96
+
97
+    return result;
98
+}

+ 11
- 1
react/features/app/reducer.js View File

@@ -1,6 +1,10 @@
1
-import { ReducerRegistry } from '../base/redux';
1
+import { SET_ROOM } from '../base/conference';
2
+import { SET_LOCATION_URL } from '../base/connection';
3
+
4
+import { ReducerRegistry, set } from '../base/redux';
2 5
 
3 6
 import { APP_WILL_MOUNT, APP_WILL_UNMOUNT } from './actionTypes';
7
+import { _getRouteToRender } from './functions';
4 8
 
5 9
 ReducerRegistry.register('features/app', (state = {}, action) => {
6 10
     switch (action.type) {
@@ -31,6 +35,12 @@ ReducerRegistry.register('features/app', (state = {}, action) => {
31 35
             };
32 36
         }
33 37
         break;
38
+
39
+    case SET_LOCATION_URL:
40
+        return set(state, 'getRouteToRender', undefined);
41
+
42
+    case SET_ROOM:
43
+        return set(state, 'getRouteToRender', _getRouteToRender);
34 44
     }
35 45
 
36 46
     return state;

Loading…
Cancel
Save