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
 import { loadConfig } from '../base/lib-jitsi-meet';
4
 import { loadConfig } from '../base/lib-jitsi-meet';
5
 
5
 
6
 import { APP_WILL_MOUNT, APP_WILL_UNMOUNT } from './actionTypes';
6
 import { APP_WILL_MOUNT, APP_WILL_UNMOUNT } from './actionTypes';
7
-import { _getRouteToRender, _parseURIString } from './functions';
7
+import { _parseURIString } from './functions';
8
 
8
 
9
 declare var APP: Object;
9
 declare var APP: Object;
10
 
10
 
50
 
50
 
51
     if (oldHost === newHost) {
51
     if (oldHost === newHost) {
52
         dispatchSetLocationURL();
52
         dispatchSetLocationURL();
53
-        dispatchSetRoomAndNavigate();
53
+        dispatchSetRoom();
54
     } else {
54
     } else {
55
         // If the host has changed, we need to load the config of the new host
55
         // If the host has changed, we need to load the config of the new host
56
         // and set it, and only after that we can navigate to a different route.
56
         // and set it, and only after that we can navigate to a different route.
58
             .then(
58
             .then(
59
                 config => configLoaded(/* err */ undefined, config),
59
                 config => configLoaded(/* err */ undefined, config),
60
                 err => configLoaded(err, /* config */ undefined))
60
                 err => configLoaded(err, /* config */ undefined))
61
-            .then(dispatchSetRoomAndNavigate);
61
+            .then(dispatchSetRoom);
62
     }
62
     }
63
 
63
 
64
     /**
64
     /**
110
      *
110
      *
111
      * @returns {void}
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
 
219
 
220
     return loadConfig(protocol + location.host + (location.contextRoot || '/'));
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
      * @returns {void}
65
      * @returns {void}
66
      */
66
      */
67
     _navigate(route) {
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
         // Navigate to the specified Route.
85
         // Navigate to the specified Route.
81
         const windowLocation = this.getWindowLocation();
86
         const windowLocation = this.getWindowLocation();
82
 
87
 
83
-        if (windowLocation.pathname === path) {
88
+        if (!route || windowLocation.pathname === path) {
84
             // The browser is at the specified path already and what remains is
89
             // The browser is at the specified path already and what remains is
85
             // to make this App instance aware of the route to be rendered at
90
             // to make this App instance aware of the route to be rendered at
86
             // the current location.
91
             // the current location.

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

1
+import { SET_ROOM } from '../base/conference';
1
 import {
2
 import {
2
     CONNECTION_ESTABLISHED,
3
     CONNECTION_ESTABLISHED,
3
-    getURLWithoutParams
4
+    getURLWithoutParams,
5
+    SET_LOCATION_URL
4
 } from '../base/connection';
6
 } from '../base/connection';
5
 import { MiddlewareRegistry } from '../base/redux';
7
 import { MiddlewareRegistry } from '../base/redux';
6
 
8
 
8
     switch (action.type) {
10
     switch (action.type) {
9
     case CONNECTION_ESTABLISHED:
11
     case CONNECTION_ESTABLISHED:
10
         return _connectionEstablished(store, next, action);
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
     return next(action);
19
     return next(action);
53
 
59
 
54
     return result;
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
-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
 import { APP_WILL_MOUNT, APP_WILL_UNMOUNT } from './actionTypes';
6
 import { APP_WILL_MOUNT, APP_WILL_UNMOUNT } from './actionTypes';
7
+import { _getRouteToRender } from './functions';
4
 
8
 
5
 ReducerRegistry.register('features/app', (state = {}, action) => {
9
 ReducerRegistry.register('features/app', (state = {}, action) => {
6
     switch (action.type) {
10
     switch (action.type) {
31
             };
35
             };
32
         }
36
         }
33
         break;
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
     return state;
46
     return state;

Loading…
Cancel
Save