Coding style
This commit is contained in:
parent
c0de88ba8c
commit
90e7804834
|
@ -3,7 +3,8 @@
|
||||||
import {
|
import {
|
||||||
MEDIA_TYPE,
|
MEDIA_TYPE,
|
||||||
SET_AUDIO_AVAILABLE,
|
SET_AUDIO_AVAILABLE,
|
||||||
SET_VIDEO_AVAILABLE } from '../base/media';
|
SET_VIDEO_AVAILABLE
|
||||||
|
} from '../base/media';
|
||||||
import { MiddlewareRegistry } from '../base/redux';
|
import { MiddlewareRegistry } from '../base/redux';
|
||||||
import { isLocalTrackMuted, TRACK_UPDATED } from '../base/tracks';
|
import { isLocalTrackMuted, TRACK_UPDATED } from '../base/tracks';
|
||||||
|
|
||||||
|
@ -26,6 +27,9 @@ MiddlewareRegistry.register(store => next => action => {
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
case SET_AUDIO_AVAILABLE:
|
||||||
|
return _setMediaAvailableOrMuted(store, next, action);
|
||||||
|
|
||||||
case SET_TOOLBOX_TIMEOUT: {
|
case SET_TOOLBOX_TIMEOUT: {
|
||||||
const { timeoutID } = store.getState()['features/toolbox'];
|
const { timeoutID } = store.getState()['features/toolbox'];
|
||||||
const { handler, timeoutMS } = action;
|
const { handler, timeoutMS } = action;
|
||||||
|
@ -37,35 +41,27 @@ MiddlewareRegistry.register(store => next => action => {
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
case SET_AUDIO_AVAILABLE: {
|
case SET_VIDEO_AVAILABLE:
|
||||||
return _setMediaAvailableOrMuted(store, next, action);
|
return _setMediaAvailableOrMuted(store, next, action);
|
||||||
}
|
|
||||||
|
|
||||||
case SET_VIDEO_AVAILABLE: {
|
case TRACK_UPDATED:
|
||||||
return _setMediaAvailableOrMuted(store, next, action);
|
|
||||||
}
|
|
||||||
|
|
||||||
case TRACK_UPDATED: {
|
|
||||||
if (action.track.jitsiTrack.isLocal()) {
|
if (action.track.jitsiTrack.isLocal()) {
|
||||||
return _setMediaAvailableOrMuted(store, next, action);
|
return _setMediaAvailableOrMuted(store, next, action);
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
return next(action);
|
return next(action);
|
||||||
});
|
});
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Adjusts the state of toolbar's microphone or camera button.
|
* Adjusts the state of toolbar's microphone or camera button.
|
||||||
*
|
*
|
||||||
* @param {Store} store - The Redux store instance.
|
* @param {Store} store - The redux store.
|
||||||
* @param {Function} next - The redux function to continue dispatching the
|
* @param {Function} next - The redux function to continue dispatching the
|
||||||
* specified {@code action} in the specified {@code store}.
|
* specified {@code action} in the specified {@code store}.
|
||||||
* @param {Object} action - SET_AUDIO_AVAILABLE, SET_VIDEO_AVAILABLE or
|
* @param {Object} action - <tt>SET_AUDIO_AVAILABLE</tt>,
|
||||||
* TRACK_UPDATED.
|
* <tt>SET_VIDEO_AVAILABLE</tt>, or <tt>TRACK_UPDATED</tt>.
|
||||||
*
|
|
||||||
* @returns {*}
|
* @returns {*}
|
||||||
*/
|
*/
|
||||||
function _setMediaAvailableOrMuted({ dispatch, getState }, next, action) {
|
function _setMediaAvailableOrMuted({ dispatch, getState }, next, action) {
|
||||||
|
@ -74,43 +70,39 @@ function _setMediaAvailableOrMuted({ dispatch, getState }, next, action) {
|
||||||
let mediaType;
|
let mediaType;
|
||||||
|
|
||||||
switch (action.type) {
|
switch (action.type) {
|
||||||
case SET_AUDIO_AVAILABLE: {
|
case SET_AUDIO_AVAILABLE:
|
||||||
mediaType = MEDIA_TYPE.AUDIO;
|
mediaType = MEDIA_TYPE.AUDIO;
|
||||||
break;
|
break;
|
||||||
}
|
|
||||||
|
|
||||||
case SET_VIDEO_AVAILABLE: {
|
case SET_VIDEO_AVAILABLE:
|
||||||
mediaType = MEDIA_TYPE.VIDEO;
|
mediaType = MEDIA_TYPE.VIDEO;
|
||||||
break;
|
break;
|
||||||
}
|
|
||||||
|
|
||||||
case TRACK_UPDATED: {
|
case TRACK_UPDATED:
|
||||||
mediaType
|
mediaType
|
||||||
= action.track.jitsiTrack.isAudioTrack()
|
= action.track.jitsiTrack.isAudioTrack()
|
||||||
? MEDIA_TYPE.AUDIO : MEDIA_TYPE.VIDEO;
|
? MEDIA_TYPE.AUDIO
|
||||||
|
: MEDIA_TYPE.VIDEO;
|
||||||
break;
|
break;
|
||||||
}
|
|
||||||
|
|
||||||
default: {
|
default:
|
||||||
throw new Error(`Unsupported action ${action}`);
|
throw new Error(`Unsupported action ${action}`);
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
const state = getState();
|
||||||
|
const { audio, video } = state['features/base/media'];
|
||||||
const mediaState = getState()['features/base/media'];
|
const { available } = mediaType === MEDIA_TYPE.AUDIO ? audio : video;
|
||||||
const { available }
|
|
||||||
= mediaType === MEDIA_TYPE.AUDIO
|
|
||||||
? mediaState.audio : mediaState.video;
|
|
||||||
const i18nKey
|
const i18nKey
|
||||||
= mediaType === MEDIA_TYPE.AUDIO
|
= mediaType === MEDIA_TYPE.AUDIO
|
||||||
? available ? 'mute' : 'micDisabled'
|
? available ? 'mute' : 'micDisabled'
|
||||||
: available ? 'videomute' : 'cameraDisabled';
|
: available ? 'videomute' : 'cameraDisabled';
|
||||||
|
const tracks = state['features/base/tracks'];
|
||||||
const tracks = getState()['features/base/tracks'];
|
|
||||||
const muted = isLocalTrackMuted(tracks, mediaType);
|
const muted = isLocalTrackMuted(tracks, mediaType);
|
||||||
|
|
||||||
dispatch(setToolbarButton(
|
dispatch(
|
||||||
mediaType === MEDIA_TYPE.AUDIO ? 'microphone' : 'camera', {
|
setToolbarButton(
|
||||||
|
mediaType === MEDIA_TYPE.AUDIO ? 'microphone' : 'camera',
|
||||||
|
{
|
||||||
enabled: available,
|
enabled: available,
|
||||||
i18n: `[content]toolbar.${i18nKey}`,
|
i18n: `[content]toolbar.${i18nKey}`,
|
||||||
toggled: available ? muted : true
|
toggled: available ? muted : true
|
||||||
|
|
Loading…
Reference in New Issue