Skip to content

Jitsi Meet - Secure, Simple and Scalable Video Conferences that you use as a standalone app or embed in your web application.

ref: Convert some reducers to TS (#11886)

Robert Pintiliic1e9724bbaf6
diff --git a/react/features/app/types.ts b/react/features/app/types.ts
index 5e71fe466f..443f14cde8 100644
--- a/react/features/app/types.ts
+++ b/react/features/app/types.ts
@@ -12,9 +12,11 @@ import { IFlagsState } from '../base/flags/reducer';
import { IJwtState } from '../base/jwt/reducer';
import { ILastNState } from '../base/lastn/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';
-
export interface IStore {
dispatch: Function,
getState: Function
@@ -35,6 +37,9 @@ export interface IState {
'features/base/jwt': IJwtState,
'features/base/known-domains': Array<string>,
'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
}
diff --git a/react/features/base/logging/reducer.js b/react/features/base/logging/reducer.ts
similarity index 79%
rename from react/features/base/logging/reducer.js
rename to react/features/base/logging/reducer.ts
index a423e88956..d93def7175 100644
--- a/react/features/base/logging/reducer.js
+++ b/react/features/base/logging/reducer.ts
@@ -1,6 +1,5 @@
-// @flow
-
-import { equals, ReducerRegistry, set } from '../redux';
+import ReducerRegistry from '../redux/ReducerRegistry';
+import { equals, set } from '../redux/functions';
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(
'features/base/logging',
- (state = DEFAULT_STATE, action) => {
+ (state: ILoggingState = DEFAULT_STATE, action) => {
switch (action.type) {
case SET_LOGGING_CONFIG:
return _setLoggingConfig(state, action);
@@ -63,7 +76,7 @@ ReducerRegistry.register(
* @returns {Object} The new state of the feature base/logging after the
* reduction of the specified action.
*/
-function _setLoggingConfig(state, action) {
+function _setLoggingConfig(state: ILoggingState, action: any) {
const config = {
// The config of DEFAULT_STATE is the default configuration of the
// feature base/logging.
@@ -91,6 +104,6 @@ function _setLoggingConfig(state, action) {
* @returns {Object} The new state of the feature base/logging after the
* reduction of the specified action.
*/
-function _setLogCollector(state, action) {
+function _setLogCollector(state: ILoggingState, action: any) {
return set(state, 'logCollector', action.logCollector);
}
diff --git a/react/features/base/media/reducer.js b/react/features/base/media/reducer.ts
similarity index 86%
rename from react/features/base/media/reducer.js
rename to react/features/base/media/reducer.ts
index 8988b443af..65951f7177 100644
--- a/react/features/base/media/reducer.js
+++ b/react/features/base/media/reducer.ts
@@ -1,7 +1,7 @@
import { combineReducers } from 'redux';
import { CONFERENCE_FAILED, CONFERENCE_LEFT } from '../conference/actionTypes';
-import { ReducerRegistry } from '../redux';
+import ReducerRegistry from '../redux/ReducerRegistry';
import { TRACK_REMOVED } from '../tracks/actionTypes';
import {
@@ -49,7 +49,7 @@ export const _AUDIO_INITIAL_MEDIA_STATE = {
* @private
* @returns {AudioMediaState}
*/
-function _audio(state = _AUDIO_INITIAL_MEDIA_STATE, action) {
+function _audio(state: IAudioState = _AUDIO_INITIAL_MEDIA_STATE, action: any) {
switch (action.type) {
case SET_AUDIO_AVAILABLE:
return {
@@ -103,7 +103,7 @@ export const _SCREENSHARE_INITIAL_MEDIA_STATE = {
* @private
* @returns {ScreenshareMediaState}
*/
-function _screenshare(state = _SCREENSHARE_INITIAL_MEDIA_STATE, action) {
+function _screenshare(state: IScreenshareState = _SCREENSHARE_INITIAL_MEDIA_STATE, action: any) {
switch (action.type) {
case SET_SCREENSHARE_MUTED:
return {
@@ -161,7 +161,7 @@ export const _VIDEO_INITIAL_MEDIA_STATE = {
* @private
* @returns {VideoMediaState}
*/
-function _video(state = _VIDEO_INITIAL_MEDIA_STATE, action) {
+function _video(state: IVideoState = _VIDEO_INITIAL_MEDIA_STATE, action: any) {
switch (action.type) {
case CONFERENCE_FAILED:
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.
*
@@ -239,7 +265,7 @@ ReducerRegistry.register('features/base/media', combineReducers({
* @private
* @returns {Object}
*/
-function _clearAllVideoTransforms(state) {
+function _clearAllVideoTransforms(state: IVideoState) {
return {
...state,
transforms: _VIDEO_INITIAL_MEDIA_STATE.transforms
@@ -254,7 +280,7 @@ function _clearAllVideoTransforms(state) {
* @private
* @returns {Object}
*/
-function _storeVideoTransform(state, { streamId, transform }) {
+function _storeVideoTransform(state: IVideoState, { streamId, transform }: { streamId: string, transform: string }) {
return {
...state,
transforms: {
@@ -273,12 +299,12 @@ function _storeVideoTransform(state, { streamId, transform }) {
* @private
* @returns {Object}
*/
-function _trackRemoved(state, { track: { jitsiTrack } }) {
+function _trackRemoved(state: IVideoState, { track: { jitsiTrack } } : {track: {jitsiTrack: any}}) {
if (jitsiTrack) {
const streamId = jitsiTrack.getStreamId();
if (streamId && streamId in state.transforms) {
- const nextTransforms = {
+ const nextTransforms: any = {
...state.transforms
};
diff --git a/react/features/base/net-info/constants.js b/react/features/base/net-info/constants.ts
similarity index 100%
rename from react/features/base/net-info/constants.js
rename to react/features/base/net-info/constants.ts
diff --git a/react/features/base/net-info/reducer.js b/react/features/base/net-info/reducer.ts
similarity index 57%
rename from react/features/base/net-info/reducer.js
rename to react/features/base/net-info/reducer.ts
index ad7c697332..0a78d4c674 100644
--- a/react/features/base/net-info/reducer.js
+++ b/react/features/base/net-info/reducer.ts
@@ -1,5 +1,7 @@
-// @flow
-import { assign, ReducerRegistry } from '../redux';
+import { NetInfoCellularGeneration, NetInfoStateType } from '@react-native-community/netinfo';
+
+import ReducerRegistry from '../redux/ReducerRegistry';
+import { assign } from '../redux/functions';
import { SET_NETWORK_INFO, _STORE_NETWORK_INFO_CLEANUP } from './actionTypes';
import { STORE_NAME } from './constants';
@@ -8,10 +10,18 @@ const DEFAULT_STATE = {
isOnline: true
};
+export interface INetInfoState {
+ _cleanup?: Function;
+ cellularGeneration?: NetInfoCellularGeneration;
+ details?: Object;
+ isOnline?: boolean;
+ networkType?: NetInfoStateType;
+}
+
/**
* 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) {
case SET_NETWORK_INFO:
return assign(state, {
diff --git a/react/features/noise-suppression/reducer.ts b/react/features/noise-suppression/reducer.ts
index 8a7736e958..3119c09c3c 100644
--- a/react/features/noise-suppression/reducer.ts
+++ b/react/features/noise-suppression/reducer.ts
@@ -1,5 +1,4 @@
-// @ts-ignore
-import { ReducerRegistry } from '../base/redux';
+import ReducerRegistry from '../base/redux/ReducerRegistry';
import {
SET_NOISE_SUPPRESSION_ENABLED