|
|
@@ -1,7 +1,7 @@
|
|
1
|
1
|
/* global APP */
|
|
2
|
2
|
|
|
3
|
3
|
import JitsiMeetJS, { JitsiTrackEvents } from '../lib-jitsi-meet';
|
|
4
|
|
-import { MEDIA_TYPE } from '../media';
|
|
|
4
|
+import { MEDIA_TYPE, setAudioMuted, setVideoMuted } from '../media';
|
|
5
|
5
|
|
|
6
|
6
|
const logger = require('jitsi-meet-logger').getLogger(__filename);
|
|
7
|
7
|
|
|
|
@@ -159,20 +159,35 @@ export function getTracksByMediaType(tracks, mediaType) {
|
|
159
|
159
|
/**
|
|
160
|
160
|
* Mutes or unmutes a specific <tt>JitsiLocalTrack</tt>. If the muted state of
|
|
161
|
161
|
* the specified <tt>track</tt> is already in accord with the specified
|
|
162
|
|
- * <tt>muted</tt> value, then does nothing.
|
|
|
162
|
+ * <tt>muted</tt> value, then does nothing. In case mute/unmute operation fails
|
|
|
163
|
+ * (JitsiLocalTrack Promise is rejected) a rollback action will be dispatched on
|
|
|
164
|
+ * the given store. For example if the mute operation fails then the 'unmute'
|
|
|
165
|
+ * action will be dispatched to rollback to the previous state in base/media.
|
|
163
|
166
|
*
|
|
164
|
167
|
* @param {JitsiLocalTrack} track - The <tt>JitsiLocalTrack</tt> to mute or
|
|
165
|
168
|
* unmute.
|
|
166
|
169
|
* @param {boolean} muted - If the specified <tt>track</tt> is to be muted, then
|
|
167
|
170
|
* <tt>true</tt>; otherwise, <tt>false</tt>.
|
|
168
|
|
- * @returns {Promise}
|
|
|
171
|
+ * @param {Store} store - The redux store in the context of which the function
|
|
|
172
|
+ * is to execute and which will be used to dispatch the rollback action in case
|
|
|
173
|
+ * mute/unmute fails.
|
|
|
174
|
+* @returns {Promise}
|
|
169
|
175
|
*/
|
|
170
|
|
-export function setTrackMuted(track, muted) {
|
|
|
176
|
+export function setTrackMuted(track, muted, { dispatch }) {
|
|
171
|
177
|
if (track.isMuted() === muted) {
|
|
172
|
178
|
return Promise.resolve();
|
|
173
|
179
|
}
|
|
174
|
180
|
|
|
175
|
181
|
const f = muted ? 'mute' : 'unmute';
|
|
176
|
182
|
|
|
177
|
|
- return track[f]();
|
|
|
183
|
+ return track[f]().catch(error => {
|
|
|
184
|
+ console.error(`set track ${f} failed`, error);
|
|
|
185
|
+
|
|
|
186
|
+ const setMuted
|
|
|
187
|
+ = track.mediaType === MEDIA_TYPE.AUDIO
|
|
|
188
|
+ ? setAudioMuted
|
|
|
189
|
+ : setVideoMuted;
|
|
|
190
|
+
|
|
|
191
|
+ dispatch(setMuted(!muted));
|
|
|
192
|
+ });
|
|
178
|
193
|
}
|