Transmission plus immédiate via websockets
This commit is contained in:
@ -1,9 +1,10 @@
|
||||
import * as Location from 'expo-location'
|
||||
import * as TaskManager from 'expo-task-manager'
|
||||
import { Platform } from 'react-native'
|
||||
import { setLastLocation } from './features/location/locationSlice'
|
||||
import { PlayerLocation, setLastLocation } from './features/location/locationSlice'
|
||||
import store from './store'
|
||||
import { useEffect } from 'react'
|
||||
import { socket } from './socket'
|
||||
|
||||
const LOCATION_TASK = "fetch-geolocation"
|
||||
|
||||
@ -13,7 +14,23 @@ TaskManager.defineTask(LOCATION_TASK, async ({ data, error }: any) => {
|
||||
return
|
||||
}
|
||||
const { locations } = data
|
||||
store.dispatch(setLastLocation(locations.at(-1)))
|
||||
const lastLoc: Location.LocationObject = locations.at(-1)
|
||||
store.dispatch(setLastLocation(lastLoc))
|
||||
console.log("sending-loc", lastLoc, socket.active)
|
||||
const playerId = store.getState().game.playerId
|
||||
if (socket.active && playerId) {
|
||||
const lastLocToSend: PlayerLocation = {
|
||||
playerId: playerId,
|
||||
longitude: lastLoc.coords.longitude,
|
||||
latitude: lastLoc.coords.latitude,
|
||||
speed: lastLoc.coords.speed ?? 0,
|
||||
accuracy: lastLoc.coords.accuracy ?? 0,
|
||||
altitude: lastLoc.coords.accuracy ?? 0,
|
||||
altitudeAccuracy: lastLoc.coords.altitudeAccuracy ?? 0,
|
||||
timestamp: new Date(lastLoc.timestamp).toISOString(),
|
||||
}
|
||||
socket.emit('last-location', { playerId: playerId, loc: lastLocToSend })
|
||||
}
|
||||
})
|
||||
|
||||
export async function startGeolocationService(): Promise<void | (() => void)> {
|
||||
|
Reference in New Issue
Block a user