@mostajs/geo-tracker
v0.1.0
Published
Suivi de position temps réel pour @mostajs — orchestre @mostajs/gps (acquérir) + @mostajs/geo (distance) : anti-spam (temps+distance), publication REST, file + retry hors-ligne, wake-lock, lifecycle/état. Cœur agnostique + hook React.
Maintainers
Readme
@mostajs/geo-tracker
Auteur : Dr Hamid MADANI [email protected]
Suivi de position temps réel. Orchestre @mostajs/gps (acquérir) + @mostajs/geo
(distance) : anti-spam (temps + distance), publication REST, file + retry
hors-ligne, wake-lock, lifecycle/état. Cœur agnostique + hook React.
Cœur
import { createTracker, createRestPublisher } from '@mostajs/geo-tracker'
import { watch } from '@mostajs/gps'
import { distance } from '@mostajs/geo'
const tracker = createTracker({
watch, // ← @mostajs/gps (sinon repli navigator.geolocation)
distance, // ← @mostajs/geo (sinon repli haversine)
publish: { // publisher REST par défaut (net multi-projet)
endpoint: `/${course}/api/v1/Position`,
apiKey, // → en-tête x-api-key
mapFix: (f) => ({ courseId, cyclistId, lat: f.lat, lon: f.lon, at: new Date(f.at).toISOString() }),
},
minIntervalMs: 3000, // n'envoie pas plus d'1 fix / 3 s
minDistanceM: 8, // ni si déplacement < 8 m
wakeLock: true, // garde l'écran allumé
onState: (s) => console.log(s.phase, s.sent, s.queued),
})
tracker.start() /* … */ tracker.stop()publish accepte aussi un Publisher custom : (fixes) => Promise<void> (throw → retry).
Hook React
import { useTracker } from '@mostajs/geo-tracker/react'
const t = useTracker({ publish: { endpoint, apiKey, mapFix }, minIntervalMs: 3000 })
// t.phase ('idle'|'acquiring'|'tracking'|'error'), t.sent, t.queued, t.lastFix, t.active
return <button onClick={t.active ? t.stop : t.start}>{t.active ? 'Arrêter' : 'Suivre'}</button>Garanties
- Anti-spam : un fix n'est publié que si
≥ minIntervalMsET≥ minDistanceMdepuis le dernier. - Résilience : un échec de publication garde le fix en file (borne
maxQueue) et réessaie (flushIntervalMs). - Composable :
watch/distance/wakeLockinjectables (gps/geo) ; replis intégrés → buildable seul.
Tests : node test-scripts/test-tracker-core.mjs.
