瀏覽代碼

ref: remove features/base/conference -> /app cycle

Move call to reloadNow() on CONNECTION_FAILED to
the ./features/app/middleware to avoid importing higher order feature
from the lower level one.
master
paweldomas 5 年之前
父節點
當前提交
6c3968a434
共有 2 個檔案被更改,包括 73 行新增56 行删除
  1. 73
    0
      react/features/app/middleware.js
  2. 0
    56
      react/features/base/conference/middleware.js

+ 73
- 0
react/features/app/middleware.js 查看文件

@@ -1,18 +1,27 @@
1 1
 // @flow
2 2
 
3
+import {
4
+    createConnectionEvent,
5
+    sendAnalytics
6
+} from '../analytics';
7
+
3 8
 import { SET_ROOM } from '../base/conference';
4 9
 import {
5 10
     CONNECTION_ESTABLISHED,
11
+    CONNECTION_FAILED,
6 12
     getURLWithoutParams
7 13
 } from '../base/connection';
8 14
 import { MiddlewareRegistry } from '../base/redux';
9 15
 
16
+import { reloadNow } from './actions';
10 17
 import { _getRouteToRender } from './getRouteToRender';
11 18
 
12 19
 MiddlewareRegistry.register(store => next => action => {
13 20
     switch (action.type) {
14 21
     case CONNECTION_ESTABLISHED:
15 22
         return _connectionEstablished(store, next, action);
23
+    case CONNECTION_FAILED:
24
+        return _connectionFailed(store, next, action);
16 25
 
17 26
     case SET_ROOM:
18 27
         return _setRoom(store, next, action);
@@ -62,6 +71,70 @@ function _connectionEstablished(store, next, action) {
62 71
     return result;
63 72
 }
64 73
 
74
+/**
75
+ * CONNECTION_FAILED action side effects.
76
+ *
77
+ * @param {Object} store - The Redux store.
78
+ * @param {Dispatch} next - The redux {@code dispatch} function to dispatch the specified {@code action} to
79
+ * the specified {@code store}.
80
+ * @param {Action} action - The redux action {@code CONNECTION_FAILED} which is being dispatched in the specified
81
+ * {@code store}.
82
+ * @returns {Object}
83
+ * @private
84
+ */
85
+function _connectionFailed({ dispatch, getState }, next, action) {
86
+    // In the case of a split-brain error, reload early and prevent further
87
+    // handling of the action.
88
+    if (_isMaybeSplitBrainError(getState, action)) {
89
+        dispatch(reloadNow());
90
+
91
+        return;
92
+    }
93
+
94
+    return next(action);
95
+}
96
+
97
+/**
98
+ * Returns whether or not a CONNECTION_FAILED action is for a possible split brain error. A split brain error occurs
99
+ * when at least two users join a conference on different bridges. It is assumed the split brain scenario occurs very
100
+ * early on in the call.
101
+ *
102
+ * @param {Function} getState - The redux function for fetching the current state.
103
+ * @param {Action} action - The redux action {@code CONNECTION_FAILED} which is being dispatched in the specified
104
+ * {@code store}.
105
+ * @private
106
+ * @returns {boolean}
107
+ */
108
+function _isMaybeSplitBrainError(getState, action) {
109
+    const { error } = action;
110
+    const isShardChangedError = error
111
+        && error.message === 'item-not-found'
112
+        && error.details
113
+        && error.details.shard_changed;
114
+
115
+    if (isShardChangedError) {
116
+        const state = getState();
117
+        const { timeEstablished } = state['features/base/connection'];
118
+        const { _immediateReloadThreshold } = state['features/base/config'];
119
+
120
+        const timeSinceConnectionEstablished = timeEstablished && Date.now() - timeEstablished;
121
+        const reloadThreshold = typeof _immediateReloadThreshold === 'number' ? _immediateReloadThreshold : 1500;
122
+
123
+        const isWithinSplitBrainThreshold = !timeEstablished || timeSinceConnectionEstablished <= reloadThreshold;
124
+
125
+        sendAnalytics(createConnectionEvent('failed', {
126
+            ...error,
127
+            connectionEstablished: timeEstablished,
128
+            splitBrain: isWithinSplitBrainThreshold,
129
+            timeSinceConnectionEstablished
130
+        }));
131
+
132
+        return isWithinSplitBrainThreshold;
133
+    }
134
+
135
+    return false;
136
+}
137
+
65 138
 /**
66 139
  * Navigates to a route in accord with a specific redux state.
67 140
  *

+ 0
- 56
react/features/base/conference/middleware.js 查看文件

@@ -1,12 +1,10 @@
1 1
 // @flow
2 2
 
3
-import { reloadNow } from '../../app';
4 3
 import { openDisplayNamePrompt } from '../../display-name';
5 4
 
6 5
 import {
7 6
     ACTION_PINNED,
8 7
     ACTION_UNPINNED,
9
-    createConnectionEvent,
10 8
     createOfferAnswerFailedEvent,
11 9
     createPinnedEvent,
12 10
     sendAnalytics
@@ -256,14 +254,6 @@ function _connectionEstablished({ dispatch }, next, action) {
256 254
  * @returns {Object} The value returned by {@code next(action)}.
257 255
  */
258 256
 function _connectionFailed({ dispatch, getState }, next, action) {
259
-    // In the case of a split-brain error, reload early and prevent further
260
-    // handling of the action.
261
-    if (_isMaybeSplitBrainError(getState, action)) {
262
-        dispatch(reloadNow());
263
-
264
-        return;
265
-    }
266
-
267 257
     const result = next(action);
268 258
 
269 259
     if (typeof beforeUnloadHandler !== 'undefined') {
@@ -355,52 +345,6 @@ function _conferenceWillLeave() {
355 345
     }
356 346
 }
357 347
 
358
-/**
359
- * Returns whether or not a CONNECTION_FAILED action is for a possible split
360
- * brain error. A split brain error occurs when at least two users join a
361
- * conference on different bridges. It is assumed the split brain scenario
362
- * occurs very early on in the call.
363
- *
364
- * @param {Function} getState - The redux function for fetching the current
365
- * state.
366
- * @param {Action} action - The redux action {@code CONNECTION_FAILED} which is
367
- * being dispatched in the specified {@code store}.
368
- * @private
369
- * @returns {boolean}
370
- */
371
-function _isMaybeSplitBrainError(getState, action) {
372
-    const { error } = action;
373
-    const isShardChangedError = error
374
-        && error.message === 'item-not-found'
375
-        && error.details
376
-        && error.details.shard_changed;
377
-
378
-    if (isShardChangedError) {
379
-        const state = getState();
380
-        const { timeEstablished } = state['features/base/connection'];
381
-        const { _immediateReloadThreshold } = state['features/base/config'];
382
-
383
-        const timeSinceConnectionEstablished
384
-            = timeEstablished && Date.now() - timeEstablished;
385
-        const reloadThreshold = typeof _immediateReloadThreshold === 'number'
386
-            ? _immediateReloadThreshold : 1500;
387
-
388
-        const isWithinSplitBrainThreshold = !timeEstablished
389
-            || timeSinceConnectionEstablished <= reloadThreshold;
390
-
391
-        sendAnalytics(createConnectionEvent('failed', {
392
-            ...error,
393
-            connectionEstablished: timeEstablished,
394
-            splitBrain: isWithinSplitBrainThreshold,
395
-            timeSinceConnectionEstablished
396
-        }));
397
-
398
-        return isWithinSplitBrainThreshold;
399
-    }
400
-
401
-    return false;
402
-}
403
-
404 348
 /**
405 349
  * Notifies the feature base/conference that the action {@code PIN_PARTICIPANT}
406 350
  * is being dispatched within a specific redux store. Pins the specified remote

Loading…
取消
儲存