2016-10-05 14:36:59 +00:00
|
|
|
import { combineReducers } from 'redux';
|
|
|
|
|
|
|
|
import { ReducerRegistry } from '../redux';
|
|
|
|
|
|
|
|
import {
|
2017-01-11 18:14:00 +00:00
|
|
|
SET_AUDIO_MUTED,
|
|
|
|
SET_CAMERA_FACING_MODE,
|
2017-04-03 08:57:01 +00:00
|
|
|
SET_VIDEO_MUTED,
|
|
|
|
TOGGLE_CAMERA_FACING_MODE
|
2016-10-05 14:36:59 +00:00
|
|
|
} from './actionTypes';
|
|
|
|
import { CAMERA_FACING_MODE } from './constants';
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Media state object for local audio.
|
|
|
|
*
|
|
|
|
* @typedef {Object} AudioMediaState
|
|
|
|
* @property {boolean} muted=false - Audio muted state.
|
|
|
|
*/
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Initial state for local audio.
|
|
|
|
*
|
|
|
|
* @type {AudioMediaState}
|
|
|
|
*/
|
|
|
|
const AUDIO_INITIAL_MEDIA_STATE = {
|
|
|
|
muted: false
|
|
|
|
};
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Reducer for audio media state.
|
|
|
|
*
|
|
|
|
* @param {AudioMediaState} state - Media state of local audio.
|
|
|
|
* @param {Object} action - Action object.
|
|
|
|
* @param {string} action.type - Type of action.
|
2017-01-28 23:28:13 +00:00
|
|
|
* @private
|
2016-10-05 14:36:59 +00:00
|
|
|
* @returns {AudioMediaState}
|
|
|
|
*/
|
2017-01-28 23:28:13 +00:00
|
|
|
function _audio(state = AUDIO_INITIAL_MEDIA_STATE, action) {
|
2016-10-05 14:36:59 +00:00
|
|
|
switch (action.type) {
|
2017-01-11 18:14:00 +00:00
|
|
|
case SET_AUDIO_MUTED:
|
2016-10-05 14:36:59 +00:00
|
|
|
return {
|
|
|
|
...state,
|
|
|
|
muted: action.muted
|
|
|
|
};
|
|
|
|
|
|
|
|
default:
|
|
|
|
return state;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Media state object for local video.
|
|
|
|
*
|
|
|
|
* @typedef {Object} VideoMediaState
|
|
|
|
* @property {CAMERA_FACING_MODE} facingMode='user' - Camera facing mode.
|
|
|
|
* @property {boolean} muted=false - Video muted state.
|
|
|
|
*/
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Initial state for video.
|
|
|
|
*
|
|
|
|
* @type {VideoMediaState}
|
|
|
|
*/
|
|
|
|
const VIDEO_INITIAL_MEDIA_STATE = {
|
|
|
|
facingMode: CAMERA_FACING_MODE.USER,
|
|
|
|
muted: false
|
|
|
|
};
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Reducer for camera media state.
|
|
|
|
*
|
|
|
|
* @param {VideoMediaState} state - Media state of local video.
|
|
|
|
* @param {Object} action - Action object.
|
|
|
|
* @param {string} action.type - Type of action.
|
2017-01-28 23:28:13 +00:00
|
|
|
* @private
|
2016-10-05 14:36:59 +00:00
|
|
|
* @returns {VideoMediaState}
|
|
|
|
*/
|
2017-01-28 23:28:13 +00:00
|
|
|
function _video(state = VIDEO_INITIAL_MEDIA_STATE, action) {
|
2016-10-05 14:36:59 +00:00
|
|
|
switch (action.type) {
|
2017-01-11 18:14:00 +00:00
|
|
|
case SET_CAMERA_FACING_MODE:
|
2016-10-05 14:36:59 +00:00
|
|
|
return {
|
|
|
|
...state,
|
|
|
|
facingMode: action.cameraFacingMode
|
|
|
|
};
|
|
|
|
|
2017-01-11 18:14:00 +00:00
|
|
|
case SET_VIDEO_MUTED:
|
2016-10-05 14:36:59 +00:00
|
|
|
return {
|
|
|
|
...state,
|
|
|
|
muted: action.muted
|
|
|
|
};
|
|
|
|
|
2017-04-03 08:57:01 +00:00
|
|
|
case TOGGLE_CAMERA_FACING_MODE: {
|
|
|
|
let cameraFacingMode = state.facingMode;
|
|
|
|
|
|
|
|
cameraFacingMode
|
|
|
|
= cameraFacingMode === CAMERA_FACING_MODE.USER
|
|
|
|
? CAMERA_FACING_MODE.ENVIRONMENT
|
|
|
|
: CAMERA_FACING_MODE.USER;
|
|
|
|
|
|
|
|
return {
|
|
|
|
...state,
|
|
|
|
facingMode: cameraFacingMode
|
|
|
|
};
|
|
|
|
}
|
|
|
|
|
2016-10-05 14:36:59 +00:00
|
|
|
default:
|
|
|
|
return state;
|
|
|
|
}
|
|
|
|
}
|
2017-01-17 14:44:50 +00:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Listen for various actions related to media devices.
|
|
|
|
*
|
|
|
|
* @param {Object} state - State of media devices.
|
|
|
|
* @param {Object} action - Action object.
|
|
|
|
* @param {string} action.type - Type of action.
|
|
|
|
* @param {Object} action.media - Information about media devices to be
|
|
|
|
* modified.
|
|
|
|
* @returns {Object}
|
|
|
|
*/
|
|
|
|
ReducerRegistry.register('features/base/media', combineReducers({
|
2017-01-28 23:28:13 +00:00
|
|
|
audio: _audio,
|
|
|
|
video: _video
|
2017-01-17 14:44:50 +00:00
|
|
|
}));
|