浏览代码

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
 // @flow
1
 // @flow
2
 
2
 
3
+import {
4
+    createConnectionEvent,
5
+    sendAnalytics
6
+} from '../analytics';
7
+
3
 import { SET_ROOM } from '../base/conference';
8
 import { SET_ROOM } from '../base/conference';
4
 import {
9
 import {
5
     CONNECTION_ESTABLISHED,
10
     CONNECTION_ESTABLISHED,
11
+    CONNECTION_FAILED,
6
     getURLWithoutParams
12
     getURLWithoutParams
7
 } from '../base/connection';
13
 } from '../base/connection';
8
 import { MiddlewareRegistry } from '../base/redux';
14
 import { MiddlewareRegistry } from '../base/redux';
9
 
15
 
16
+import { reloadNow } from './actions';
10
 import { _getRouteToRender } from './getRouteToRender';
17
 import { _getRouteToRender } from './getRouteToRender';
11
 
18
 
12
 MiddlewareRegistry.register(store => next => action => {
19
 MiddlewareRegistry.register(store => next => action => {
13
     switch (action.type) {
20
     switch (action.type) {
14
     case CONNECTION_ESTABLISHED:
21
     case CONNECTION_ESTABLISHED:
15
         return _connectionEstablished(store, next, action);
22
         return _connectionEstablished(store, next, action);
23
+    case CONNECTION_FAILED:
24
+        return _connectionFailed(store, next, action);
16
 
25
 
17
     case SET_ROOM:
26
     case SET_ROOM:
18
         return _setRoom(store, next, action);
27
         return _setRoom(store, next, action);
62
     return result;
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
  * Navigates to a route in accord with a specific redux state.
139
  * Navigates to a route in accord with a specific redux state.
67
  *
140
  *

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

1
 // @flow
1
 // @flow
2
 
2
 
3
-import { reloadNow } from '../../app';
4
 import { openDisplayNamePrompt } from '../../display-name';
3
 import { openDisplayNamePrompt } from '../../display-name';
5
 
4
 
6
 import {
5
 import {
7
     ACTION_PINNED,
6
     ACTION_PINNED,
8
     ACTION_UNPINNED,
7
     ACTION_UNPINNED,
9
-    createConnectionEvent,
10
     createOfferAnswerFailedEvent,
8
     createOfferAnswerFailedEvent,
11
     createPinnedEvent,
9
     createPinnedEvent,
12
     sendAnalytics
10
     sendAnalytics
256
  * @returns {Object} The value returned by {@code next(action)}.
254
  * @returns {Object} The value returned by {@code next(action)}.
257
  */
255
  */
258
 function _connectionFailed({ dispatch, getState }, next, action) {
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
     const result = next(action);
257
     const result = next(action);
268
 
258
 
269
     if (typeof beforeUnloadHandler !== 'undefined') {
259
     if (typeof beforeUnloadHandler !== 'undefined') {
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
  * Notifies the feature base/conference that the action {@code PIN_PARTICIPANT}
349
  * Notifies the feature base/conference that the action {@code PIN_PARTICIPANT}
406
  * is being dispatched within a specific redux store. Pins the specified remote
350
  * is being dispatched within a specific redux store. Pins the specified remote

正在加载...
取消
保存