mirror of
https://gitcode.com/GitHub_Trending/ji/jitsi-meet.git
synced 2026-05-14 14:07:50 +00:00
Simplify the code by using a bitfied instead of a couple of boolean flags. This allows us to mute the video from multiple places and only make the unmute effective once they have all unmuted. Alas, this cannot be applied to the web without a massive refactor, because it uses the track muted state as the source of truth instead of the media state.
141 lines
3.1 KiB
JavaScript
141 lines
3.1 KiB
JavaScript
import { combineReducers } from 'redux';
|
|
|
|
import { ReducerRegistry } from '../redux';
|
|
|
|
import {
|
|
SET_AUDIO_AVAILABLE,
|
|
SET_AUDIO_MUTED,
|
|
SET_CAMERA_FACING_MODE,
|
|
SET_VIDEO_AVAILABLE,
|
|
SET_VIDEO_MUTED,
|
|
TOGGLE_CAMERA_FACING_MODE
|
|
} 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 = {
|
|
available: true,
|
|
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.
|
|
* @private
|
|
* @returns {AudioMediaState}
|
|
*/
|
|
function _audio(state = AUDIO_INITIAL_MEDIA_STATE, action) {
|
|
switch (action.type) {
|
|
case SET_AUDIO_AVAILABLE:
|
|
return {
|
|
...state,
|
|
available: action.available
|
|
};
|
|
|
|
case SET_AUDIO_MUTED:
|
|
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 = {
|
|
available: true,
|
|
facingMode: CAMERA_FACING_MODE.USER,
|
|
muted: 0
|
|
};
|
|
|
|
/**
|
|
* 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.
|
|
* @private
|
|
* @returns {VideoMediaState}
|
|
*/
|
|
function _video(state = VIDEO_INITIAL_MEDIA_STATE, action) {
|
|
switch (action.type) {
|
|
case SET_CAMERA_FACING_MODE:
|
|
return {
|
|
...state,
|
|
facingMode: action.cameraFacingMode
|
|
};
|
|
|
|
case SET_VIDEO_AVAILABLE:
|
|
return {
|
|
...state,
|
|
available: action.available
|
|
};
|
|
|
|
case SET_VIDEO_MUTED:
|
|
return {
|
|
...state,
|
|
muted: action.muted
|
|
};
|
|
|
|
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
|
|
};
|
|
}
|
|
|
|
default:
|
|
return state;
|
|
}
|
|
}
|
|
|
|
/**
|
|
* 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({
|
|
audio: _audio,
|
|
video: _video
|
|
}));
|