ref: Convert some reducers to TS (#11886)

This commit is contained in:
Robert Pintilii 2022-07-20 18:01:16 +03:00 committed by GitHub
parent 24b9f5d113
commit c1e9724bba
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
6 changed files with 74 additions and 21 deletions

View File

@ -12,9 +12,11 @@ import { IFlagsState } from '../base/flags/reducer';
import { IJwtState } from '../base/jwt/reducer'; import { IJwtState } from '../base/jwt/reducer';
import { ILastNState } from '../base/lastn/reducer'; import { ILastNState } from '../base/lastn/reducer';
import { ILibJitsiMeetState } from '../base/lib-jitsi-meet/reducer'; import { ILibJitsiMeetState } from '../base/lib-jitsi-meet/reducer';
import { ILoggingState } from '../base/logging/reducer';
import { IMediaState } from '../base/media/reducer';
import { INetInfoState } from '../base/net-info/reducer';
import { INoiseSuppressionState } from '../noise-suppression/reducer'; import { INoiseSuppressionState } from '../noise-suppression/reducer';
export interface IStore { export interface IStore {
dispatch: Function, dispatch: Function,
getState: Function getState: Function
@ -35,6 +37,9 @@ export interface IState {
'features/base/jwt': IJwtState, 'features/base/jwt': IJwtState,
'features/base/known-domains': Array<string>, 'features/base/known-domains': Array<string>,
'features/base/lastn': ILastNState, 'features/base/lastn': ILastNState,
'features/base/lib-jitsi-meet': ILibJitsiMeetState 'features/base/lib-jitsi-meet': ILibJitsiMeetState,
'features/base/logging': ILoggingState,
'features/base/media': IMediaState,
'features/base/net-info': INetInfoState,
'features/noise-suppression': INoiseSuppressionState 'features/noise-suppression': INoiseSuppressionState
} }

View File

@ -1,6 +1,5 @@
// @flow import ReducerRegistry from '../redux/ReducerRegistry';
import { equals, set } from '../redux/functions';
import { equals, ReducerRegistry, set } from '../redux';
import { SET_LOG_COLLECTOR, SET_LOGGING_CONFIG } from './actionTypes'; import { SET_LOG_COLLECTOR, SET_LOGGING_CONFIG } from './actionTypes';
@ -38,9 +37,23 @@ if (navigator.product === 'ReactNative') {
}; };
} }
type LogLevel = 'trace' | 'log' | 'info' | 'warn' | 'error';
interface LoggingLevel {
[key: string]: LogLevel;
}
export interface ILoggingState {
config: LoggingLevel & {
defaultLogLevel: LogLevel;
disableLogCollector?: boolean;
};
logCollector?: Object;
}
ReducerRegistry.register( ReducerRegistry.register(
'features/base/logging', 'features/base/logging',
(state = DEFAULT_STATE, action) => { (state: ILoggingState = DEFAULT_STATE, action) => {
switch (action.type) { switch (action.type) {
case SET_LOGGING_CONFIG: case SET_LOGGING_CONFIG:
return _setLoggingConfig(state, action); return _setLoggingConfig(state, action);
@ -63,7 +76,7 @@ ReducerRegistry.register(
* @returns {Object} The new state of the feature base/logging after the * @returns {Object} The new state of the feature base/logging after the
* reduction of the specified action. * reduction of the specified action.
*/ */
function _setLoggingConfig(state, action) { function _setLoggingConfig(state: ILoggingState, action: any) {
const config = { const config = {
// The config of DEFAULT_STATE is the default configuration of the // The config of DEFAULT_STATE is the default configuration of the
// feature base/logging. // feature base/logging.
@ -91,6 +104,6 @@ function _setLoggingConfig(state, action) {
* @returns {Object} The new state of the feature base/logging after the * @returns {Object} The new state of the feature base/logging after the
* reduction of the specified action. * reduction of the specified action.
*/ */
function _setLogCollector(state, action) { function _setLogCollector(state: ILoggingState, action: any) {
return set(state, 'logCollector', action.logCollector); return set(state, 'logCollector', action.logCollector);
} }

View File

@ -1,7 +1,7 @@
import { combineReducers } from 'redux'; import { combineReducers } from 'redux';
import { CONFERENCE_FAILED, CONFERENCE_LEFT } from '../conference/actionTypes'; import { CONFERENCE_FAILED, CONFERENCE_LEFT } from '../conference/actionTypes';
import { ReducerRegistry } from '../redux'; import ReducerRegistry from '../redux/ReducerRegistry';
import { TRACK_REMOVED } from '../tracks/actionTypes'; import { TRACK_REMOVED } from '../tracks/actionTypes';
import { import {
@ -49,7 +49,7 @@ export const _AUDIO_INITIAL_MEDIA_STATE = {
* @private * @private
* @returns {AudioMediaState} * @returns {AudioMediaState}
*/ */
function _audio(state = _AUDIO_INITIAL_MEDIA_STATE, action) { function _audio(state: IAudioState = _AUDIO_INITIAL_MEDIA_STATE, action: any) {
switch (action.type) { switch (action.type) {
case SET_AUDIO_AVAILABLE: case SET_AUDIO_AVAILABLE:
return { return {
@ -103,7 +103,7 @@ export const _SCREENSHARE_INITIAL_MEDIA_STATE = {
* @private * @private
* @returns {ScreenshareMediaState} * @returns {ScreenshareMediaState}
*/ */
function _screenshare(state = _SCREENSHARE_INITIAL_MEDIA_STATE, action) { function _screenshare(state: IScreenshareState = _SCREENSHARE_INITIAL_MEDIA_STATE, action: any) {
switch (action.type) { switch (action.type) {
case SET_SCREENSHARE_MUTED: case SET_SCREENSHARE_MUTED:
return { return {
@ -161,7 +161,7 @@ export const _VIDEO_INITIAL_MEDIA_STATE = {
* @private * @private
* @returns {VideoMediaState} * @returns {VideoMediaState}
*/ */
function _video(state = _VIDEO_INITIAL_MEDIA_STATE, action) { function _video(state: IVideoState = _VIDEO_INITIAL_MEDIA_STATE, action: any) {
switch (action.type) { switch (action.type) {
case CONFERENCE_FAILED: case CONFERENCE_FAILED:
case CONFERENCE_LEFT: case CONFERENCE_LEFT:
@ -216,6 +216,32 @@ function _video(state = _VIDEO_INITIAL_MEDIA_STATE, action) {
} }
} }
interface IAudioState {
available: boolean;
muted: boolean;
unmuteBlocked: boolean;
}
interface IScreenshareState {
available: boolean;
muted: number;
unmuteBlocked: boolean;
}
interface IVideoState {
available: boolean;
facingMode: string;
muted: number;
transforms: Object;
unmuteBlocked: boolean;
}
export interface IMediaState {
audio: IAudioState;
screenshare: IScreenshareState;
video: IVideoState;
}
/** /**
* Listen for various actions related to media devices. * Listen for various actions related to media devices.
* *
@ -239,7 +265,7 @@ ReducerRegistry.register('features/base/media', combineReducers({
* @private * @private
* @returns {Object} * @returns {Object}
*/ */
function _clearAllVideoTransforms(state) { function _clearAllVideoTransforms(state: IVideoState) {
return { return {
...state, ...state,
transforms: _VIDEO_INITIAL_MEDIA_STATE.transforms transforms: _VIDEO_INITIAL_MEDIA_STATE.transforms
@ -254,7 +280,7 @@ function _clearAllVideoTransforms(state) {
* @private * @private
* @returns {Object} * @returns {Object}
*/ */
function _storeVideoTransform(state, { streamId, transform }) { function _storeVideoTransform(state: IVideoState, { streamId, transform }: { streamId: string, transform: string }) {
return { return {
...state, ...state,
transforms: { transforms: {
@ -273,12 +299,12 @@ function _storeVideoTransform(state, { streamId, transform }) {
* @private * @private
* @returns {Object} * @returns {Object}
*/ */
function _trackRemoved(state, { track: { jitsiTrack } }) { function _trackRemoved(state: IVideoState, { track: { jitsiTrack } } : {track: {jitsiTrack: any}}) {
if (jitsiTrack) { if (jitsiTrack) {
const streamId = jitsiTrack.getStreamId(); const streamId = jitsiTrack.getStreamId();
if (streamId && streamId in state.transforms) { if (streamId && streamId in state.transforms) {
const nextTransforms = { const nextTransforms: any = {
...state.transforms ...state.transforms
}; };

View File

@ -1,5 +1,7 @@
// @flow import { NetInfoCellularGeneration, NetInfoStateType } from '@react-native-community/netinfo';
import { assign, ReducerRegistry } from '../redux';
import ReducerRegistry from '../redux/ReducerRegistry';
import { assign } from '../redux/functions';
import { SET_NETWORK_INFO, _STORE_NETWORK_INFO_CLEANUP } from './actionTypes'; import { SET_NETWORK_INFO, _STORE_NETWORK_INFO_CLEANUP } from './actionTypes';
import { STORE_NAME } from './constants'; import { STORE_NAME } from './constants';
@ -8,10 +10,18 @@ const DEFAULT_STATE = {
isOnline: true isOnline: true
}; };
export interface INetInfoState {
_cleanup?: Function;
cellularGeneration?: NetInfoCellularGeneration;
details?: Object;
isOnline?: boolean;
networkType?: NetInfoStateType;
}
/** /**
* The base/net-info feature's reducer. * The base/net-info feature's reducer.
*/ */
ReducerRegistry.register(STORE_NAME, (state = DEFAULT_STATE, action) => { ReducerRegistry.register(STORE_NAME, (state: INetInfoState = DEFAULT_STATE, action) => {
switch (action.type) { switch (action.type) {
case SET_NETWORK_INFO: case SET_NETWORK_INFO:
return assign(state, { return assign(state, {

View File

@ -1,5 +1,4 @@
// @ts-ignore import ReducerRegistry from '../base/redux/ReducerRegistry';
import { ReducerRegistry } from '../base/redux';
import { import {
SET_NOISE_SUPPRESSION_ENABLED SET_NOISE_SUPPRESSION_ENABLED