Name Redux actions consistently
Redux actions which represent "commands" should be imperative, and those representing events should use the past tense.
This commit is contained in:
parent
7ec5b34548
commit
e71e6c5b79
|
@ -1,31 +1,31 @@
|
||||||
import { Symbol } from '../react';
|
import { Symbol } from '../react';
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Action to change muted state of the local audio.
|
* Action to change the muted state of the local audio.
|
||||||
*
|
*
|
||||||
* {
|
* {
|
||||||
* type: AUDIO_MUTED_CHANGED,
|
* type: SET_AUDIO_MUTED,
|
||||||
* muted: boolean
|
* muted: boolean
|
||||||
* }
|
* }
|
||||||
*/
|
*/
|
||||||
export const AUDIO_MUTED_CHANGED = Symbol('AUDIO_MUTED_CHANGED');
|
export const SET_AUDIO_MUTED = Symbol('SET_AUDIO_MUTED');
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Action to signal a change of the facing mode of the local video camera.
|
* Action to change the facing mode of the local video camera.
|
||||||
*
|
*
|
||||||
* {
|
* {
|
||||||
* type: CAMERA_FACING_MODE_CHANGED,
|
* type: SET_CAMERA_FACING_MODE,
|
||||||
* cameraFacingMode: CAMERA_FACING_MODE
|
* cameraFacingMode: CAMERA_FACING_MODE
|
||||||
* }
|
* }
|
||||||
*/
|
*/
|
||||||
export const CAMERA_FACING_MODE_CHANGED = Symbol('CAMERA_FACING_MODE_CHANGED');
|
export const SET_CAMERA_FACING_MODE = Symbol('SET_CAMERA_FACING_MODE');
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Action to change muted state of the local video.
|
* Action to change the muted state of the local video.
|
||||||
*
|
*
|
||||||
* {
|
* {
|
||||||
* type: VIDEO_MUTED_CHANGED,
|
* type: SET_VIDEO_MUTED,
|
||||||
* muted: boolean
|
* muted: boolean
|
||||||
* }
|
* }
|
||||||
*/
|
*/
|
||||||
export const VIDEO_MUTED_CHANGED = Symbol('VIDEO_MUTED_CHANGED');
|
export const SET_VIDEO_MUTED = Symbol('SET_VIDEO_MUTED');
|
||||||
|
|
|
@ -1,40 +1,40 @@
|
||||||
import {
|
import {
|
||||||
AUDIO_MUTED_CHANGED,
|
SET_AUDIO_MUTED,
|
||||||
CAMERA_FACING_MODE_CHANGED,
|
SET_CAMERA_FACING_MODE,
|
||||||
VIDEO_MUTED_CHANGED
|
SET_VIDEO_MUTED
|
||||||
} from './actionTypes';
|
} from './actionTypes';
|
||||||
import { CAMERA_FACING_MODE } from './constants';
|
import { CAMERA_FACING_MODE } from './constants';
|
||||||
import './middleware';
|
import './middleware';
|
||||||
import './reducer';
|
import './reducer';
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Action to signal the change in local audio muted state.
|
* Action to change the local audio muted state.
|
||||||
*
|
*
|
||||||
* @param {boolean} muted - If local audio is muted.
|
* @param {boolean} muted - If local audio is muted.
|
||||||
* @returns {{
|
* @returns {{
|
||||||
* type: AUDIO_MUTED_CHANGED,
|
* type: SET_AUDIO_MUTED,
|
||||||
* muted: boolean
|
* muted: boolean
|
||||||
* }}
|
* }}
|
||||||
*/
|
*/
|
||||||
export function audioMutedChanged(muted) {
|
export function setAudioMuted(muted) {
|
||||||
return {
|
return {
|
||||||
type: AUDIO_MUTED_CHANGED,
|
type: SET_AUDIO_MUTED,
|
||||||
muted
|
muted
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Action to signal the change in facing mode of local video camera.
|
* Action to change the facing mode of the local video camera.
|
||||||
*
|
*
|
||||||
* @param {CAMERA_FACING_MODE} cameraFacingMode - Camera facing mode.
|
* @param {CAMERA_FACING_MODE} cameraFacingMode - Camera facing mode.
|
||||||
* @returns {{
|
* @returns {{
|
||||||
* type: CAMERA_FACING_MODE_CHANGED,
|
* type: SET_CAMERA_FACING_MODE,
|
||||||
* cameraFacingMode: CAMERA_FACING_MODE
|
* cameraFacingMode: CAMERA_FACING_MODE
|
||||||
* }}
|
* }}
|
||||||
*/
|
*/
|
||||||
export function cameraFacingModeChanged(cameraFacingMode) {
|
export function setCameraFacingMode(cameraFacingMode) {
|
||||||
return {
|
return {
|
||||||
type: CAMERA_FACING_MODE_CHANGED,
|
type: SET_CAMERA_FACING_MODE,
|
||||||
cameraFacingMode
|
cameraFacingMode
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
@ -48,7 +48,7 @@ export function toggleAudioMuted() {
|
||||||
return (dispatch, getState) => {
|
return (dispatch, getState) => {
|
||||||
const muted = getState()['features/base/media'].audio.muted;
|
const muted = getState()['features/base/media'].audio.muted;
|
||||||
|
|
||||||
return dispatch(audioMutedChanged(!muted));
|
return dispatch(setAudioMuted(!muted));
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -67,7 +67,7 @@ export function toggleCameraFacingMode() {
|
||||||
? CAMERA_FACING_MODE.ENVIRONMENT
|
? CAMERA_FACING_MODE.ENVIRONMENT
|
||||||
: CAMERA_FACING_MODE.USER;
|
: CAMERA_FACING_MODE.USER;
|
||||||
|
|
||||||
return dispatch(cameraFacingModeChanged(cameraFacingMode));
|
return dispatch(setCameraFacingMode(cameraFacingMode));
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -80,22 +80,22 @@ export function toggleVideoMuted() {
|
||||||
return (dispatch, getState) => {
|
return (dispatch, getState) => {
|
||||||
const muted = getState()['features/base/media'].video.muted;
|
const muted = getState()['features/base/media'].video.muted;
|
||||||
|
|
||||||
return dispatch(videoMutedChanged(!muted));
|
return dispatch(setVideoMuted(!muted));
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Action to signal the change in local video muted state.
|
* Action to change the local video muted state.
|
||||||
*
|
*
|
||||||
* @param {boolean} muted - If local video is muted.
|
* @param {boolean} muted - If local video is muted.
|
||||||
* @returns {{
|
* @returns {{
|
||||||
* type: VIDEO_MUTED_CHANGED,
|
* type: SET_VIDEO_MUTED,
|
||||||
* muted: boolean
|
* muted: boolean
|
||||||
* }}
|
* }}
|
||||||
*/
|
*/
|
||||||
export function videoMutedChanged(muted) {
|
export function setVideoMuted(muted) {
|
||||||
return {
|
return {
|
||||||
type: VIDEO_MUTED_CHANGED,
|
type: SET_VIDEO_MUTED,
|
||||||
muted
|
muted
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
|
@ -3,9 +3,9 @@ import { MiddlewareRegistry } from '../redux';
|
||||||
import { setTrackMuted, TRACK_ADDED } from '../tracks';
|
import { setTrackMuted, TRACK_ADDED } from '../tracks';
|
||||||
|
|
||||||
import {
|
import {
|
||||||
audioMutedChanged,
|
setAudioMuted,
|
||||||
cameraFacingModeChanged,
|
setCameraFacingMode,
|
||||||
videoMutedChanged
|
setVideoMuted
|
||||||
} from './actions';
|
} from './actions';
|
||||||
import { CAMERA_FACING_MODE } from './constants';
|
import { CAMERA_FACING_MODE } from './constants';
|
||||||
|
|
||||||
|
@ -42,10 +42,10 @@ function resetInitialMediaState(store) {
|
||||||
const { dispatch, getState } = store;
|
const { dispatch, getState } = store;
|
||||||
const state = getState()['features/base/media'];
|
const state = getState()['features/base/media'];
|
||||||
|
|
||||||
state.audio.muted && dispatch(audioMutedChanged(false));
|
state.audio.muted && dispatch(setAudioMuted(false));
|
||||||
(state.video.facingMode !== CAMERA_FACING_MODE.USER)
|
(state.video.facingMode !== CAMERA_FACING_MODE.USER)
|
||||||
&& dispatch(cameraFacingModeChanged(CAMERA_FACING_MODE.USER));
|
&& dispatch(setCameraFacingMode(CAMERA_FACING_MODE.USER));
|
||||||
state.video.muted && dispatch(videoMutedChanged(false));
|
state.video.muted && dispatch(setVideoMuted(false));
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
|
@ -3,9 +3,9 @@ import { combineReducers } from 'redux';
|
||||||
import { ReducerRegistry } from '../redux';
|
import { ReducerRegistry } from '../redux';
|
||||||
|
|
||||||
import {
|
import {
|
||||||
AUDIO_MUTED_CHANGED,
|
SET_AUDIO_MUTED,
|
||||||
CAMERA_FACING_MODE_CHANGED,
|
SET_CAMERA_FACING_MODE,
|
||||||
VIDEO_MUTED_CHANGED
|
SET_VIDEO_MUTED
|
||||||
} from './actionTypes';
|
} from './actionTypes';
|
||||||
import { CAMERA_FACING_MODE } from './constants';
|
import { CAMERA_FACING_MODE } from './constants';
|
||||||
|
|
||||||
|
@ -35,7 +35,7 @@ const AUDIO_INITIAL_MEDIA_STATE = {
|
||||||
*/
|
*/
|
||||||
function audio(state = AUDIO_INITIAL_MEDIA_STATE, action) {
|
function audio(state = AUDIO_INITIAL_MEDIA_STATE, action) {
|
||||||
switch (action.type) {
|
switch (action.type) {
|
||||||
case AUDIO_MUTED_CHANGED:
|
case SET_AUDIO_MUTED:
|
||||||
return {
|
return {
|
||||||
...state,
|
...state,
|
||||||
muted: action.muted
|
muted: action.muted
|
||||||
|
@ -74,13 +74,13 @@ const VIDEO_INITIAL_MEDIA_STATE = {
|
||||||
*/
|
*/
|
||||||
function video(state = VIDEO_INITIAL_MEDIA_STATE, action) {
|
function video(state = VIDEO_INITIAL_MEDIA_STATE, action) {
|
||||||
switch (action.type) {
|
switch (action.type) {
|
||||||
case CAMERA_FACING_MODE_CHANGED:
|
case SET_CAMERA_FACING_MODE:
|
||||||
return {
|
return {
|
||||||
...state,
|
...state,
|
||||||
facingMode: action.cameraFacingMode
|
facingMode: action.cameraFacingMode
|
||||||
};
|
};
|
||||||
|
|
||||||
case VIDEO_MUTED_CHANGED:
|
case SET_VIDEO_MUTED:
|
||||||
return {
|
return {
|
||||||
...state,
|
...state,
|
||||||
muted: action.muted
|
muted: action.muted
|
||||||
|
|
|
@ -3,12 +3,12 @@ import {
|
||||||
LIB_INITIALIZED
|
LIB_INITIALIZED
|
||||||
} from '../lib-jitsi-meet';
|
} from '../lib-jitsi-meet';
|
||||||
import {
|
import {
|
||||||
AUDIO_MUTED_CHANGED,
|
|
||||||
audioMutedChanged,
|
|
||||||
CAMERA_FACING_MODE_CHANGED,
|
|
||||||
MEDIA_TYPE,
|
MEDIA_TYPE,
|
||||||
VIDEO_MUTED_CHANGED,
|
SET_AUDIO_MUTED,
|
||||||
videoMutedChanged
|
SET_CAMERA_FACING_MODE,
|
||||||
|
SET_VIDEO_MUTED,
|
||||||
|
setAudioMuted,
|
||||||
|
setVideoMuted
|
||||||
} from '../media';
|
} from '../media';
|
||||||
import { MiddlewareRegistry } from '../redux';
|
import { MiddlewareRegistry } from '../redux';
|
||||||
|
|
||||||
|
@ -32,11 +32,11 @@ import {
|
||||||
*/
|
*/
|
||||||
MiddlewareRegistry.register(store => next => action => {
|
MiddlewareRegistry.register(store => next => action => {
|
||||||
switch (action.type) {
|
switch (action.type) {
|
||||||
case AUDIO_MUTED_CHANGED:
|
case SET_AUDIO_MUTED:
|
||||||
_mutedChanged(store, action, MEDIA_TYPE.AUDIO);
|
_setMuted(store, action, MEDIA_TYPE.AUDIO);
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case CAMERA_FACING_MODE_CHANGED:
|
case SET_CAMERA_FACING_MODE:
|
||||||
store.dispatch(
|
store.dispatch(
|
||||||
createLocalTracks({
|
createLocalTracks({
|
||||||
devices: [ MEDIA_TYPE.VIDEO ],
|
devices: [ MEDIA_TYPE.VIDEO ],
|
||||||
|
@ -56,8 +56,8 @@ MiddlewareRegistry.register(store => next => action => {
|
||||||
case TRACK_UPDATED:
|
case TRACK_UPDATED:
|
||||||
return _trackUpdated(store, next, action);
|
return _trackUpdated(store, next, action);
|
||||||
|
|
||||||
case VIDEO_MUTED_CHANGED:
|
case SET_VIDEO_MUTED:
|
||||||
_mutedChanged(store, action, MEDIA_TYPE.VIDEO);
|
_setMuted(store, action, MEDIA_TYPE.VIDEO);
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -91,7 +91,7 @@ function _getLocalTrack(store, mediaType) {
|
||||||
* @private
|
* @private
|
||||||
* @returns {void}
|
* @returns {void}
|
||||||
*/
|
*/
|
||||||
function _mutedChanged(store, action, mediaType) {
|
function _setMuted(store, action, mediaType) {
|
||||||
const localTrack = _getLocalTrack(store, mediaType);
|
const localTrack = _getLocalTrack(store, mediaType);
|
||||||
|
|
||||||
localTrack && setTrackMuted(localTrack.jitsiTrack, action.muted);
|
localTrack && setTrackMuted(localTrack.jitsiTrack, action.muted);
|
||||||
|
@ -145,10 +145,10 @@ function _trackUpdated(store, next, action) {
|
||||||
if (oldMuted !== newMuted) {
|
if (oldMuted !== newMuted) {
|
||||||
switch (mediaType) {
|
switch (mediaType) {
|
||||||
case MEDIA_TYPE.AUDIO:
|
case MEDIA_TYPE.AUDIO:
|
||||||
store.dispatch(audioMutedChanged(newMuted));
|
store.dispatch(setAudioMuted(newMuted));
|
||||||
break;
|
break;
|
||||||
case MEDIA_TYPE.VIDEO:
|
case MEDIA_TYPE.VIDEO:
|
||||||
store.dispatch(videoMutedChanged(newMuted));
|
store.dispatch(setVideoMuted(newMuted));
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,12 +1,12 @@
|
||||||
import { Symbol } from '../base/react';
|
import { Symbol } from '../base/react';
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Action to change the participant to be displayed in LargeVideo.
|
* Action to select the participant to be displayed in LargeVideo.
|
||||||
*
|
*
|
||||||
* {
|
* {
|
||||||
* type: LARGE_VIDEO_PARTICIPANT_CHANGED,
|
* type: SELECT_LARGE_VIDEO_PARTICIPANT,
|
||||||
* participantId: (string|undefined)
|
* participantId: (string|undefined)
|
||||||
* }
|
* }
|
||||||
*/
|
*/
|
||||||
export const LARGE_VIDEO_PARTICIPANT_CHANGED
|
export const SELECT_LARGE_VIDEO_PARTICIPANT
|
||||||
= Symbol('LARGE_VIDEO_PARTICIPANT_CHANGED');
|
= Symbol('SELECT_LARGE_VIDEO_PARTICIPANT');
|
||||||
|
|
|
@ -8,7 +8,7 @@ import {
|
||||||
getTrackByMediaTypeAndParticipant
|
getTrackByMediaTypeAndParticipant
|
||||||
} from '../base/tracks';
|
} from '../base/tracks';
|
||||||
|
|
||||||
import { LARGE_VIDEO_PARTICIPANT_CHANGED } from './actionTypes';
|
import { SELECT_LARGE_VIDEO_PARTICIPANT } from './actionTypes';
|
||||||
import './middleware';
|
import './middleware';
|
||||||
import './reducer';
|
import './reducer';
|
||||||
|
|
||||||
|
@ -60,7 +60,7 @@ export function selectParticipantInLargeVideo() {
|
||||||
|
|
||||||
if (participantId !== largeVideo.participantId) {
|
if (participantId !== largeVideo.participantId) {
|
||||||
dispatch({
|
dispatch({
|
||||||
type: LARGE_VIDEO_PARTICIPANT_CHANGED,
|
type: SELECT_LARGE_VIDEO_PARTICIPANT,
|
||||||
participantId
|
participantId
|
||||||
});
|
});
|
||||||
|
|
||||||
|
|
|
@ -1,7 +1,7 @@
|
||||||
import { PARTICIPANT_ID_CHANGED } from '../base/participants';
|
import { PARTICIPANT_ID_CHANGED } from '../base/participants';
|
||||||
import { ReducerRegistry } from '../base/redux';
|
import { ReducerRegistry } from '../base/redux';
|
||||||
|
|
||||||
import { LARGE_VIDEO_PARTICIPANT_CHANGED } from './actionTypes';
|
import { SELECT_LARGE_VIDEO_PARTICIPANT } from './actionTypes';
|
||||||
|
|
||||||
ReducerRegistry.register('features/largeVideo', (state = {}, action) => {
|
ReducerRegistry.register('features/largeVideo', (state = {}, action) => {
|
||||||
switch (action.type) {
|
switch (action.type) {
|
||||||
|
@ -20,7 +20,7 @@ ReducerRegistry.register('features/largeVideo', (state = {}, action) => {
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case LARGE_VIDEO_PARTICIPANT_CHANGED:
|
case SELECT_LARGE_VIDEO_PARTICIPANT:
|
||||||
return {
|
return {
|
||||||
...state,
|
...state,
|
||||||
participantId: action.participantId
|
participantId: action.participantId
|
||||||
|
|
Loading…
Reference in New Issue