|
@@ -5,6 +5,7 @@ import {
|
5
|
5
|
SET_LOCATION_URL
|
6
|
6
|
} from '../base/connection';
|
7
|
7
|
import { MiddlewareRegistry } from '../base/redux';
|
|
8
|
+import { createInitialLocalTracks, destroyLocalTracks } from '../base/tracks';
|
8
|
9
|
|
9
|
10
|
MiddlewareRegistry.register(store => next => action => {
|
10
|
11
|
switch (action.type) {
|
|
@@ -12,8 +13,10 @@ MiddlewareRegistry.register(store => next => action => {
|
12
|
13
|
return _connectionEstablished(store, next, action);
|
13
|
14
|
|
14
|
15
|
case SET_LOCATION_URL:
|
|
16
|
+ return _setLocationURL(store, next, action);
|
|
17
|
+
|
15
|
18
|
case SET_ROOM:
|
16
|
|
- return _setLocationURLOrRoom(store, next, action);
|
|
19
|
+ return _setRoom(store, next, action);
|
17
|
20
|
}
|
18
|
21
|
|
19
|
22
|
return next(action);
|
|
@@ -63,36 +66,77 @@ function _connectionEstablished(store, next, action) {
|
63
|
66
|
/**
|
64
|
67
|
* Navigates to a route in accord with a specific redux state.
|
65
|
68
|
*
|
66
|
|
- * @param {Object} state - The redux state which determines/identifies the route
|
|
69
|
+ * @param {Store} store - The redux store which determines/identifies the route
|
67
|
70
|
* to navigate to.
|
68
|
71
|
* @private
|
69
|
72
|
* @returns {void}
|
70
|
73
|
*/
|
71
|
|
-function _navigate(state) {
|
|
74
|
+function _navigate({ dispatch, getState }) {
|
|
75
|
+ const state = getState();
|
72
|
76
|
const { app, getRouteToRender } = state['features/app'];
|
73
|
77
|
const routeToRender = getRouteToRender && getRouteToRender(state);
|
74
|
78
|
|
|
79
|
+ // Create/destroy the local tracks as needed: create them the first time we
|
|
80
|
+ // are going to render an actual route (be that the WelcomePage or the
|
|
81
|
+ // Conference).
|
|
82
|
+ //
|
|
83
|
+ // When the WelcomePage is disabled, the app will transition to the
|
|
84
|
+ // null/undefined route. Detect these transitions and create/destroy the
|
|
85
|
+ // local tracks so the camera doesn't stay open if the app is not rendering
|
|
86
|
+ // any component.
|
|
87
|
+ if (typeof routeToRender === 'undefined' || routeToRender === null) {
|
|
88
|
+ // Destroy the local tracks if there is no route to render and there is
|
|
89
|
+ // no welcome page.
|
|
90
|
+ app.props.welcomePageEnabled || dispatch(destroyLocalTracks());
|
|
91
|
+ } else {
|
|
92
|
+ // Create the local tracks if they haven't been created yet.
|
|
93
|
+ state['features/base/tracks'].some(t => t.local)
|
|
94
|
+ || dispatch(createInitialLocalTracks());
|
|
95
|
+ }
|
|
96
|
+
|
75
|
97
|
app._navigate(routeToRender);
|
76
|
98
|
}
|
77
|
99
|
|
78
|
100
|
/**
|
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}.
|
|
101
|
+ * Notifies the feature app that the action {@link SET_LOCATION_URL} is being
|
|
102
|
+ * dispatched within a specific redux {@code store}.
|
|
103
|
+ *
|
|
104
|
+ * @param {Store} store - The redux store in which the specified {@code action}
|
|
105
|
+ * is being dispatched.
|
|
106
|
+ * @param {Dispatch} next - The redux {@code dispatch} function to dispatch the
|
|
107
|
+ * specified {@code action} to the specified {@code store}.
|
|
108
|
+ * @param {Action} action - The redux action, {@code SET_LOCATION_URL}, which is
|
|
109
|
+ * being dispatched in the specified {@code store}.
|
|
110
|
+ * @private
|
|
111
|
+ * @returns {Object} The new state that is the result of the reduction of the
|
|
112
|
+ * specified {@code action}.
|
|
113
|
+ */
|
|
114
|
+function _setLocationURL({ getState }, next, action) {
|
|
115
|
+ const result = next(action);
|
|
116
|
+
|
|
117
|
+ getState()['features/app'].app._navigate(undefined);
|
|
118
|
+
|
|
119
|
+ return result;
|
|
120
|
+}
|
|
121
|
+
|
|
122
|
+/**
|
|
123
|
+ * Notifies the feature app that the action {@link SET_ROOM} is being dispatched
|
|
124
|
+ * within a specific redux {@code store}.
|
81
|
125
|
*
|
82
|
126
|
* @param {Store} store - The redux store in which the specified {@code action}
|
83
|
127
|
* is being dispatched.
|
84
|
128
|
* @param {Dispatch} next - The redux {@code dispatch} function to dispatch the
|
85
|
129
|
* 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}.
|
|
130
|
+ * @param {Action} action - The redux action, {@code SET_ROOM}, which is being
|
|
131
|
+ * dispatched in the specified {@code store}.
|
88
|
132
|
* @private
|
89
|
133
|
* @returns {Object} The new state that is the result of the reduction of the
|
90
|
134
|
* specified {@code action}.
|
91
|
135
|
*/
|
92
|
|
-function _setLocationURLOrRoom({ getState }, next, action) {
|
|
136
|
+function _setRoom(store, next, action) {
|
93
|
137
|
const result = next(action);
|
94
|
138
|
|
95
|
|
- _navigate(getState());
|
|
139
|
+ _navigate(store);
|
96
|
140
|
|
97
|
141
|
return result;
|
98
|
142
|
}
|