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
fix(analytics): Update permanent props.
Hristo Terezov26ad7cffec9c
diff --git a/react/features/analytics/actionTypes.ts b/react/features/analytics/actionTypes.tsindex ed04f64028..eec21e27ec 100644--- a/react/features/analytics/actionTypes.ts+++ b/react/features/analytics/actionTypes.ts@@ -7,3 +7,23 @@* }*/export const UPDATE_LOCAL_TRACKS_DURATION = 'UPDATE_LOCAL_TRACKS_DURATION';++/**+ * The type of (redux) action which sets the isInitialized redux prop.+ *+ * {+ * type: SET_INITIALIZED,+ * value: boolean+ * }+ */+export const SET_INITIALIZED = 'SET_INITIALIZED';++/**+ * The type of (redux) action which updates the initial permanent properties.+ *+ * {+ * type: SET_INITIAL_PERMANENT_PROPERTIES,+ * properties: Object+ * }+ */+export const SET_INITIAL_PERMANENT_PROPERTIES = 'SET_INITIAL_PERMANENT_PROPERTIES';diff --git a/react/features/analytics/actions.ts b/react/features/analytics/actions.tsnew file mode 100644index 0000000000..e3940c72b9--- /dev/null+++ b/react/features/analytics/actions.ts@@ -0,0 +1,25 @@+import { IStore } from '../app/types';+import { analytics } from '../base/lib-jitsi-meet';++import { SET_INITIAL_PERMANENT_PROPERTIES } from './actionTypes';++/**+ * Updates a permanentProperty.+ *+ * @param {Object} properties - An object with properties to be updated.+ * @returns {Function}+ */+export function setPermanentProperty(properties: Object) {+ return (dispatch: IStore['dispatch'], getState: IStore['getState']) => {+ const { isInitialized = false } = getState()['features/analytics'];++ if (isInitialized) {+ analytics.addPermanentProperties(properties);+ } else {+ dispatch({+ type: SET_INITIAL_PERMANENT_PROPERTIES,+ properties+ });+ }+ };+}diff --git a/react/features/analytics/functions.ts b/react/features/analytics/functions.tsindex 299cdf1864..2b787b2589 100644--- a/react/features/analytics/functions.ts+++ b/react/features/analytics/functions.ts@@ -159,13 +159,13 @@ export async function createHandlers({ getState }: IStore) {** @param {Store} store - The redux store in which the specified {@code action} is being dispatched.* @param {Array<Object>} handlers - The analytics handlers.- * @returns {void}+ * @returns {boolean} - True if the analytics were successfully initialized and false otherwise.*/-export function initAnalytics(store: IStore, handlers: Array<Object>) {+export function initAnalytics(store: IStore, handlers: Array<Object>): boolean {const { getState, dispatch } = store;if (!isAnalyticsEnabled(getState) || handlers.length === 0) {- return;+ return false;}const state = getState();@@ -232,7 +232,11 @@ export function initAnalytics(store: IStore, handlers: Array<Object>) {}}- analytics.addPermanentProperties(permanentProperties);+ analytics.addPermanentProperties({+ ...permanentProperties,+ ...getState()['features/analytics'].initialPermanentProperties+ });+analytics.setConferenceName(getAnalyticsRoomName(state, dispatch));// Set the handlers last, since this triggers emptying of the cache@@ -249,6 +253,8 @@ export function initAnalytics(store: IStore, handlers: Array<Object>) {}});}++ return true;}/**diff --git a/react/features/analytics/middleware.ts b/react/features/analytics/middleware.tsindex bd62ff81d5..4418d32a77 100644--- a/react/features/analytics/middleware.ts+++ b/react/features/analytics/middleware.ts@@ -5,7 +5,6 @@ import {SET_ROOM} from '../base/conference/actionTypes';import { SET_CONFIG } from '../base/config/actionTypes';-import { analytics } from '../base/lib-jitsi-meet';import { SET_NETWORK_INFO } from '../base/net-info/actionTypes';import MiddlewareRegistry from '../base/redux/MiddlewareRegistry';import {@@ -23,7 +22,8 @@ import { I_AM_VISITOR_MODE } from '../visitors/actionTypes';import { iAmVisitor } from '../visitors/functions';import { createLocalTracksDurationEvent, createNetworkInfoEvent } from './AnalyticsEvents';-import { UPDATE_LOCAL_TRACKS_DURATION } from './actionTypes';+import { SET_INITIALIZED, UPDATE_LOCAL_TRACKS_DURATION } from './actionTypes';+import { setPermanentProperty } from './actions';import { createHandlers, initAnalytics, resetAnalytics, sendAnalytics } from './functions';/**@@ -91,10 +91,10 @@ MiddlewareRegistry.register(store => next => action => {const result = next(action);const newIAmVisitor = iAmVisitor(store.getState());- analytics.addPermanentProperties({+ store.dispatch(setPermanentProperty({isVisitor: newIAmVisitor,isPromotedFromVisitor: oldIAmVisitor && !newIAmVisitor- });+ }));return result;}@@ -104,6 +104,13 @@ MiddlewareRegistry.register(store => next => action => {// the user will be redirected to another page and new instance of// Analytics will be created and initialized.resetAnalytics();++ const { dispatch } = store;++ dispatch({+ type: SET_INITIALIZED,+ value: false+ });}break;case SET_ROOM: {@@ -114,7 +121,12 @@ MiddlewareRegistry.register(store => next => action => {const result = next(action);createHandlersPromise.then(handlers => {- initAnalytics(store, handlers);+ if (initAnalytics(store, handlers)) {+ store.dispatch({+ type: SET_INITIALIZED,+ value: true+ });+ }});return result;@@ -163,9 +175,9 @@ MiddlewareRegistry.register(store => next => action => {}case SET_LOBBY_VISIBILITY:if (getIsLobbyVisible(store.getState())) {- analytics.addPermanentProperties({+ store.dispatch(setPermanentProperty({wasLobbyVisible: true- });+ }));}break;diff --git a/react/features/analytics/reducer.ts b/react/features/analytics/reducer.tsindex 342dce872a..49080fc2d0 100644--- a/react/features/analytics/reducer.ts+++ b/react/features/analytics/reducer.ts@@ -1,11 +1,17 @@import ReducerRegistry from '../base/redux/ReducerRegistry';-import { UPDATE_LOCAL_TRACKS_DURATION } from './actionTypes';+import {+ SET_INITIALIZED,+ SET_INITIAL_PERMANENT_PROPERTIES,+ UPDATE_LOCAL_TRACKS_DURATION+} from './actionTypes';/*** Initial state.*/const DEFAULT_STATE = {+ isInitialized: false,+ initialPermanentProperties: {},localTracksDuration: {audio: {startedTime: -1,@@ -34,6 +40,8 @@ interface IValue {}export interface IAnalyticsState {+ initialPermanentProperties: Object;+ isInitialized: boolean;localTracksDuration: {audio: IValue;conference: IValue;@@ -55,6 +63,20 @@ export interface IAnalyticsState {ReducerRegistry.register<IAnalyticsState>('features/analytics',(state = DEFAULT_STATE, action): IAnalyticsState => {switch (action.type) {+ case SET_INITIALIZED:+ return {+ ...state,+ initialPermanentProperties: action.value ? state.initialPermanentProperties : {},+ isInitialized: action.value+ };+ case SET_INITIAL_PERMANENT_PROPERTIES:+ return {+ ...state,+ initialPermanentProperties: {+ ...state.initialPermanentProperties,+ ...action.properties+ }+ };case UPDATE_LOCAL_TRACKS_DURATION:return {...state,diff --git a/react/features/prejoin/components/native/Prejoin.tsx b/react/features/prejoin/components/native/Prejoin.tsxindex 8fd5d0b68e..713af01fd4 100644--- a/react/features/prejoin/components/native/Prejoin.tsx+++ b/react/features/prejoin/components/native/Prejoin.tsx@@ -12,6 +12,7 @@ import {} from 'react-native';import { useDispatch, useSelector } from 'react-redux';+import { setPermanentProperty } from '../../../analytics/actions';import { appNavigate } from '../../../app/actions.native';import { IReduxState } from '../../../app/types';import { setAudioOnly } from '../../../base/audio-only/actions';@@ -112,9 +113,14 @@ const Prejoin: React.FC<IPrejoinProps> = ({ navigation }: IPrejoinProps) => {useEffect(() => {BackHandler.addEventListener('hardwareBackPress', goBack);+ dispatch(setPermanentProperty({+ wasPrejoinDisplayed: true+ }));+return () => BackHandler.removeEventListener('hardwareBackPress', goBack);- }, []);+ }, []); // dispatch is not in the dependancy list because we want the action to be dispatched only once when+ // the component is mounted.const headerLeft = () => {if (Platform.OS === 'ios') {