Jitsi Meet - Secure, Simple and Scalable Video Conferences that you use as a standalone app or embed in your web application.
TypeScript debiandeep-videojitsijitsi-meetscalable-video-conferencessfuvideovideo-communicationvideo-conferencingwebrtc
ref(reducers) Convert some reducers to TS (#11768)
Robert Pintiliia39d9f283d75
diff --git a/react/features/analytics/reducer.js b/react/features/analytics/reducer.tssimilarity index 70%rename from react/features/analytics/reducer.jsrename to react/features/analytics/reducer.tsindex 5510a90e23..67cbc03f8a 100644--- a/react/features/analytics/reducer.js+++ b/react/features/analytics/reducer.ts@@ -1,6 +1,4 @@-// @flow--import { ReducerRegistry } from '../base/redux';+import ReducerRegistry from '../base/redux/ReducerRegistry';import { UPDATE_LOCAL_TRACKS_DURATION } from './actionTypes';@@ -30,6 +28,22 @@ const DEFAULT_STATE = {}};+interface Value {+ startedTime: number,+ value: number+}++export interface IAnalyticsState {+ localTracksDuration: {+ audio: Value,+ video: {+ camera: Value,+ desktop: Value+ },+ conference: Value+ }+}+/*** Listen for actions which changes the state of the analytics feature.*@@ -38,7 +52,7 @@ const DEFAULT_STATE = {* @param {string} action.type - Type of action.* @returns {Object}*/-ReducerRegistry.register('features/analytics', (state = DEFAULT_STATE, action) => {+ReducerRegistry.register('features/analytics', (state: IAnalyticsState = DEFAULT_STATE, action: any) => {switch (action.type) {case UPDATE_LOCAL_TRACKS_DURATION:return {diff --git a/react/features/app/types.ts b/react/features/app/types.tsindex 6c438a0d26..fa6429499f 100644--- a/react/features/app/types.ts+++ b/react/features/app/types.ts@@ -1,4 +1,20 @@+import { IAnalyticsState } from "../analytics/reducer"+import { IAuthenticationState } from "../authentication/reducer"+import { IAVModerationState } from "../av-moderation/reducer"+import { IAppState } from "../base/app/reducer"+import { IAudioOnlyState } from "../base/audio-only/reducer"+import { IConferenceState } from "../base/conference/reducer"+export interface IStore {getState: Function,dispatch: Function}++export interface IState {+ 'features/analytics': IAnalyticsState,+ 'features/authentication': IAuthenticationState,+ 'features/av-moderation': IAVModerationState,+ 'features/base/app': IAppState,+ 'features/base/audio-only': IAudioOnlyState,+ 'features/base/conference': IConferenceState+}diff --git a/react/features/authentication/reducer.js b/react/features/authentication/reducer.tssimilarity index 81%rename from react/features/authentication/reducer.jsrename to react/features/authentication/reducer.tsindex 1191943f83..c3dd3d4c19 100644--- a/react/features/authentication/reducer.js+++ b/react/features/authentication/reducer.ts@@ -1,6 +1,6 @@-// @flow--import { assign, ReducerRegistry } from '../base/redux';+// @ts-ignore+import { assign } from '../base/redux/functions';+import ReducerRegistry from '../base/redux/ReducerRegistry';import {CANCEL_LOGIN,@@ -10,6 +10,13 @@ import {WAIT_FOR_OWNER} from './actionTypes';+export interface IAuthenticationState {+ error?: Object|undefined;+ progress?: number|undefined;+ thenableWithCancel?: Object|undefined;+ waitForOwnerTimeoutID?: number;+}+/*** Listens for actions which change the state of the authentication feature.*@@ -18,7 +25,7 @@ import {* @param {string} action.type - Type of action.* @returns {Object}*/-ReducerRegistry.register('features/authentication', (state = {}, action) => {+ReducerRegistry.register('features/authentication', (state: IAuthenticationState = {}, action: any) => {switch (action.type) {case CANCEL_LOGIN:return assign(state, {diff --git a/react/features/av-moderation/constants.js b/react/features/av-moderation/constants.tssimilarity index 85%rename from react/features/av-moderation/constants.jsrename to react/features/av-moderation/constants.tsindex 261b2f6047..18f0d62665 100644--- a/react/features/av-moderation/constants.js+++ b/react/features/av-moderation/constants.ts@@ -1,11 +1,9 @@-// @flow-import { MEDIA_TYPE, type MediaType } from '../base/media/constants';/*** Mapping between a media type and the witelist reducer key.*/-export const MEDIA_TYPE_TO_WHITELIST_STORE_KEY: {[key: MediaType]: string} = {+export const MEDIA_TYPE_TO_WHITELIST_STORE_KEY: { [key: string]: string } = {[MEDIA_TYPE.AUDIO]: 'audioWhitelist',[MEDIA_TYPE.VIDEO]: 'videoWhitelist'};@@ -13,7 +11,7 @@ export const MEDIA_TYPE_TO_WHITELIST_STORE_KEY: {[key: MediaType]: string} = {/*** Mapping between a media type and the pending reducer key.*/-export const MEDIA_TYPE_TO_PENDING_STORE_KEY: {[key: MediaType]: string} = {+export const MEDIA_TYPE_TO_PENDING_STORE_KEY: {[key: string]: string} = {[MEDIA_TYPE.AUDIO]: 'pendingAudio',[MEDIA_TYPE.VIDEO]: 'pendingVideo'};diff --git a/react/features/av-moderation/reducer.js b/react/features/av-moderation/reducer.tssimilarity index 90%rename from react/features/av-moderation/reducer.jsrename to react/features/av-moderation/reducer.tsindex 9738744082..a2696580ad 100644--- a/react/features/av-moderation/reducer.js+++ b/react/features/av-moderation/reducer.ts@@ -1,12 +1,11 @@-/* @flow */-import { MEDIA_TYPE } from '../base/media/constants';import type { MediaType } from '../base/media/constants';import {PARTICIPANT_LEFT,PARTICIPANT_UPDATED+ // @ts-ignore} from '../base/participants';-import { ReducerRegistry } from '../base/redux';+import ReducerRegistry from '../base/redux/ReducerRegistry';import {DISABLE_MODERATION,@@ -29,8 +28,19 @@ const initialState = {pendingVideo: []};+export interface IAVModerationState {+ audioModerationEnabled: boolean;+ videoModerationEnabled: boolean;+ audioWhitelist: { [id: string]: boolean };+ videoWhitelist: { [id: string]: boolean };+ pendingAudio: Array<{ id: string }>;+ pendingVideo: Array<{ id: string }>;+ audioUnmuteApproved?: boolean|undefined;+ videoUnmuteApproved?: boolean|undefined;+}+/**- Updates a participant in the state for the specified media type.+ * Updates a participant in the state for the specified media type.** @param {MediaType} mediaType - The media type.* @param {Object} participant - Information about participant to be modified.@@ -38,11 +48,11 @@ const initialState = {* @private* @returns {boolean} - Whether state instance was modified.*/-function _updatePendingParticipant(mediaType: MediaType, participant, state: Object = {}) {+function _updatePendingParticipant(mediaType: MediaType, participant: any, state: any = {}) {let arrayItemChanged = false;const storeKey = MEDIA_TYPE_TO_PENDING_STORE_KEY[mediaType];const arr = state[storeKey];- const newArr = arr.map(pending => {+ const newArr = arr.map((pending: { id: string} ) => {if (pending.id === participant.id) {arrayItemChanged = true;@@ -64,7 +74,7 @@ function _updatePendingParticipant(mediaType: MediaType, participant, state: Objreturn false;}-ReducerRegistry.register('features/av-moderation', (state = initialState, action) => {+ReducerRegistry.register('features/av-moderation', (state: IAVModerationState = initialState, action: any) => {switch (action.type) {case DISABLE_MODERATION: {diff --git a/react/features/base/app/reducer.js b/react/features/base/app/reducer.tssimilarity index 72%rename from react/features/base/app/reducer.jsrename to react/features/base/app/reducer.tsindex e099c5d679..0b656bc23b 100644--- a/react/features/base/app/reducer.js+++ b/react/features/base/app/reducer.ts@@ -1,10 +1,12 @@-// @flow--import { ReducerRegistry } from '../redux';+import ReducerRegistry from '../redux/ReducerRegistry';import { APP_WILL_MOUNT, APP_WILL_UNMOUNT } from './actionTypes';-ReducerRegistry.register('features/base/app', (state = {}, action) => {+export interface IAppState {+ app?: Object|undefined;+}++ReducerRegistry.register('features/base/app', (state: IAppState = {}, action) => {switch (action.type) {case APP_WILL_MOUNT: {const { app } = action;diff --git a/react/features/base/audio-only/reducer.js b/react/features/base/audio-only/reducer.tssimilarity index 56%rename from react/features/base/audio-only/reducer.jsrename to react/features/base/audio-only/reducer.tsindex 28b1a289c7..f24dca3f5c 100644--- a/react/features/base/audio-only/reducer.js+++ b/react/features/base/audio-only/reducer.ts@@ -1,16 +1,17 @@-// @flow--import { ReducerRegistry } from '../redux';+import ReducerRegistry from '../redux/ReducerRegistry';import { SET_AUDIO_ONLY } from './actionTypes';+export interface IAudioOnlyState {+ enabled: boolean+}const DEFAULT_STATE = {enabled: false};-ReducerRegistry.register('features/base/audio-only', (state = DEFAULT_STATE, action) => {+ReducerRegistry.register('features/base/audio-only', (state: IAudioOnlyState = DEFAULT_STATE, action) => {switch (action.type) {case SET_AUDIO_ONLY:return {diff --git a/react/features/base/conference/reducer.js b/react/features/base/conference/reducer.tssimilarity index 90%rename from react/features/base/conference/reducer.jsrename to react/features/base/conference/reducer.tsindex 090b51725b..2400d5369b 100644--- a/react/features/base/conference/reducer.js+++ b/react/features/base/conference/reducer.ts@@ -1,9 +1,12 @@-// @flow-+// @ts-ignoreimport { LOCKED_LOCALLY, LOCKED_REMOTELY } from '../../room-lock';+// @ts-ignoreimport { CONNECTION_WILL_CONNECT, SET_LOCATION_URL } from '../connection';+// @ts-ignoreimport { JitsiConferenceErrors } from '../lib-jitsi-meet';-import { assign, ReducerRegistry, set } from '../redux';+// @ts-ignore+import { assign, set } from '../redux';+import ReducerRegistry from '../redux/ReducerRegistry';import {AUTH_STATUS_CHANGED,@@ -25,6 +28,7 @@ import {SET_START_MUTED_POLICY,SET_START_REACTIONS_MUTED} from './actionTypes';+// @ts-ignoreimport { isRoomValid } from './functions';const DEFAULT_STATE = {@@ -38,13 +42,26 @@ const DEFAULT_STATE = {passwordRequired: undefined};+export interface IConferenceState {+ conference: Object|undefined;+ e2eeSupported: boolean|undefined;+ joining: Object|undefined;+ leaving: Object|undefined;+ locked: string|undefined;+ membersOnly: boolean|undefined;+ password: string|undefined;+ passwordRequired: boolean|undefined;+ authEnabled?: boolean|undefined;+ authLogin?: string|undefined;+}+/*** Listen for actions that contain the conference object, so that it can be* stored for use by other action creators.*/ReducerRegistry.register('features/base/conference',- (state = DEFAULT_STATE, action) => {+ (state: IConferenceState = DEFAULT_STATE, action: any) => {switch (action.type) {case AUTH_STATUS_CHANGED:return _authStatusChanged(state, action);@@ -125,7 +142,7 @@ ReducerRegistry.register(* @returns {Object} The new state of the feature base/conference after the* reduction of the specified action.*/-function _authStatusChanged(state, { authEnabled, authLogin }) {+function _authStatusChanged(state: any, { authEnabled, authLogin }: {authEnabled: boolean, authLogin: string}) {return assign(state, {authEnabled,authLogin@@ -142,7 +159,7 @@ function _authStatusChanged(state, { authEnabled, authLogin }) {* @returns {Object} The new state of the feature base/conference after the* reduction of the specified action.*/-function _conferenceFailed(state, { conference, error }) {+function _conferenceFailed(state: any, { conference, error }: {conference: Object, error: any}) {// The current (similar to getCurrentConference in// base/conference/functions.any.js) conference which is joining or joined:const conference_ = state.conference || state.joining;@@ -208,7 +225,7 @@ function _conferenceFailed(state, { conference, error }) {* @returns {Object} The new state of the feature base/conference after the* reduction of the specified action.*/-function _conferenceJoined(state, { conference }) {+function _conferenceJoined(state: any, { conference }: {conference: any}) {// FIXME The indicator which determines whether a JitsiConference is locked// i.e. password-protected is private to lib-jitsi-meet. However, the// library does not fire LOCK_STATE_CHANGED upon joining a JitsiConference@@ -254,7 +271,7 @@ function _conferenceJoined(state, { conference }) {* @returns {Object} The next/new state of the feature base/conference after the* reduction of the specified action.*/-function _conferenceLeftOrWillLeave(state, { conference, type }) {+function _conferenceLeftOrWillLeave(state: any, { conference, type }: {conference: Object, type: string}) {const nextState = { ...state };// The redux action CONFERENCE_LEFT is the last time that we should be@@ -308,7 +325,7 @@ function _conferenceLeftOrWillLeave(state, { conference, type }) {* @returns {Object} The new state of the feature base/conference after the* reduction of the specified action.*/-function _conferenceWillJoin(state, { conference }) {+function _conferenceWillJoin(state: any, { conference }: {conference: Object}) {return assign(state, {error: undefined,joining: conference@@ -325,7 +342,7 @@ function _conferenceWillJoin(state, { conference }) {* @returns {Object} The new state of the feature base/conference after the* reduction of the specified action.*/-function _lockStateChanged(state, { conference, locked }) {+function _lockStateChanged(state: any, { conference, locked }: {conference: Object, locked: boolean}) {if (state.conference !== conference) {return state;}@@ -346,7 +363,7 @@ function _lockStateChanged(state, { conference, locked }) {* @returns {Object} The new state of the feature base/conference after the* reduction of the specified action.*/-function _p2pStatusChanged(state, action) {+function _p2pStatusChanged(state: any, action: any) {return set(state, 'p2p', action.p2p);}@@ -359,7 +376,7 @@ function _p2pStatusChanged(state, action) {* @returns {Object} The new state of the feature base/conference after the* reduction of the specified action.*/-function _setPassword(state, { conference, method, password }) {+function _setPassword(state: any, { conference, method, password }: {conference: any, method: Object, password: string}) {switch (method) {case conference.join:return assign(state, {@@ -406,7 +423,7 @@ function _setPassword(state, { conference, method, password }) {* @returns {Object} The new state of the feature base/conference after the* reduction of the specified action.*/-function _setRoom(state, action) {+function _setRoom(state: any, action: any) {let { room } = action;if (!isRoomValid(room)) {diff --git a/react/features/base/media/constants.js b/react/features/base/media/constants.tssimilarity index 94%rename from react/features/base/media/constants.jsrename to react/features/base/media/constants.tsindex 67d9a30939..80967d1c65 100644--- a/react/features/base/media/constants.js+++ b/react/features/base/media/constants.ts@@ -1,5 +1,3 @@-// @flow-/*** The set of facing modes for camera.*@@ -17,7 +15,7 @@ export type MediaType = 'audio' | 'video' | 'presenter' | 'screenshare';** @enum {string}*/-export const MEDIA_TYPE = {+export const MEDIA_TYPE: {[key: string]: MediaType} = {AUDIO: 'audio',PRESENTER: 'presenter',SCREENSHARE: 'screenshare',diff --git a/react/features/base/redux/ReducerRegistry.js b/react/features/base/redux/ReducerRegistry.tssimilarity index 87%rename from react/features/base/redux/ReducerRegistry.jsrename to react/features/base/redux/ReducerRegistry.tsindex fb5c9d405c..7f40cb0c8b 100644--- a/react/features/base/redux/ReducerRegistry.js+++ b/react/features/base/redux/ReducerRegistry.ts@@ -1,20 +1,18 @@-/* @flow */--import { combineReducers } from 'redux';+import { Action, combineReducers } from 'redux';import type { Reducer } from 'redux';/*** The type of the dictionary/map which associates a reducer (function) with the* name of he Redux state property managed by the reducer.*/-declare type NameReducerMap<S, A> = { [name: string]: Reducer<S, A> };+declare type NameReducerMap<S, A> = { [name: string]: Reducer<S, Action<any>> };/*** A registry for Redux reducers, allowing features to register themselves* without needing to create additional inter-feature dependencies.*/class ReducerRegistry {- _elements: NameReducerMap<*, *>;+ _elements: NameReducerMap<any, any>;/*** Creates a ReducerRegistry instance.@@ -37,7 +35,7 @@ class ReducerRegistry {* included (such as reducers from third-party modules).* @returns {Function}*/- combineReducers(additional: NameReducerMap<*, *> = {}) {+ combineReducers(additional: NameReducerMap<any, any> = {}) {// $FlowExpectedErrorreturn combineReducers({...this._elements,@@ -55,7 +53,7 @@ class ReducerRegistry {* @param {Reducer} reducer - A Redux reducer.* @returns {void}*/- register(name: string, reducer: Reducer<*, *>) {+ register(name: string, reducer: Reducer<any, any>) {this._elements[name] = reducer;}}