|
@@ -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
|
*
|