2025-01-22 14:34:34 +05:30
|
|
|
import React,{ type ReactNode, useEffect, useRef } from 'react';
|
|
|
|
|
import { AppState, type AppStateStatus } from 'react-native';
|
2023-08-01 17:43:25 +05:30
|
|
|
import dayJs from 'dayjs';
|
2023-10-30 06:49:47 +05:30
|
|
|
import RNFS from 'react-native-fs';
|
|
|
|
|
import fetchUpdatedRemoteConfig, {
|
|
|
|
|
FIREBASE_FETCH_TIMESTAMP,
|
|
|
|
|
} from '@services/firebaseFetchAndUpdate.service';
|
2023-08-02 13:32:18 +05:30
|
|
|
import { setItem, getItem } from '../components/utlis/storageHelper';
|
2023-08-30 15:51:58 +05:30
|
|
|
import CosmosForegroundService, {
|
2023-08-01 17:43:25 +05:30
|
|
|
type IForegroundTask,
|
2023-04-18 01:27:28 +05:30
|
|
|
} from '../services/foregroundServices/foreground.service';
|
|
|
|
|
import useIsOnline from '../hooks/useIsOnline';
|
2024-04-02 20:48:40 +05:30
|
|
|
import { getSyncTime, sendCurrentGeolocationAndBuffer } from '../hooks/capturingApi';
|
2023-08-08 11:04:32 +05:30
|
|
|
import {
|
2024-08-09 18:22:53 +05:30
|
|
|
getAppVersion,
|
2024-06-17 17:21:20 +05:30
|
|
|
} from '../components/utlis/commonFunctions';
|
2024-10-08 17:34:39 +05:30
|
|
|
|
2024-12-13 17:09:29 +05:30
|
|
|
import { setServerTimestamp } from '../reducer/foregroundServiceSlice';
|
2023-04-18 01:27:28 +05:30
|
|
|
import { logError } from '../components/utlis/errorUtils';
|
2023-05-10 12:50:20 +05:30
|
|
|
import { useAppDispatch, useAppSelector } from '../hooks';
|
|
|
|
|
import { dataSyncService } from '../services/dataSync.service';
|
2024-10-08 17:34:39 +05:30
|
|
|
import { DATA_SYNC_TIME_INTERVAL, IS_DATA_SYNC_REQUIRED } from '../constants/config';
|
2023-05-10 12:50:20 +05:30
|
|
|
import useIsLocationEnabled from '../hooks/useIsLocationEnabled';
|
2025-01-22 14:34:34 +05:30
|
|
|
import { MILLISECONDS_IN_A_MINUTE, MILLISECONDS_IN_A_SECOND } from '../../RN-UI-LIB/src/utlis/common';
|
2023-06-20 12:41:47 +05:30
|
|
|
import { getConfigData } from '../action/configActions';
|
2023-08-01 17:43:25 +05:30
|
|
|
import { AppStates } from '../types/appStates';
|
2023-08-02 13:32:18 +05:30
|
|
|
import { StorageKeys } from '../types/storageKeys';
|
2023-09-13 22:33:51 +05:30
|
|
|
import { AgentActivity } from '../types/agentActivity';
|
2023-09-15 01:45:42 +05:30
|
|
|
import {
|
2023-09-15 12:48:20 +05:30
|
|
|
getActivityTimeOnApp,
|
|
|
|
|
getActivityTimeWindowMedium,
|
|
|
|
|
getActivityTimeWindowHigh,
|
2024-05-21 16:34:48 +05:30
|
|
|
getDataSyncJobIntervalInMinutes,
|
|
|
|
|
getImageUploadJobIntervalInMinutes,
|
|
|
|
|
getVideoUploadJobIntervalInMinutes,
|
|
|
|
|
getAudioUploadJobIntervalInMinutes,
|
|
|
|
|
getCalendarAndAccountsUploadJobIntervalInMinutes,
|
2024-08-27 12:28:16 +05:30
|
|
|
getWifiDetailsUploadJobIntervalInMinutes,
|
2023-09-15 12:48:20 +05:30
|
|
|
} from './AgentActivityConfigurableConstants';
|
2023-09-13 00:40:45 +05:30
|
|
|
import { GlobalImageMap } from './CachedImage';
|
2023-09-19 12:49:35 +05:30
|
|
|
import { addClickstreamEvent } from '../services/clickstreamEventService';
|
2025-01-22 14:34:34 +05:30
|
|
|
import { BuildFlavours, CLICKSTREAM_EVENT_NAMES } from './Constants';
|
2024-03-29 15:30:06 +05:30
|
|
|
import useResyncFirebase from '@hooks/useResyncFirebase';
|
2024-08-08 15:43:45 +05:30
|
|
|
import { imageSyncService, sendImagesToServer } from '@services/imageSyncService';
|
2024-04-30 19:23:19 +05:30
|
|
|
import { sendAudiosToServer } from '@services/audioSyncService';
|
|
|
|
|
import { sendVideosToServer } from '@services/videoSyncService';
|
|
|
|
|
import { getSyncUrl } from '@services/syncJsonDataToBe';
|
2024-06-17 17:21:20 +05:30
|
|
|
import { handleCheckAndUpdatePullToRefreshStateForNearbyCases } from '@screens/allCases/utils';
|
2024-08-09 18:22:53 +05:30
|
|
|
import { getPermissionsToRequest } from '@components/utlis/PermissionUtils';
|
|
|
|
|
import { syncToLonghorn } from '../miniModules/callingAgents/screens/homeScreen/action';
|
2024-08-27 16:22:33 +05:30
|
|
|
import { getWifiDetailsSyncUrl } from '@components/utlis/WifiDetails';
|
2024-09-04 15:03:33 +05:30
|
|
|
import store from '@store';
|
2024-10-08 17:34:39 +05:30
|
|
|
import useFirestoreUpdates from '@hooks/useFirestoreUpdates';
|
|
|
|
|
import { GLOBAL } from '@constants/Global';
|
2023-04-18 01:27:28 +05:30
|
|
|
|
2024-11-27 22:56:47 +05:30
|
|
|
import { handlePostOperativeHourActivity } from '@screens/caseDetails/utils/postOperationalHourActions';
|
|
|
|
|
import { setPostOperationalHourRestrictions } from '@reducers/postOperationalHourRestrictionsSlice';
|
2024-11-06 18:23:37 +05:30
|
|
|
|
2023-04-18 01:27:28 +05:30
|
|
|
export enum FOREGROUND_TASKS {
|
|
|
|
|
GEOLOCATION = 'GEOLOCATION',
|
|
|
|
|
TIME_SYNC = 'TIME_SYNC',
|
2023-05-10 12:50:20 +05:30
|
|
|
DATA_SYNC = 'DATA_SYNC',
|
2023-05-17 20:28:49 +05:30
|
|
|
FIRESTORE_FALLBACK = 'FIRESTORE_FALLBACK',
|
2023-08-01 17:43:25 +05:30
|
|
|
UPDATE_AGENT_ACTIVENESS = 'UPDATE_AGENT_ACTIVENESS',
|
2023-09-13 22:33:51 +05:30
|
|
|
UPDATE_AGENT_ACTIVITY = 'UPDATE_AGENT_ACTIVITY',
|
2023-09-13 00:40:45 +05:30
|
|
|
DELETE_CACHE = 'DELETE_CACHE',
|
2023-10-19 18:34:25 +05:30
|
|
|
FETCH_DATA_FROM_FIREBASE = 'FETCH_DATA_FROM_FIREBASE',
|
2024-03-29 15:30:06 +05:30
|
|
|
FIREBASE_RESYNC = 'FIREBASE_RESYNC',
|
2024-04-07 16:40:01 +05:30
|
|
|
IMAGE_SYNC_JOB = 'IMAGE_SYNC_JOB',
|
2024-04-17 09:55:52 +05:30
|
|
|
IMAGE_UPLOAD_JOB = 'IMAGE_UPLOAD_JOB',
|
2024-04-30 19:23:19 +05:30
|
|
|
VIDEO_UPLOAD_JOB = 'VIDEO_UPLOAD_JOB',
|
|
|
|
|
AUDIO_UPLOAD_JOB = 'AUDIO_UPLOAD_JOB',
|
|
|
|
|
DATA_SYNC_JOB = 'DATA_SYNC_JOB',
|
2024-06-17 17:21:20 +05:30
|
|
|
NEARBY_CASES_GEOLOCATION_CHECK = 'NEARBY_CASES_GEOLOCATION_CHECK',
|
2024-08-09 18:22:53 +05:30
|
|
|
COSMOS_SYNC_WITH_LONGHORN = 'COSMOS_SYNC_WITH_LONGHORN',
|
2024-11-06 18:23:37 +05:30
|
|
|
WIFI_DETAILS_SYNC = 'WIFI_DETAILS_SYNC',
|
2023-04-18 01:27:28 +05:30
|
|
|
}
|
|
|
|
|
|
|
|
|
|
interface ITrackingComponent {
|
|
|
|
|
children?: ReactNode;
|
|
|
|
|
}
|
2023-06-13 18:53:13 +05:30
|
|
|
|
2023-08-02 13:32:18 +05:30
|
|
|
const ACTIVITY_TIME_WINDOW = 10; // 10 minutes
|
2023-04-18 01:27:28 +05:30
|
|
|
|
|
|
|
|
const TrackingComponent: React.FC<ITrackingComponent> = ({ children }) => {
|
|
|
|
|
const isOnline = useIsOnline();
|
|
|
|
|
const dispatch = useAppDispatch();
|
|
|
|
|
const appState = useRef(AppState.currentState);
|
|
|
|
|
|
2024-05-14 23:28:46 +05:30
|
|
|
const referenceId = useAppSelector((state) => state.user.user?.referenceId!);
|
2023-05-17 20:28:49 +05:30
|
|
|
|
2023-04-18 01:27:28 +05:30
|
|
|
const handleTimeSync = async () => {
|
|
|
|
|
try {
|
2023-08-08 18:45:08 +05:30
|
|
|
if (!isOnline) {
|
|
|
|
|
return;
|
|
|
|
|
}
|
2023-04-18 01:27:28 +05:30
|
|
|
const timestamp = await getSyncTime();
|
|
|
|
|
if (timestamp) {
|
2024-12-13 17:09:29 +05:30
|
|
|
dispatch(setServerTimestamp(timestamp));
|
2024-11-29 16:44:01 +05:30
|
|
|
dispatch(setPostOperationalHourRestrictions(handlePostOperativeHourActivity(timestamp)));
|
2023-04-18 01:27:28 +05:30
|
|
|
}
|
|
|
|
|
} catch (e: any) {
|
|
|
|
|
logError(e, 'Error during fetching timestamp from server.');
|
|
|
|
|
}
|
|
|
|
|
};
|
|
|
|
|
|
2024-01-04 19:17:10 +05:30
|
|
|
const resyncFirebase = useResyncFirebase();
|
2023-04-18 01:27:28 +05:30
|
|
|
|
2023-09-13 22:33:51 +05:30
|
|
|
const handleUpdateActivity = async () => {
|
|
|
|
|
const foregroundTimestamp = await getItem(StorageKeys.APP_FOREGROUND_TIMESTAMP);
|
|
|
|
|
const backgroundTimestamp = await getItem(StorageKeys.APP_BACKGROUND_TIMESTAMP);
|
2023-09-17 16:41:41 +05:30
|
|
|
const stateSetTimestamp = await getItem(StorageKeys.STATE_SET_TIMESTAMP);
|
2023-09-13 22:33:51 +05:30
|
|
|
|
2023-09-18 20:46:35 +05:30
|
|
|
if (foregroundTimestamp == null) {
|
|
|
|
|
await setItem(StorageKeys.APP_FOREGROUND_TIMESTAMP, dayJs().toString());
|
|
|
|
|
}
|
|
|
|
|
|
2023-09-13 22:33:51 +05:30
|
|
|
const foregroundTime = dayJs(foregroundTimestamp);
|
2023-09-17 16:41:41 +05:30
|
|
|
const stateSetTime = dayJs(stateSetTimestamp);
|
|
|
|
|
|
2023-09-13 22:33:51 +05:30
|
|
|
const diffBetweenCurrentTimeAndForegroundTime =
|
2023-09-15 01:45:42 +05:30
|
|
|
dayJs().diff(foregroundTime, 'seconds') < 0 ? 0 : dayJs().diff(foregroundTime, 'seconds');
|
2023-09-17 16:41:41 +05:30
|
|
|
const diffBetweenCurrentTimeAndSetStateTime =
|
|
|
|
|
dayJs().diff(stateSetTime, 'minutes') < 0 ? 0 : dayJs().diff(stateSetTime, 'minutes');
|
2023-09-13 22:33:51 +05:30
|
|
|
|
2023-09-15 12:48:20 +05:30
|
|
|
const ACTIVITY_TIME_ON_APP = getActivityTimeOnApp();
|
|
|
|
|
const ACTIVITY_TIME_WINDOW_HIGH = getActivityTimeWindowHigh();
|
|
|
|
|
const ACTIVITY_TIME_WINDOW_MEDIUM = getActivityTimeWindowMedium();
|
2023-09-13 22:33:51 +05:30
|
|
|
|
2023-09-18 20:46:35 +05:30
|
|
|
const isStateSetTimeWithinHighRange =
|
|
|
|
|
diffBetweenCurrentTimeAndSetStateTime < ACTIVITY_TIME_WINDOW_HIGH;
|
|
|
|
|
const isStateSetTimeWithinMediumRange =
|
|
|
|
|
diffBetweenCurrentTimeAndSetStateTime < ACTIVITY_TIME_WINDOW_MEDIUM;
|
2023-09-13 22:33:51 +05:30
|
|
|
const isForegroundTimeAfterBackground = dayJs(foregroundTimestamp).isAfter(backgroundTimestamp);
|
|
|
|
|
|
2023-09-15 01:45:42 +05:30
|
|
|
if (AppState.currentState === AppStates.ACTIVE) {
|
|
|
|
|
if (diffBetweenCurrentTimeAndForegroundTime >= ACTIVITY_TIME_ON_APP) {
|
|
|
|
|
await setItem(StorageKeys.USER_ACTIVITY_ON_APP, AgentActivity.HIGH);
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|
2023-09-13 22:33:51 +05:30
|
|
|
if (isForegroundTimeAfterBackground) {
|
2023-09-15 01:45:42 +05:30
|
|
|
if (diffBetweenCurrentTimeAndForegroundTime >= ACTIVITY_TIME_ON_APP) {
|
2023-09-13 22:33:51 +05:30
|
|
|
await setItem(StorageKeys.USER_ACTIVITY_ON_APP, AgentActivity.HIGH);
|
|
|
|
|
}
|
2023-09-18 20:46:35 +05:30
|
|
|
} else if (isStateSetTimeWithinHighRange) {
|
|
|
|
|
} else if (isStateSetTimeWithinMediumRange) {
|
2023-09-17 16:41:41 +05:30
|
|
|
await setItem(StorageKeys.USER_ACTIVITY_ON_APP, AgentActivity.MEDIUM);
|
2023-09-18 20:46:35 +05:30
|
|
|
} else {
|
2023-09-13 22:33:51 +05:30
|
|
|
await setItem(StorageKeys.USER_ACTIVITY_ON_APP, AgentActivity.LOW);
|
|
|
|
|
}
|
|
|
|
|
};
|
|
|
|
|
|
2023-09-13 00:40:45 +05:30
|
|
|
const deleteCache = () => {
|
|
|
|
|
const directoryPath = RNFS.CachesDirectoryPath;
|
|
|
|
|
const currentDate = new Date().getTime();
|
|
|
|
|
|
|
|
|
|
RNFS.readdir(directoryPath)
|
|
|
|
|
.then((files) => {
|
|
|
|
|
for (const file of files) {
|
|
|
|
|
const filePath = `${directoryPath}/${file}`;
|
2024-03-29 15:30:06 +05:30
|
|
|
if (!file.endsWith('jpg') || !file.endsWith('pdf')) {
|
2023-09-13 00:40:45 +05:30
|
|
|
continue;
|
|
|
|
|
}
|
|
|
|
|
RNFS.stat(filePath)
|
2024-03-29 15:30:06 +05:30
|
|
|
.then(async (fileStat) => {
|
2023-09-13 00:40:45 +05:30
|
|
|
// Calculate the age of the file in milliseconds
|
|
|
|
|
const fileAgeMs = currentDate - new Date(fileStat.mtime).getTime();
|
|
|
|
|
|
|
|
|
|
// Check if the file is older than 30 days (30 days = 30 * 24 * 60 * 60 * 1000 milliseconds)
|
|
|
|
|
|
|
|
|
|
if (fileAgeMs > 30 * 24 * 60 * 60 * 1000) {
|
|
|
|
|
delete GlobalImageMap[filePath];
|
2024-03-29 15:30:06 +05:30
|
|
|
await RNFS.unlink(filePath); // Delete the file
|
2023-09-13 00:40:45 +05:30
|
|
|
}
|
|
|
|
|
})
|
|
|
|
|
.then(() => {
|
|
|
|
|
console.log(`Deleted old file: ${file}`);
|
|
|
|
|
})
|
|
|
|
|
.catch((error) => {
|
|
|
|
|
console.error(`Error deleting file: ${file}`, error);
|
|
|
|
|
});
|
|
|
|
|
}
|
|
|
|
|
})
|
|
|
|
|
.catch((error) => {
|
|
|
|
|
console.error('Error reading directory:', error);
|
|
|
|
|
});
|
|
|
|
|
};
|
|
|
|
|
|
2023-10-19 18:34:25 +05:30
|
|
|
const handleFetchUpdatedDataFromFirebase = async () => {
|
|
|
|
|
const currentTimestamp: number = Date.now();
|
|
|
|
|
if (
|
2024-03-29 15:30:06 +05:30
|
|
|
FIREBASE_FETCH_TIMESTAMP &&
|
|
|
|
|
currentTimestamp - FIREBASE_FETCH_TIMESTAMP > 15 * MILLISECONDS_IN_A_MINUTE
|
2023-10-19 18:34:25 +05:30
|
|
|
) {
|
|
|
|
|
fetchUpdatedRemoteConfig();
|
|
|
|
|
}
|
|
|
|
|
};
|
|
|
|
|
|
2024-08-09 18:22:53 +05:30
|
|
|
|
|
|
|
|
const checkPermissions = async () => {
|
|
|
|
|
const permissionsToRequest = await getPermissionsToRequest();
|
|
|
|
|
const allPermissionsGranted = permissionsToRequest?.length === 0;
|
|
|
|
|
return allPermissionsGranted;
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
const appVersion = getAppVersion();
|
|
|
|
|
|
|
|
|
|
const taskSyncToLonghorn = async () => {
|
|
|
|
|
const allPermissionsGranted = await checkPermissions();
|
2024-09-04 15:03:33 +05:30
|
|
|
const agentId= store.getState().user.user?.referenceId!;
|
|
|
|
|
if(!agentId) {
|
|
|
|
|
addClickstreamEvent(CLICKSTREAM_EVENT_NAMES.FA_COSMOS_SYNC_TO_LONGHORN_ERROR);
|
|
|
|
|
return;
|
|
|
|
|
}
|
2024-08-26 16:47:07 +05:30
|
|
|
await syncToLonghorn({allPermissionsGranted, agentId, appVersion, isSyncToastEnabled: false});
|
2024-08-09 18:22:53 +05:30
|
|
|
};
|
|
|
|
|
|
2023-04-18 01:27:28 +05:30
|
|
|
const tasks: IForegroundTask[] = [
|
|
|
|
|
{
|
|
|
|
|
taskId: FOREGROUND_TASKS.TIME_SYNC,
|
|
|
|
|
task: handleTimeSync,
|
2023-05-17 20:28:49 +05:30
|
|
|
delay: 5 * MILLISECONDS_IN_A_MINUTE, // 5 minutes,
|
2023-04-18 01:27:28 +05:30
|
|
|
onLoop: true,
|
|
|
|
|
},
|
|
|
|
|
{
|
|
|
|
|
taskId: FOREGROUND_TASKS.GEOLOCATION,
|
2024-04-02 20:48:40 +05:30
|
|
|
task: () => dispatch(sendCurrentGeolocationAndBuffer(appState.current)),
|
2023-05-17 20:28:49 +05:30
|
|
|
delay: 3 * MILLISECONDS_IN_A_MINUTE, // 3 minutes
|
|
|
|
|
onLoop: true,
|
|
|
|
|
},
|
2023-08-01 17:43:25 +05:30
|
|
|
{
|
2023-09-13 22:33:51 +05:30
|
|
|
taskId: FOREGROUND_TASKS.UPDATE_AGENT_ACTIVITY,
|
|
|
|
|
task: handleUpdateActivity,
|
2023-08-02 13:32:18 +05:30
|
|
|
delay: ACTIVITY_TIME_WINDOW * MILLISECONDS_IN_A_MINUTE, // 10 minutes
|
2023-08-01 17:43:25 +05:30
|
|
|
onLoop: true,
|
|
|
|
|
},
|
2023-09-13 00:40:45 +05:30
|
|
|
{
|
|
|
|
|
taskId: FOREGROUND_TASKS.DELETE_CACHE,
|
|
|
|
|
task: deleteCache,
|
2023-09-14 17:39:26 +05:30
|
|
|
delay: DATA_SYNC_TIME_INTERVAL,
|
2023-09-13 00:40:45 +05:30
|
|
|
onLoop: true,
|
|
|
|
|
},
|
2023-10-19 18:34:25 +05:30
|
|
|
{
|
|
|
|
|
taskId: FOREGROUND_TASKS.FETCH_DATA_FROM_FIREBASE,
|
|
|
|
|
task: handleFetchUpdatedDataFromFirebase,
|
2023-10-30 06:49:47 +05:30
|
|
|
delay: 60 * MILLISECONDS_IN_A_MINUTE, // 60 minutes
|
2024-04-07 16:40:01 +05:30
|
|
|
onLoop: true,
|
|
|
|
|
},
|
|
|
|
|
|
|
|
|
|
{
|
|
|
|
|
taskId: FOREGROUND_TASKS.IMAGE_SYNC_JOB,
|
2024-04-17 09:55:52 +05:30
|
|
|
task: imageSyncService,
|
2024-05-21 16:34:48 +05:30
|
|
|
delay: getDataSyncJobIntervalInMinutes() * MILLISECONDS_IN_A_MINUTE, // 10 minutes
|
2024-04-17 09:55:52 +05:30
|
|
|
onLoop: true,
|
|
|
|
|
},
|
|
|
|
|
{
|
|
|
|
|
taskId: FOREGROUND_TASKS.IMAGE_UPLOAD_JOB,
|
|
|
|
|
task: sendImagesToServer,
|
2024-05-21 16:34:48 +05:30
|
|
|
delay: getImageUploadJobIntervalInMinutes() * MILLISECONDS_IN_A_MINUTE, // 10 minutes
|
2024-04-30 19:23:19 +05:30
|
|
|
onLoop: true,
|
|
|
|
|
},
|
|
|
|
|
{
|
|
|
|
|
taskId: FOREGROUND_TASKS.VIDEO_UPLOAD_JOB,
|
|
|
|
|
task: sendVideosToServer,
|
2024-05-21 16:34:48 +05:30
|
|
|
delay: getVideoUploadJobIntervalInMinutes() * MILLISECONDS_IN_A_MINUTE, // 10 minutes
|
2024-04-30 19:23:19 +05:30
|
|
|
onLoop: true,
|
|
|
|
|
},
|
|
|
|
|
{
|
|
|
|
|
taskId: FOREGROUND_TASKS.AUDIO_UPLOAD_JOB,
|
|
|
|
|
task: sendAudiosToServer,
|
2024-05-21 16:34:48 +05:30
|
|
|
delay: getAudioUploadJobIntervalInMinutes() * MILLISECONDS_IN_A_MINUTE, // 10 minutes
|
2024-04-30 19:23:19 +05:30
|
|
|
onLoop: true,
|
|
|
|
|
},
|
|
|
|
|
{
|
|
|
|
|
taskId: FOREGROUND_TASKS.DATA_SYNC_JOB,
|
|
|
|
|
task: getSyncUrl,
|
2024-05-21 16:34:48 +05:30
|
|
|
delay: getCalendarAndAccountsUploadJobIntervalInMinutes() * MILLISECONDS_IN_A_MINUTE, // 12 hours
|
2024-04-24 10:17:37 +05:30
|
|
|
onLoop: true,
|
2024-06-17 17:21:20 +05:30
|
|
|
},
|
|
|
|
|
{
|
|
|
|
|
taskId: FOREGROUND_TASKS.NEARBY_CASES_GEOLOCATION_CHECK,
|
|
|
|
|
task: handleCheckAndUpdatePullToRefreshStateForNearbyCases,
|
|
|
|
|
delay: 3 * MILLISECONDS_IN_A_MINUTE, // 3 minutes
|
|
|
|
|
onLoop: true,
|
|
|
|
|
},
|
2024-08-26 19:06:34 +05:30
|
|
|
{
|
|
|
|
|
taskId: FOREGROUND_TASKS.WIFI_DETAILS_SYNC,
|
2024-08-27 16:22:33 +05:30
|
|
|
task: getWifiDetailsSyncUrl,
|
2024-09-02 15:31:11 +05:30
|
|
|
delay: getWifiDetailsUploadJobIntervalInMinutes() * MILLISECONDS_IN_A_MINUTE, // 30 minutes
|
2024-08-26 19:06:34 +05:30
|
|
|
onLoop: true,
|
|
|
|
|
},
|
2023-04-18 01:27:28 +05:30
|
|
|
];
|
2023-05-10 12:50:20 +05:30
|
|
|
|
2024-12-02 15:41:47 +05:30
|
|
|
if(GLOBAL?.BUILD_FLAVOUR === BuildFlavours.CALLING_AGENTS) {
|
|
|
|
|
tasks.push({
|
|
|
|
|
taskId: FOREGROUND_TASKS.COSMOS_SYNC_WITH_LONGHORN,
|
|
|
|
|
task: taskSyncToLonghorn,
|
|
|
|
|
delay: 15 * MILLISECONDS_IN_A_SECOND,
|
|
|
|
|
onLoop: true,
|
|
|
|
|
});
|
|
|
|
|
}
|
|
|
|
|
|
2023-08-08 18:45:08 +05:30
|
|
|
const handleDataSync = () => {
|
|
|
|
|
if (!isOnline) {
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
dataSyncService();
|
|
|
|
|
};
|
|
|
|
|
|
2023-05-10 12:50:20 +05:30
|
|
|
if (IS_DATA_SYNC_REQUIRED) {
|
|
|
|
|
tasks.push({
|
|
|
|
|
taskId: FOREGROUND_TASKS.DATA_SYNC,
|
2023-08-09 16:48:22 +05:30
|
|
|
delay:
|
|
|
|
|
GLOBAL?.BUILD_FLAVOUR === 'callingAgents'
|
2023-08-23 14:36:36 +05:30
|
|
|
? 5 * MILLISECONDS_IN_A_MINUTE
|
|
|
|
|
: DATA_SYNC_TIME_INTERVAL,
|
2023-08-08 18:45:08 +05:30
|
|
|
task: handleDataSync,
|
2023-05-10 12:50:20 +05:30
|
|
|
onLoop: true,
|
|
|
|
|
});
|
|
|
|
|
}
|
|
|
|
|
|
2024-08-26 16:47:07 +05:30
|
|
|
|
|
|
|
|
|
|
|
|
|
|
2023-09-15 01:45:42 +05:30
|
|
|
const userActivityUpdateOnBackground = async () => {
|
|
|
|
|
const foregroundTimestamp = await getItem(StorageKeys.APP_FOREGROUND_TIMESTAMP);
|
|
|
|
|
const backgroundTimestamp = await getItem(StorageKeys.APP_BACKGROUND_TIMESTAMP);
|
|
|
|
|
const foregroundTime = dayJs(foregroundTimestamp);
|
|
|
|
|
const backgroundTime = dayJs(backgroundTimestamp);
|
|
|
|
|
const diffBetweenBackgroundAndForegroundTime = dayJs(backgroundTime).diff(
|
|
|
|
|
foregroundTime,
|
|
|
|
|
'seconds'
|
|
|
|
|
);
|
2023-09-15 12:48:20 +05:30
|
|
|
const ACTIVITY_TIME_ON_APP = getActivityTimeOnApp();
|
2023-09-15 01:45:42 +05:30
|
|
|
|
|
|
|
|
if (diffBetweenBackgroundAndForegroundTime >= ACTIVITY_TIME_ON_APP) {
|
|
|
|
|
await setItem(StorageKeys.USER_ACTIVITY_ON_APP, AgentActivity.HIGH);
|
2023-09-17 16:41:41 +05:30
|
|
|
await setItem(StorageKeys.STATE_SET_TIMESTAMP, dayJs().toString());
|
2023-09-15 01:45:42 +05:30
|
|
|
}
|
|
|
|
|
};
|
|
|
|
|
|
2023-04-18 01:27:28 +05:30
|
|
|
const handleAppStateChange = async (nextAppState: AppStateStatus) => {
|
|
|
|
|
// App comes to foreground from background
|
2023-08-04 13:25:05 +05:30
|
|
|
const now = dayJs().toString();
|
2023-08-01 17:43:25 +05:30
|
|
|
if (nextAppState === AppStates.ACTIVE) {
|
2023-08-02 13:32:18 +05:30
|
|
|
await setItem(StorageKeys.APP_FOREGROUND_TIMESTAMP, now);
|
2023-09-19 12:49:35 +05:30
|
|
|
addClickstreamEvent(CLICKSTREAM_EVENT_NAMES.AV_APP_FOREGROUND, { now });
|
2024-02-13 19:31:04 +05:30
|
|
|
handleTimeSync();
|
2023-06-20 12:41:47 +05:30
|
|
|
dispatch(getConfigData());
|
2023-08-30 15:51:58 +05:30
|
|
|
CosmosForegroundService.start(tasks);
|
2024-01-04 19:17:10 +05:30
|
|
|
resyncFirebase();
|
2023-04-18 01:27:28 +05:30
|
|
|
}
|
2023-08-02 13:32:18 +05:30
|
|
|
if (nextAppState === AppStates.BACKGROUND) {
|
|
|
|
|
await setItem(StorageKeys.APP_BACKGROUND_TIMESTAMP, now);
|
2023-09-15 01:45:42 +05:30
|
|
|
userActivityUpdateOnBackground();
|
2023-09-19 12:49:35 +05:30
|
|
|
addClickstreamEvent(CLICKSTREAM_EVENT_NAMES.AV_APP_BACKGROUND, { now });
|
2023-08-01 17:43:25 +05:30
|
|
|
}
|
2023-04-18 01:27:28 +05:30
|
|
|
appState.current = nextAppState;
|
|
|
|
|
};
|
|
|
|
|
|
2023-06-06 20:05:01 +05:30
|
|
|
useEffect(() => {
|
2025-01-07 15:47:18 +05:30
|
|
|
if (!referenceId) {
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
dispatch(getConfigData());
|
2023-06-06 20:05:01 +05:30
|
|
|
}, []);
|
|
|
|
|
|
2023-04-18 01:27:28 +05:30
|
|
|
useEffect(() => {
|
2024-08-26 16:47:07 +05:30
|
|
|
const appStateSubscription = AppState.addEventListener('change', handleAppStateChange);
|
2023-09-19 15:09:37 +05:30
|
|
|
CosmosForegroundService.start(tasks);
|
2023-06-20 15:50:22 +05:30
|
|
|
return () => {
|
|
|
|
|
appStateSubscription?.remove();
|
|
|
|
|
};
|
2023-08-08 18:45:08 +05:30
|
|
|
}, []);
|
2023-04-18 01:27:28 +05:30
|
|
|
|
2023-05-10 12:50:20 +05:30
|
|
|
useIsLocationEnabled();
|
|
|
|
|
|
2024-10-08 17:34:39 +05:30
|
|
|
// Firestore listener hook
|
|
|
|
|
useFirestoreUpdates();
|
|
|
|
|
|
2023-04-18 01:27:28 +05:30
|
|
|
return <>{children}</>;
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
export default TrackingComponent;
|