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
sdk(react-native-sdk): error fixes (#13549)
Calinteodor27c62b3d7874
diff --git a/react/features/mobile/background/actionTypes.ts b/react/features/mobile/background/actionTypes.tsindex 4b0639a201..942fff56ab 100644--- a/react/features/mobile/background/actionTypes.ts+++ b/react/features/mobile/background/actionTypes.ts@@ -1,14 +1,14 @@/**- * The type of redux action to set the AppState API change event listener.+ * The type of redux action used for app state subscription.** {- * type: _SET_APP_STATE_LISTENER,- * listener: Function+ * type: _SET_APP_STATE_SUBSCRIPTION,+ * subscription: NativeEventSubscription* }** @protected*/-export const _SET_APP_STATE_LISTENER = '_SET_APP_STATE_LISTENER';+export const _SET_APP_STATE_SUBSCRIPTION = '_SET_APP_STATE_SUBSCRIPTION';/*** The type of redux action which signals that the app state has changed (indiff --git a/react/features/mobile/background/actions.ts b/react/features/mobile/background/actions.tsindex cfb65f9fbc..c9a60fb990 100644--- a/react/features/mobile/background/actions.ts+++ b/react/features/mobile/background/actions.ts@@ -1,19 +1,21 @@-import { APP_STATE_CHANGED, _SET_APP_STATE_LISTENER } from './actionTypes';+import { NativeEventSubscription } from 'react-native';++import { APP_STATE_CHANGED, _SET_APP_STATE_SUBSCRIPTION } from './actionTypes';/**- * Sets the listener to be used with React Native's AppState API.+ * Sets subscription for app state.*- * @param {Function} listener - Function to be set as the change event listener.- * @protected+ * @param {Function} subscription - Subscription for the native event.+ * @private* @returns {{- * type: _SET_APP_STATE_LISTENER,- * listener: Function+ * type: _SET_APP_STATE_SUBSCRIPTION,+ * subscription: NativeEventSubscription* }}*/-export function _setAppStateListener(listener?: Function) {+export function _setAppStateSubscription(subscription?: NativeEventSubscription) {return {- type: _SET_APP_STATE_LISTENER,- listener+ type: _SET_APP_STATE_SUBSCRIPTION,+ subscription};}diff --git a/react/features/mobile/background/middleware.native.ts b/react/features/mobile/background/middleware.native.tsindex 081c43dc59..b001013214 100644--- a/react/features/mobile/background/middleware.native.ts+++ b/react/features/mobile/background/middleware.native.ts@@ -5,11 +5,7 @@ import { IStore } from '../../app/types';import { APP_WILL_MOUNT, APP_WILL_UNMOUNT } from '../../base/app/actionTypes';import MiddlewareRegistry from '../../base/redux/MiddlewareRegistry';-import { _SET_APP_STATE_LISTENER } from './actionTypes';-import {- _setAppStateListener as _setAppStateListenerA,- appStateChanged-} from './actions';+import { _setAppStateSubscription, appStateChanged } from './actions';/*** Middleware that captures App lifetime actions and subscribes to application@@ -23,18 +19,16 @@ import {*/MiddlewareRegistry.register(store => next => action => {switch (action.type) {- case _SET_APP_STATE_LISTENER:- return _setAppStateListenerF(store, next, action);case APP_WILL_MOUNT: {const { dispatch } = store;- dispatch(_setAppStateListenerA(_onAppStateChange.bind(undefined, dispatch)));+ _setAppStateListener(store, next, action, _onAppStateChange.bind(undefined, dispatch));break;}case APP_WILL_UNMOUNT:- store.dispatch(_setAppStateListenerA(undefined));+ _setAppStateListener(store, next, action, undefined);break;}@@ -65,19 +59,16 @@ function _onAppStateChange(dispatch: IStore['dispatch'], appState: string) {* specified action to the specified store.* @param {Action} action - The redux action {@code _SET_IMMERSIVE_LISTENER}* which is being dispatched in the specified store.+ * @param {any} listener - Listener for app state status.* @private* @returns {Object} The value returned by {@code next(action)}.*/-function _setAppStateListenerF({ getState }: IStore, next: Function, action: AnyAction) {- // Remove the old AppState listener and add the new one.- const { appStateListener: oldListener } = getState()['features/background'];+function _setAppStateListener({ dispatch, getState }: IStore, next: Function, action: AnyAction, listener: any) {+ const { subscription } = getState()['features/background'];const result = next(action);- const { appStateListener: newListener } = getState()['features/background'];- if (oldListener !== newListener) {- oldListener && AppState.removeEventListener('change', oldListener);- newListener && AppState.addEventListener('change', newListener);- }+ subscription?.remove();+ listener && dispatch(_setAppStateSubscription(AppState.addEventListener('change', listener)));return result;}diff --git a/react/features/mobile/background/reducer.ts b/react/features/mobile/background/reducer.tsindex 142bb75aa0..8187524325 100644--- a/react/features/mobile/background/reducer.ts+++ b/react/features/mobile/background/reducer.ts@@ -1,15 +1,12 @@-import { AppStateStatus } from 'react-native';+import { NativeEventSubscription } from 'react-native';import ReducerRegistry from '../../base/redux/ReducerRegistry';-import {- APP_STATE_CHANGED,- _SET_APP_STATE_LISTENER-} from './actionTypes';+import { APP_STATE_CHANGED, _SET_APP_STATE_SUBSCRIPTION } from './actionTypes';export interface IBackgroundState {appState: string;- appStateListener?: (state: AppStateStatus) => void;+ subscription?: NativeEventSubscription;}/**@@ -21,10 +18,11 @@ const DEFAULT_STATE = {ReducerRegistry.register<IBackgroundState>('features/background', (state = DEFAULT_STATE, action): IBackgroundState => {switch (action.type) {- case _SET_APP_STATE_LISTENER:++ case _SET_APP_STATE_SUBSCRIPTION:return {...state,- appStateListener: action.listener+ subscription: action.subscription};case APP_STATE_CHANGED:diff --git a/react/features/mobile/react-native-sdk/middleware.js b/react/features/mobile/react-native-sdk/middleware.jsindex 6853074ed3..c808dbf508 100644--- a/react/features/mobile/react-native-sdk/middleware.js+++ b/react/features/mobile/react-native-sdk/middleware.js@@ -23,13 +23,13 @@ const externalAPIEnabled = isExternalAPIAvailable();switch (type) {case READY_TO_CLOSE:- rnSdkHandlers.onReadyToClose && rnSdkHandlers.onReadyToClose();+ rnSdkHandlers?.onReadyToClose && rnSdkHandlers?.onReadyToClose();break;case CONFERENCE_JOINED:- rnSdkHandlers.onConferenceJoined && rnSdkHandlers.onConferenceJoined();+ rnSdkHandlers?.onConferenceJoined && rnSdkHandlers?.onConferenceJoined();break;case CONFERENCE_WILL_JOIN:- rnSdkHandlers.onConferenceWillJoin && rnSdkHandlers.onConferenceWillJoin();+ rnSdkHandlers?.onConferenceWillJoin && rnSdkHandlers?.onConferenceWillJoin();break;case CONFERENCE_LEFT:// Props are torn down at this point, perhaps need to leave this one out@@ -38,7 +38,7 @@ const externalAPIEnabled = isExternalAPIAvailable();const { participant } = action;const participantInfo = participantToParticipantInfo(participant);- rnSdkHandlers.onParticipantJoined && rnSdkHandlers.onParticipantJoined(participantInfo);+ rnSdkHandlers?.onParticipantJoined && rnSdkHandlers?.onParticipantJoined(participantInfo);break;}}