|
|
@@ -4,9 +4,11 @@ import {
|
|
4
|
4
|
} from '../lib-jitsi-meet';
|
|
5
|
5
|
import {
|
|
6
|
6
|
AUDIO_MUTED_CHANGED,
|
|
|
7
|
+ audioMutedChanged,
|
|
7
|
8
|
CAMERA_FACING_MODE_CHANGED,
|
|
8
|
9
|
MEDIA_TYPE,
|
|
9
|
|
- VIDEO_MUTED_CHANGED
|
|
|
10
|
+ VIDEO_MUTED_CHANGED,
|
|
|
11
|
+ videoMutedChanged
|
|
10
|
12
|
} from '../media';
|
|
11
|
13
|
import { MiddlewareRegistry } from '../redux';
|
|
12
|
14
|
|
|
|
@@ -14,6 +16,7 @@ import {
|
|
14
|
16
|
createLocalTracks,
|
|
15
|
17
|
destroyLocalTracks
|
|
16
|
18
|
} from './actions';
|
|
|
19
|
+import { TRACK_UPDATED } from './actionTypes';
|
|
17
|
20
|
import {
|
|
18
|
21
|
getLocalTrack,
|
|
19
|
22
|
setTrackMuted
|
|
|
@@ -50,6 +53,9 @@ MiddlewareRegistry.register(store => next => action => {
|
|
50
|
53
|
store.dispatch(destroyLocalTracks());
|
|
51
|
54
|
break;
|
|
52
|
55
|
|
|
|
56
|
+ case TRACK_UPDATED:
|
|
|
57
|
+ return _trackUpdated(store, next, action);
|
|
|
58
|
+
|
|
53
|
59
|
case VIDEO_MUTED_CHANGED:
|
|
54
|
60
|
_mutedChanged(store, action, MEDIA_TYPE.VIDEO);
|
|
55
|
61
|
break;
|
|
|
@@ -58,6 +64,22 @@ MiddlewareRegistry.register(store => next => action => {
|
|
58
|
64
|
return next(action);
|
|
59
|
65
|
});
|
|
60
|
66
|
|
|
|
67
|
+/**
|
|
|
68
|
+ * Gets the local track associated with a specific <tt>MEDIA_TYPE</tt> in a
|
|
|
69
|
+ * specific Redux store.
|
|
|
70
|
+ *
|
|
|
71
|
+ * @param {Store} store - The Redux store from which the local track associated
|
|
|
72
|
+ * with the specified <tt>mediaType</tt> is to be retrieved.
|
|
|
73
|
+ * @param {MEDIA_TYPE} mediaType - The <tt>MEDIA_TYPE</tt> of the local track to
|
|
|
74
|
+ * be retrieved from the specified <tt>store</tt>.
|
|
|
75
|
+ * @private
|
|
|
76
|
+ * @returns {Track} The local <tt>Track</tt> associated with the specified
|
|
|
77
|
+ * <tt>mediaType</tt> in the specified <tt>store</tt>.
|
|
|
78
|
+ */
|
|
|
79
|
+function _getLocalTrack(store, mediaType) {
|
|
|
80
|
+ return getLocalTrack(store.getState()['features/base/tracks'], mediaType);
|
|
|
81
|
+}
|
|
|
82
|
+
|
|
61
|
83
|
/**
|
|
62
|
84
|
* Mutes or unmutes a local track with a specific media type.
|
|
63
|
85
|
*
|
|
|
@@ -70,8 +92,67 @@ MiddlewareRegistry.register(store => next => action => {
|
|
70
|
92
|
* @returns {void}
|
|
71
|
93
|
*/
|
|
72
|
94
|
function _mutedChanged(store, action, mediaType) {
|
|
73
|
|
- const tracks = store.getState()['features/base/tracks'];
|
|
74
|
|
- const localTrack = getLocalTrack(tracks, mediaType);
|
|
|
95
|
+ const localTrack = _getLocalTrack(store, mediaType);
|
|
75
|
96
|
|
|
76
|
97
|
localTrack && setTrackMuted(localTrack.jitsiTrack, action.muted);
|
|
77
|
98
|
}
|
|
|
99
|
+
|
|
|
100
|
+/**
|
|
|
101
|
+ * Intercepts the action <tt>TRACK_UPDATED</tt> in order to synchronize the
|
|
|
102
|
+ * muted states of the local tracks of features/base/tracks with the muted
|
|
|
103
|
+ * states of features/base/media.
|
|
|
104
|
+ *
|
|
|
105
|
+ * @param {Store} store - The Redux store in which the specified <tt>action</tt>
|
|
|
106
|
+ * is being dispatched.
|
|
|
107
|
+ * @param {Dispatch} next - The Redux dispatch function to dispatch the
|
|
|
108
|
+ * specified <tt>action</tt> to the specified <tt>store</tt>.
|
|
|
109
|
+ * @param {Action} action - The Redux action <tt>TRACK_UPDATED</tt> which is
|
|
|
110
|
+ * being dispatched in the specified <tt>store</tt>.
|
|
|
111
|
+ * @private
|
|
|
112
|
+ * @returns {void}
|
|
|
113
|
+ */
|
|
|
114
|
+function _trackUpdated(store, next, action) {
|
|
|
115
|
+ // Determine the muted state of the local track before the update.
|
|
|
116
|
+ const track = action.track;
|
|
|
117
|
+ let mediaType;
|
|
|
118
|
+ let oldMuted;
|
|
|
119
|
+
|
|
|
120
|
+ if ('muted' in track) {
|
|
|
121
|
+ // XXX The return value of JitsiTrack.getType() is of type MEDIA_TYPE
|
|
|
122
|
+ // that happens to be compatible with the type MEDIA_TYPE defined by
|
|
|
123
|
+ // jitsi-meet-react.
|
|
|
124
|
+ mediaType = track.jitsiTrack.getType();
|
|
|
125
|
+
|
|
|
126
|
+ const localTrack = _getLocalTrack(store, mediaType);
|
|
|
127
|
+
|
|
|
128
|
+ if (localTrack) {
|
|
|
129
|
+ oldMuted = localTrack.muted;
|
|
|
130
|
+ }
|
|
|
131
|
+ }
|
|
|
132
|
+
|
|
|
133
|
+ const result = next(action);
|
|
|
134
|
+
|
|
|
135
|
+ if (typeof oldMuted !== 'undefined') {
|
|
|
136
|
+ // Determine the muted state of the local track after the update. If the
|
|
|
137
|
+ // muted states before and after the update differ, then the respective
|
|
|
138
|
+ // media state should by synchronized.
|
|
|
139
|
+ const localTrack = _getLocalTrack(store, mediaType);
|
|
|
140
|
+
|
|
|
141
|
+ if (localTrack) {
|
|
|
142
|
+ const newMuted = localTrack.muted;
|
|
|
143
|
+
|
|
|
144
|
+ if (oldMuted !== newMuted) {
|
|
|
145
|
+ switch (mediaType) {
|
|
|
146
|
+ case MEDIA_TYPE.AUDIO:
|
|
|
147
|
+ store.dispatch(audioMutedChanged(newMuted));
|
|
|
148
|
+ break;
|
|
|
149
|
+ case MEDIA_TYPE.VIDEO:
|
|
|
150
|
+ store.dispatch(videoMutedChanged(newMuted));
|
|
|
151
|
+ break;
|
|
|
152
|
+ }
|
|
|
153
|
+ }
|
|
|
154
|
+ }
|
|
|
155
|
+ }
|
|
|
156
|
+
|
|
|
157
|
+ return result;
|
|
|
158
|
+}
|