@ -4,9 +4,11 @@ import {
} from '../lib-jitsi-meet' ;
import {
AUDIO _MUTED _CHANGED ,
audioMutedChanged ,
CAMERA _FACING _MODE _CHANGED ,
MEDIA _TYPE ,
VIDEO _MUTED _CHANGED
VIDEO _MUTED _CHANGED ,
videoMutedChanged
} from '../media' ;
import { MiddlewareRegistry } from '../redux' ;
@ -14,6 +16,7 @@ import {
createLocalTracks ,
destroyLocalTracks
} from './actions' ;
import { TRACK _UPDATED } from './actionTypes' ;
import {
getLocalTrack ,
setTrackMuted
@ -50,6 +53,9 @@ MiddlewareRegistry.register(store => next => action => {
store . dispatch ( destroyLocalTracks ( ) ) ;
break ;
case TRACK _UPDATED :
return _trackUpdated ( store , next , action ) ;
case VIDEO _MUTED _CHANGED :
_mutedChanged ( store , action , MEDIA _TYPE . VIDEO ) ;
break ;
@ -58,6 +64,22 @@ MiddlewareRegistry.register(store => next => action => {
return next ( action ) ;
} ) ;
/ * *
* Gets the local track associated with a specific < tt > MEDIA _TYPE < / t t > i n a
* specific Redux store .
*
* @ param { Store } store - The Redux store from which the local track associated
* with the specified < tt > mediaType < / t t > i s t o b e r e t r i e v e d .
* @ param { MEDIA _TYPE } mediaType - The < tt > MEDIA _TYPE < / t t > o f t h e l o c a l t r a c k t o
* be retrieved from the specified < tt > store < / t t > .
* @ private
* @ returns { Track } The local < tt > Track < / t t > a s s o c i a t e d w i t h t h e s p e c i f i e d
* < tt > mediaType < / t t > i n t h e s p e c i f i e d < t t > s t o r e < / t t > .
* /
function _getLocalTrack ( store , mediaType ) {
return getLocalTrack ( store . getState ( ) [ 'features/base/tracks' ] , mediaType ) ;
}
/ * *
* Mutes or unmutes a local track with a specific media type .
*
@ -70,8 +92,67 @@ MiddlewareRegistry.register(store => next => action => {
* @ returns { void }
* /
function _mutedChanged ( store , action , mediaType ) {
const tracks = store . getState ( ) [ 'features/base/tracks' ] ;
const localTrack = getLocalTrack ( tracks , mediaType ) ;
const localTrack = _getLocalTrack ( store , mediaType ) ;
localTrack && setTrackMuted ( localTrack . jitsiTrack , action . muted ) ;
}
/ * *
* Intercepts the action < tt > TRACK _UPDATED < / t t > i n o r d e r t o s y n c h r o n i z e t h e
* 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 < tt > action < / t t >
* is being dispatched .
* @ param { Dispatch } next - The Redux dispatch function to dispatch the
* specified < tt > action < / t t > t o t h e s p e c i f i e d < t t > s t o r e < / t t > .
* @ param { Action } action - The Redux action < tt > TRACK _UPDATED < / t t > w h i c h i s
* being dispatched in the specified < tt > store < / t t > .
* @ private
* @ returns { void }
* /
function _trackUpdated ( store , next , action ) {
// Determine the muted state of the local track before the update.
const track = action . track ;
let mediaType ;
let oldMuted ;
if ( 'muted' in track ) {
// XXX The return value of JitsiTrack.getType() is of type MEDIA_TYPE
// that happens to be compatible with the type MEDIA_TYPE defined by
// jitsi-meet-react.
mediaType = track . jitsiTrack . getType ( ) ;
const localTrack = _getLocalTrack ( store , mediaType ) ;
if ( localTrack ) {
oldMuted = localTrack . muted ;
}
}
const result = next ( action ) ;
if ( typeof oldMuted !== 'undefined' ) {
// Determine the muted state of the local track after the update. If the
// muted states before and after the update differ, then the respective
// media state should by synchronized.
const localTrack = _getLocalTrack ( store , mediaType ) ;
if ( localTrack ) {
const newMuted = localTrack . muted ;
if ( oldMuted !== newMuted ) {
switch ( mediaType ) {
case MEDIA _TYPE . AUDIO :
store . dispatch ( audioMutedChanged ( newMuted ) ) ;
break ;
case MEDIA _TYPE . VIDEO :
store . dispatch ( videoMutedChanged ( newMuted ) ) ;
break ;
}
}
}
}
return result ;
}