Files
address-verification-app/index.js

93 lines
3.3 KiB
JavaScript
Raw Normal View History

2022-11-30 10:13:33 +05:30
/**
* @format
*/
2024-01-24 16:00:09 +05:30
import { AppRegistry, Platform } from 'react-native';
2022-11-30 10:13:33 +05:30
import App from './App';
import { name as appName } from './app.json';
2022-12-01 11:21:46 +05:30
import database from '@react-native-firebase/database';
import { LogBox } from 'react-native';
import ReactNativeForegroundService from '@supersami/rn-foreground-service';
2024-01-24 16:00:09 +05:30
import notifee from '@notifee/react-native';
2024-01-30 15:34:40 +05:30
import { handleNotificationView, handlePushNotification } from '@hooks/useFCM/useFCM';
2024-01-24 16:00:09 +05:30
import messaging from '@react-native-firebase/messaging';
2024-02-02 15:08:48 +05:30
import CosmosForegroundService, {
FOREGROUND_SERVICE_CONFIG,
} from '@services/foregroundServices/foreground.service';
2024-01-30 15:34:40 +05:30
import axiosInstance, { ApiKeys, getApiUrl } from '@components/utlis/apiHelper';
import { StorageKeys } from '@interfaces/storageKeys';
import { AgentActivity } from '@interfaces/agentActivity';
import { FOREGROUND_TASKS } from '@common/TrackingComponent';
import { MILLISECONDS_IN_A_MINUTE } from '@rn-ui-lib/utils/common';
import Geolocation from 'react-native-geolocation-service';
2024-02-02 15:08:48 +05:30
import ForegroundService from '@supersami/rn-foreground-service';
import { getItem } from '@components/utlis/storageHelper';
import { AppState } from 'react-native';
2024-02-07 21:30:13 +05:30
import { logError } from '@components/utlis/errorUtils';
if (__DEV__) {
LogBox.ignoreAllLogs();
}
2022-12-01 11:21:46 +05:30
2024-02-07 21:30:13 +05:30
// TODO: Can use this code for starting fgs poc
// const geolocationForegroundTask = async () => {
// Geolocation.getCurrentPosition(async (position) => {
// const { latitude, longitude, accuracy } = position.coords || {};
// if (!latitude || !longitude || !accuracy) return;
2024-01-30 15:34:40 +05:30
2024-02-07 21:30:13 +05:30
// const isActiveOnApp = (await getItem(StorageKeys.IS_USER_ACTIVE)) || false;
// const userActivityonApp =
// (await getItem(StorageKeys.USER_ACTIVITY_ON_APP)) || AgentActivity.LOW;
2024-01-30 15:34:40 +05:30
2024-02-07 21:30:13 +05:30
// const geolocation = [
// {
// latitude,
// longitude,
// accuracy,
// timestamp: Date.now(),
// isActiveOnApp: Boolean(isActiveOnApp),
// userActivityOnApp: String(userActivityonApp),
// },
// ];
// axiosInstance.post(getApiUrl(ApiKeys.SEND_LOCATION), geolocation, {
// headers: {
// donotHandleError: 'true',
// },
// });
// });
// };
2024-01-24 16:00:09 +05:30
// Background push notification handler
2024-01-30 15:34:40 +05:30
messaging().setBackgroundMessageHandler(async (remoteMessage) => {
2024-01-24 16:00:09 +05:30
const { data } = remoteMessage || {};
if (data?.payload) {
2024-02-07 21:30:13 +05:30
try {
const notification = JSON.parse(data.payload);
if (notification?.showAsPn) {
handlePushNotification(notification, true);
}
} catch (err) {
logError(err, 'Error in parsing background push notification');
2024-01-30 15:34:40 +05:30
}
2024-02-02 15:08:48 +05:30
// TODO: Try to start foreground service if not working.
// const isForegroundServiceRunning = await ForegroundService.is_running();
// console.log('isForegroundServiceRunning::', isForegroundServiceRunning);
// if (!isForegroundServiceRunning) {
// ForegroundService.add_task(geolocationForegroundTask, {
// delay: 6000,
// onLoop: true,
// taskId: FOREGROUND_TASKS.GEOLOCATION,
// });
// ForegroundService.start(FOREGROUND_SERVICE_CONFIG);
// }
2024-01-24 16:00:09 +05:30
}
});
2024-02-02 15:08:48 +05:30
notifee.onBackgroundEvent(async (event) => {
handleNotificationView(event, true);
});
2024-01-24 16:00:09 +05:30
2022-12-01 11:21:46 +05:30
database().setPersistenceEnabled(true);
2023-04-18 01:27:28 +05:30
ReactNativeForegroundService.register();
2022-11-30 10:13:33 +05:30
AppRegistry.registerComponent(appName, () => App);