Transmission plus immédiate via websockets

This commit is contained in:
2024-12-17 01:06:23 +01:00
parent 29c0a234d1
commit 0433e4695e
12 changed files with 448 additions and 12 deletions

View File

@ -1,11 +1,13 @@
import { ReactNode, useEffect, useState } from 'react'
import { ReactNode, useEffect } from 'react'
import { useAuth } from '@/hooks/useAuth'
import { useQueuedLocations, useSetLastPlayerLocations, useUnqueueLocation } from '@/hooks/useLocation'
import { useQueuedLocations, useSetLastPlayerLocation, useSetLastPlayerLocations, useUnqueueLocation } from '@/hooks/useLocation'
import { useGeolocationMutation } from '@/hooks/mutations/useGeolocationMutation'
import { useStartGeolocationServiceEffect } from '@/utils/geolocation'
import { Platform } from 'react-native'
import { useQuery } from '@tanstack/react-query'
import { isAuthValid } from '@/utils/features/auth/authSlice'
import { socket } from '@/utils/socket'
import { PlayerLocation } from '@/utils/features/location/locationSlice'
export default function GeolocationProvider({ children }: { children: ReactNode }) {
useStartGeolocationServiceEffect()
@ -14,6 +16,7 @@ export default function GeolocationProvider({ children }: { children: ReactNode
const geolocationsQueue = useQueuedLocations()
const unqueueLocation = useUnqueueLocation()
const setLastPlayerLocations = useSetLastPlayerLocations()
const setLastPlayerLocation = useSetLastPlayerLocation()
const geolocationMutation = useGeolocationMutation({
auth,
onPostSuccess: (data, variables) => unqueueLocation(variables),
@ -47,6 +50,11 @@ export default function GeolocationProvider({ children }: { children: ReactNode
setLastPlayerLocations(lastLocationsQuery.data)
}, [lastLocationsQuery.status, lastLocationsQuery.dataUpdatedAt])
socket.on('last-location', (data: PlayerLocation) => {
if (data.playerId)
setLastPlayerLocation(data)
})
return <>
{children}
</>