|
@@ -1,59 +1,16 @@
|
1
|
1
|
/* @flow */
|
2
|
2
|
|
|
3
|
+import { SET_VIDEO_AVAILABLE, SET_VIDEO_MUTED } from '../base/media';
|
3
|
4
|
import { MiddlewareRegistry } from '../base/redux';
|
4
|
5
|
|
5
|
|
-import {
|
6
|
|
- CLEAR_TOOLBOX_TIMEOUT,
|
7
|
|
- SET_TOOLBOX_TIMEOUT
|
8
|
|
-} from './actionTypes';
|
9
|
|
-
|
10
|
|
-import {
|
11
|
|
- SET_VIDEO_AVAILABLE,
|
12
|
|
- SET_VIDEO_MUTED
|
13
|
|
-} from '../../features/base/media/actionTypes';
|
14
|
|
-
|
15
|
|
-import {
|
16
|
|
- setToolbarButton
|
17
|
|
-} from './actions';
|
18
|
|
-
|
19
|
|
-/**
|
20
|
|
- * Adjusts the state of toolbar's camera button.
|
21
|
|
- *
|
22
|
|
- * @param {Store} store - The Redux store instance.
|
23
|
|
- * @param {Object} action - Either SET_VIDEO_AVAILABLE or SET_VIDEO_MUTED.
|
24
|
|
- *
|
25
|
|
- * @returns {*}
|
26
|
|
- */
|
27
|
|
-function setCameraButton(store, action) {
|
28
|
|
- const video = store.getState()['features/base/media'].video;
|
29
|
|
- let available = video.available;
|
30
|
|
-
|
31
|
|
- if (typeof action.available === 'boolean') {
|
32
|
|
- available = action.available;
|
33
|
|
- }
|
34
|
|
-
|
35
|
|
- let muted = video.muted;
|
36
|
|
-
|
37
|
|
- if (typeof action.muted === 'boolean') {
|
38
|
|
- muted = action.muted;
|
39
|
|
- }
|
40
|
|
-
|
41
|
|
- const i18nKey = available ? 'videomute' : 'cameraDisabled';
|
42
|
|
- const i18n = `[content]toolbar.${i18nKey}`;
|
43
|
|
- const button = {
|
44
|
|
- enabled: available,
|
45
|
|
- i18n,
|
46
|
|
- toggled: available ? muted : true
|
47
|
|
- };
|
48
|
|
-
|
49
|
|
- store.dispatch(setToolbarButton('camera', button));
|
50
|
|
-}
|
|
6
|
+import { setToolbarButton } from './actions';
|
|
7
|
+import { CLEAR_TOOLBOX_TIMEOUT, SET_TOOLBOX_TIMEOUT } from './actionTypes';
|
51
|
8
|
|
52
|
9
|
/**
|
53
|
10
|
* Middleware which intercepts Toolbox actions to handle changes to the
|
54
|
11
|
* visibility timeout of the Toolbox.
|
55
|
12
|
*
|
56
|
|
- * @param {Store} store - Redux store.
|
|
13
|
+ * @param {Store} store - The redux store.
|
57
|
14
|
* @returns {Function}
|
58
|
15
|
*/
|
59
|
16
|
MiddlewareRegistry.register(store => next => action => {
|
|
@@ -77,13 +34,35 @@ MiddlewareRegistry.register(store => next => action => {
|
77
|
34
|
}
|
78
|
35
|
|
79
|
36
|
case SET_VIDEO_AVAILABLE:
|
80
|
|
- case SET_VIDEO_MUTED: {
|
81
|
|
- setCameraButton(store, action);
|
82
|
|
- break;
|
83
|
|
- }
|
84
|
|
-
|
85
|
|
-
|
|
37
|
+ case SET_VIDEO_MUTED:
|
|
38
|
+ return _setVideoAvailableOrMuted(store, next, action);
|
86
|
39
|
}
|
87
|
40
|
|
88
|
41
|
return next(action);
|
89
|
42
|
});
|
|
43
|
+
|
|
44
|
+/**
|
|
45
|
+ * Adjusts the state of toolbar's camera button.
|
|
46
|
+ *
|
|
47
|
+ * @param {Store} store - The redux store.
|
|
48
|
+ * @param {Function} next - The redux function to continue dispatching the
|
|
49
|
+ * specified {@code action} in the specified {@code store}.
|
|
50
|
+ * @param {Object} action - Either {@link SET_VIDEO_AVAILABLE} or
|
|
51
|
+ * {@link SET_VIDEO_MUTED}.
|
|
52
|
+ * @returns {Object} The new state that is the result of the reduction of the
|
|
53
|
+ * specified {@code action}.
|
|
54
|
+ */
|
|
55
|
+function _setVideoAvailableOrMuted({ dispatch, getState }, next, action) {
|
|
56
|
+ const result = next(action);
|
|
57
|
+
|
|
58
|
+ const { available, muted } = getState()['features/base/media'].video;
|
|
59
|
+ const i18nKey = available ? 'videomute' : 'cameraDisabled';
|
|
60
|
+
|
|
61
|
+ dispatch(setToolbarButton('camera', {
|
|
62
|
+ enabled: available,
|
|
63
|
+ i18n: `[content]toolbar.${i18nKey}`,
|
|
64
|
+ toggled: available ? muted : true
|
|
65
|
+ }));
|
|
66
|
+
|
|
67
|
+ return result;
|
|
68
|
+}
|