expo-geofencing
Version:
Production-ready geofencing and activity recognition for Expo React Native with offline support, security features, and enterprise-grade reliability
79 lines (78 loc) • 2.44 kB
TypeScript
import { GeofenceRegion } from './index';
export interface OfflineGeofence extends GeofenceRegion {
isActive: boolean;
lastEvaluated: number;
metadata?: Record<string, any>;
}
export interface LocationPoint {
latitude: number;
longitude: number;
accuracy?: number;
timestamp: number;
}
export interface OfflineEvent {
id: string;
type: 'enter' | 'exit';
regionId: string;
location: LocationPoint;
timestamp: number;
synced: boolean;
}
export interface NetworkStatus {
isConnected: boolean;
connectionType: 'wifi' | 'cellular' | 'none';
isExpensive: boolean;
lastConnected: number;
}
export declare class OfflineManager {
private geofences;
private pendingEvents;
private networkStatus;
private syncCallbacks;
private syncInProgress;
private retryTimeouts;
constructor();
addGeofence(geofence: GeofenceRegion): void;
removeGeofence(regionId: string): void;
updateGeofence(regionId: string, updates: Partial<OfflineGeofence>): void;
getGeofences(): OfflineGeofence[];
getActiveGeofences(): OfflineGeofence[];
evaluateLocation(location: LocationPoint): OfflineEvent[];
updateNetworkStatus(status: Partial<NetworkStatus>): void;
getNetworkStatus(): NetworkStatus;
addSyncCallback(callback: (events: OfflineEvent[]) => Promise<void>): void;
removeSyncCallback(callback: (events: OfflineEvent[]) => Promise<void>): void;
syncPendingEvents(): Promise<{
success: boolean;
synced: number;
failed: number;
}>;
getPendingEvents(): OfflineEvent[];
getPendingEventsCount(): number;
clearSyncedEvents(): void;
forceSyncAttempt(): Promise<{
success: boolean;
synced: number;
failed: number;
}>;
private batchEvents;
private scheduleSyncAttempt;
private calculateDistance;
private toRadians;
private generateEventId;
private setupNetworkMonitoring;
private setupPeriodicSync;
getBatchSizeForNetwork(): number;
prioritizeEvents(): OfflineEvent[];
compressEvents(events: OfflineEvent[]): string;
decompressEvents(compressed: string): OfflineEvent[];
getStatistics(): {
totalGeofences: number;
activeGeofences: number;
pendingEvents: number;
syncedEvents: number;
lastSyncAttempt: number;
networkStatus: NetworkStatus;
};
cleanup(): void;
}