diff --git a/react/features/base/media/middleware.js b/react/features/base/media/middleware.js index 2bfa2c1c4..4d7b907b2 100644 --- a/react/features/base/media/middleware.js +++ b/react/features/base/media/middleware.js @@ -93,8 +93,8 @@ function _setRoom({ dispatch, getState }, next, action) { * @private * @returns {void} */ -function _syncTrackMutedState(store, track) { - const state = store.getState()['features/base/media']; +function _syncTrackMutedState({ dispatch, getState }, track) { + const state = getState()['features/base/media']; const muted = state[track.mediaType].muted; // XXX If muted state of track when it was added is different from our media @@ -104,6 +104,6 @@ function _syncTrackMutedState(store, track) { // fired before track gets to state. if (track.muted !== muted) { track.muted = muted; - setTrackMuted(track.jitsiTrack, muted, store); + dispatch(setTrackMuted(track.jitsiTrack, muted)); } } diff --git a/react/features/base/tracks/actions.js b/react/features/base/tracks/actions.js index abe032427..c24c71179 100644 --- a/react/features/base/tracks/actions.js +++ b/react/features/base/tracks/actions.js @@ -344,6 +344,39 @@ function _getLocalTracksToChange(currentTracks, newTracks) { }; } +/** + * Mutes or unmutes a specific JitsiLocalTrack. If the muted state of + * the specified track is already in accord with the specified + * muted value, then does nothing. In case the actual muting/unmuting + * fails, a rollback action will be dispatched to undo the muting/unmuting. + * + * @param {JitsiLocalTrack} track - The JitsiLocalTrack to mute or + * unmute. + * @param {boolean} muted - If the specified track is to be muted, then + * true; otherwise, false. + * @returns {Function} + */ +export function setTrackMuted(track, muted) { + return dispatch => { + if (track.isMuted() === muted) { + return Promise.resolve(); + } + + const f = muted ? 'mute' : 'unmute'; + + return track[f]().catch(error => { + console.error(`set track ${f} failed`, error); + + const setMuted + = track.mediaType === MEDIA_TYPE.AUDIO + ? setAudioMuted + : setVideoMuted; + + dispatch(setMuted(!muted)); + }); + }; +} + /** * Returns true if the provided JitsiTrack should be rendered as a mirror. * diff --git a/react/features/base/tracks/functions.js b/react/features/base/tracks/functions.js index 2ebcd7136..1741db4a8 100644 --- a/react/features/base/tracks/functions.js +++ b/react/features/base/tracks/functions.js @@ -1,7 +1,7 @@ /* global APP */ import JitsiMeetJS, { JitsiTrackEvents } from '../lib-jitsi-meet'; -import { MEDIA_TYPE, setAudioMuted, setVideoMuted } from '../media'; +import { MEDIA_TYPE } from '../media'; const logger = require('jitsi-meet-logger').getLogger(__filename); @@ -155,39 +155,3 @@ export function getTrackByJitsiTrack(tracks, jitsiTrack) { export function getTracksByMediaType(tracks, mediaType) { return tracks.filter(t => t.mediaType === mediaType); } - -/** - * Mutes or unmutes a specific JitsiLocalTrack. If the muted state of - * the specified track is already in accord with the specified - * muted value, then does nothing. In case mute/unmute operation fails - * (JitsiLocalTrack Promise is rejected) a rollback action will be dispatched on - * the given store. For example if the mute operation fails then the 'unmute' - * action will be dispatched to rollback to the previous state in base/media. - * - * @param {JitsiLocalTrack} track - The JitsiLocalTrack to mute or - * unmute. - * @param {boolean} muted - If the specified track is to be muted, then - * true; otherwise, false. - * @param {Store} store - The redux store in the context of which the function - * is to execute and which will be used to dispatch the rollback action in case - * mute/unmute fails. -* @returns {Promise} - */ -export function setTrackMuted(track, muted, { dispatch }) { - if (track.isMuted() === muted) { - return Promise.resolve(); - } - - const f = muted ? 'mute' : 'unmute'; - - return track[f]().catch(error => { - console.error(`set track ${f} failed`, error); - - const setMuted - = track.mediaType === MEDIA_TYPE.AUDIO - ? setAudioMuted - : setVideoMuted; - - dispatch(setMuted(!muted)); - }); -} diff --git a/react/features/base/tracks/middleware.js b/react/features/base/tracks/middleware.js index b61b0f736..0f4660657 100644 --- a/react/features/base/tracks/middleware.js +++ b/react/features/base/tracks/middleware.js @@ -13,8 +13,9 @@ import { } from '../media'; import { MiddlewareRegistry } from '../redux'; +import { setTrackMuted } from './actions'; import { TRACK_ADDED, TRACK_REMOVED, TRACK_UPDATED } from './actionTypes'; -import { getLocalTrack, setTrackMuted } from './functions'; +import { getLocalTrack } from './functions'; declare var APP: Object; @@ -23,7 +24,7 @@ declare var APP: Object; * respectively, creates/destroys local media tracks. Also listens to * media-related actions and performs corresponding operations with tracks. * - * @param {Store} store - Redux store. + * @param {Store} store - The redux store. * @returns {Function} */ MiddlewareRegistry.register(store => next => action => { @@ -132,9 +133,9 @@ MiddlewareRegistry.register(store => next => action => { /** * Gets the local track associated with a specific MEDIA_TYPE in a - * specific Redux store. + * specific redux store. * - * @param {Store} store - The Redux store from which the local track associated + * @param {Store} store - The redux store from which the local track associated * with the specified mediaType is to be retrieved. * @param {MEDIA_TYPE} mediaType - The MEDIA_TYPE of the local track to * be retrieved from the specified store. @@ -149,20 +150,18 @@ function _getLocalTrack(store, mediaType: MEDIA_TYPE) { /** * Mutes or unmutes a local track with a specific media type. * - * @param {Store} store - The Redux store in which the specified action is + * @param {Store} store - The redux store in which the specified action is * dispatched. - * @param {Action} action - The Redux action dispatched in the specified store. + * @param {Action} action - The redux action dispatched in the specified store. * @param {MEDIA_TYPE} mediaType - The {@link MEDIA_TYPE} of the local track * which is being muted or unmuted. * @private * @returns {void} */ -function _setMuted(store, action, mediaType: MEDIA_TYPE) { +function _setMuted(store, { muted }, mediaType: MEDIA_TYPE) { const localTrack = _getLocalTrack(store, mediaType); - if (localTrack) { - setTrackMuted(localTrack.jitsiTrack, action.muted, store); - } + localTrack && store.dispatch(setTrackMuted(localTrack.jitsiTrack, muted)); } /** @@ -170,11 +169,11 @@ function _setMuted(store, action, mediaType: MEDIA_TYPE) { * muted states of the local tracks of features/base/tracks with the muted * states of features/base/media. * - * @param {Store} store - The Redux store in which the specified action + * @param {Store} store - The redux store in which the specified action * is being dispatched. - * @param {Dispatch} next - The Redux dispatch function to dispatch the + * @param {Dispatch} next - The redux dispatch function to dispatch the * specified action to the specified store. - * @param {Action} action - The Redux action TRACK_UPDATED which is + * @param {Action} action - The redux action TRACK_UPDATED which is * being dispatched in the specified store. * @private * @returns {Object} The new state that is the result of the reduction of the