Compare commits

...

22 Commits

Author SHA1 Message Date
105d2aad88 Correction du partage de la position pour la joueuse qui n'est pas en course 2024-12-20 08:07:08 +01:00
1f2bee0b08 Dézoom sur le logo 2024-12-19 22:46:51 +01:00
86d07570c6 Passage en version 1.1.0 2024-12-19 21:41:44 +01:00
906dbeca22 Nouvelle icône 2024-12-19 21:41:00 +01:00
60bbe418a6 Nombre de points différents entre la première joueuse et la deuxième 2024-12-19 21:37:00 +01:00
650d77bbfd Retrait du plugin babel react-native-paper (https://github.com/fateh999/react-native-paper-dropdown/issues/115) 2024-12-19 21:23:27 +01:00
7f06ac94e8 Correction banière temps pour poursuite 2024-12-19 19:19:07 +01:00
ced5259272 Retrait de dépendances inutilisées 2024-12-19 17:57:26 +01:00
d1cdf8cf6d Affichage de la dernière localisation reçue uniquement en développement 2024-12-19 17:50:41 +01:00
4246266f9f Réparation du socket en production 2024-12-19 17:49:16 +01:00
956e9b6ffd Stockage du choix de précision de géolocalisation 2024-12-19 17:33:17 +01:00
590539a979 Amélioration Géolocalisation 2024-12-19 16:47:41 +01:00
abb5c3c584 Passage en version 1.0.1 2024-12-17 23:17:51 +01:00
5e61cabcdc Affichage de l'adresse estimée dans les infos de la position d'une joueuse 2024-12-17 23:06:20 +01:00
8ba47fe2f0 Popup pour voir l'heure de dernière position d'une joueuse 2024-12-17 22:59:47 +01:00
834b1643de Corrections et optimisations géolocalisation 2024-12-17 22:03:22 +01:00
55aff5f900 Correction appels multiples à la connexion 2024-12-17 21:14:51 +01:00
afcb5427af Retrait de l'adapter Websocket inutile 2024-12-17 01:35:10 +01:00
0b9df38139 Ajout IoAdapter pour les websockets en production 2024-12-17 01:32:10 +01:00
20f8fd515f La reconnection au serveur est déjà la valeur par défaut 2024-12-17 01:24:05 +01:00
256f0b7684 Gestion nom de domaine websocket 2024-12-17 01:19:00 +01:00
409e13277e Passage du délai de mise à jour des données depuis le serveur à 15 secondes 2024-12-17 01:12:54 +01:00
32 changed files with 288 additions and 245 deletions

View File

@ -1,5 +1,6 @@
# Public variables # Public variables
EXPO_PUBLIC_TRAINTRAPE_MOI_SERVER=https://traintrapemoi.luemy.eu/api EXPO_PUBLIC_TRAINTRAPE_MOI_SERVER=https://traintrapemoi.luemy.eu/api
EXPO_PUBLIC_TRAINTRAPE_MOI_SOCKET=https://traintrapemoi.luemy.eu/
# Build variables # Build variables
ANDROID_HOME=/opt/android-sdk ANDROID_HOME=/opt/android-sdk

View File

@ -1 +1,2 @@
EXPO_PUBLIC_TRAINTRAPE_MOI_SERVER=http://localhost:3000/ EXPO_PUBLIC_TRAINTRAPE_MOI_SERVER=http://localhost:3000/
EXPO_PUBLIC_TRAINTRAPE_MOI_SOCKET=http://localhost:3000/

View File

@ -2,7 +2,7 @@
"expo": { "expo": {
"name": "Traintrape-moi", "name": "Traintrape-moi",
"slug": "traintrape-moi-client", "slug": "traintrape-moi-client",
"version": "1.0.0", "version": "1.1.1",
"orientation": "portrait", "orientation": "portrait",
"icon": "./assets/images/icon.png", "icon": "./assets/images/icon.png",
"scheme": "traintrapemoi", "scheme": "traintrapemoi",
@ -15,7 +15,7 @@
"android": { "android": {
"adaptiveIcon": { "adaptiveIcon": {
"foregroundImage": "./assets/images/adaptive-icon.png", "foregroundImage": "./assets/images/adaptive-icon.png",
"backgroundColor": "#ffffff" "backgroundColor": "#0033fe"
}, },
"package": "eu.luemy.traintrapemoi", "package": "eu.luemy.traintrapemoi",
"permissions": [ "permissions": [
@ -42,7 +42,6 @@
"locationAlwaysAndWhenInUsePermission": "Allow $(PRODUCT_NAME) to use your location." "locationAlwaysAndWhenInUsePermission": "Allow $(PRODUCT_NAME) to use your location."
} }
], ],
"expo-notifications",
"expo-router", "expo-router",
"expo-secure-store", "expo-secure-store",
"expo-share-intent", "expo-share-intent",
@ -50,9 +49,9 @@
"expo-splash-screen", "expo-splash-screen",
{ {
"image": "./assets/images/splash-icon.png", "image": "./assets/images/splash-icon.png",
"imageWidth": 200, "imageWidth": 128,
"resizeMode": "contain", "resizeMode": "contain",
"backgroundColor": "#ffffff" "backgroundColor": "#0033fe"
} }
], ],
"expo-task-manager", "expo-task-manager",

View File

@ -1,10 +1,12 @@
import { useGameRepairMutation, useGameResetMutation, useGameStartMutation, useGameStopMutation, useGameSwitchPlayerMutation } from '@/hooks/mutations/useGameMutation' import { useGameRepairMutation, useGameResetMutation, useGameStartMutation, useGameStopMutation, useGameSwitchPlayerMutation } from '@/hooks/mutations/useGameMutation'
import { useAuth } from '@/hooks/useAuth' import { useAuth } from '@/hooks/useAuth'
import { useGame, useUpdateGameState } from '@/hooks/useGame' import { useGame, useSetLocationAccuracy, useUpdateGameState } from '@/hooks/useGame'
import { useQueryClient } from '@tanstack/react-query' import { useQueryClient } from '@tanstack/react-query'
import { useRouter } from 'expo-router' import { useRouter } from 'expo-router'
import { useState } from 'react' import { useState } from 'react'
import { Button, Dialog, FAB, List, MD3Colors, Portal, Snackbar, Surface, Text } from 'react-native-paper' import { Button, Dialog, List, MD3Colors, Portal, Snackbar, Surface, Text } from 'react-native-paper'
import { Dropdown } from 'react-native-paper-dropdown'
import { Accuracy } from 'expo-location'
export default function HistoryScreen() { export default function HistoryScreen() {
const [successVisible, setSuccessVisible] = useState(false) const [successVisible, setSuccessVisible] = useState(false)
@ -17,6 +19,17 @@ export default function HistoryScreen() {
const auth = useAuth() const auth = useAuth()
const game = useGame() const game = useGame()
const updateGameState = useUpdateGameState() const updateGameState = useUpdateGameState()
const setLocationAccuracy = useSetLocationAccuracy()
const accuracyArrayList = [
{ value: Accuracy.BestForNavigation.toString(), label: "Navigation" },
{ value: Accuracy.Highest.toString(), label: "Plus haute" },
{ value: Accuracy.High.toString(), label: "Haute" },
{ value: Accuracy.Balanced.toString(), label: "Équilibrée" },
{ value: Accuracy.Low.toString(), label: "Basse" },
{ value: Accuracy.Lowest.toString(), label: "Plus basse" },
{ value: 'null', label: "Désactivée" },
]
const gameStartMutation = useGameStartMutation({ const gameStartMutation = useGameStartMutation({
auth, auth,
@ -112,6 +125,11 @@ export default function HistoryScreen() {
description={auth.loggedIn ? "Vous êtes déjà connecté⋅e" : "Vous n'êtes pas connecté⋅e"} description={auth.loggedIn ? "Vous êtes déjà connecté⋅e" : "Vous n'êtes pas connecté⋅e"}
right={() => <List.Icon icon="login" />} right={() => <List.Icon icon="login" />}
onPress={() => router.navigate('/login')} /> onPress={() => router.navigate('/login')} />
<List.Item
key={"location-accuracy"}
title="Précision de la géolocalisation"
description="Réglez le niveau de précision de la géolocalisation. Une valeur élevée indique une consommation de batterie accrue."
right={() => <Dropdown label={"Géolocalisation"} hideMenuHeader={true} options={accuracyArrayList} value={game.settings.locationAccuracy?.toString() ?? 'null'} onSelect={(value) => setLocationAccuracy(!value || value == 'null' ? null : +value)} />} />
</List.Section> </List.Section>
<List.Section title={"Gestion du jeu"}> <List.Section title={"Gestion du jeu"}>
<List.Item <List.Item

Binary file not shown.

Before

Width:  |  Height:  |  Size: 17 KiB

After

Width:  |  Height:  |  Size: 17 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 1.4 KiB

After

Width:  |  Height:  |  Size: 13 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 22 KiB

After

Width:  |  Height:  |  Size: 17 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 5.0 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 6.2 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 14 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 21 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 17 KiB

After

Width:  |  Height:  |  Size: 17 KiB

View File

@ -2,10 +2,5 @@ module.exports = function(api) {
api.cache(true); api.cache(true);
return { return {
presets: ['babel-preset-expo'], presets: ['babel-preset-expo'],
env: {
production: {
plugins: ['react-native-paper/babel'],
},
},
} }
} }

View File

@ -7,13 +7,13 @@ import { Banner, MD3Colors, ProgressBar, Text } from "react-native-paper"
export default function FreeChaseBanner() { export default function FreeChaseBanner() {
const game = useGame() const game = useGame()
const chaseFreeTime = game.chaseFreeTime const chaseFreeTime = game.chaseFreeTime
const chaser = !game.gameStarted && !game.currentRunner && chaseFreeTime !== null const chaser = game.gameStarted && !game.currentRunner && chaseFreeTime !== null
const chaseFreeDate = useMemo(() => new Date(chaseFreeTime || 0), [chaseFreeTime]) const chaseFreeDate = useMemo(() => new Date(chaseFreeTime || 0), [chaseFreeTime])
const chaseFreePretty = chaseFreeDate.toLocaleTimeString(undefined, { hour: '2-digit', minute: '2-digit' }) const chaseFreePretty = chaseFreeDate.toLocaleTimeString(undefined, { hour: '2-digit', minute: '2-digit' })
const [remainingTime, setRemainingTime] = useState(0) const [remainingTime, setRemainingTime] = useState(0)
const prettyRemainingTime = useMemo(() => `${Math.floor(remainingTime / 60).toString().padStart(2, '0')}:${Math.floor(remainingTime % 60).toString().padStart(2, '0')}`, [remainingTime]) const prettyRemainingTime = useMemo(() => `${Math.floor(remainingTime / 60).toString().padStart(2, '0')}:${Math.floor(remainingTime % 60).toString().padStart(2, '0')}`, [remainingTime])
const iconName = useMemo(() => { const iconName = useMemo(() => {
switch (Math.abs(remainingTime % 4)) { switch (Math.abs(Math.floor(remainingTime) % 4)) {
case 0: return 'hourglass-empty' case 0: return 'hourglass-empty'
case 1: return 'hourglass-end' case 1: return 'hourglass-end'
case 2: return 'hourglass-half' case 2: return 'hourglass-half'
@ -25,7 +25,7 @@ export default function FreeChaseBanner() {
const now = new Date().getTime() const now = new Date().getTime()
if (!chaser || (chaseFreeTime < now && remainingTime < 0)) if (!chaser || (chaseFreeTime < now && remainingTime < 0))
return return
const interval = setInterval(() => setRemainingTime(Math.floor(chaseFreeTime - now) / 1000), 1000) const interval = setInterval(() => setRemainingTime(Math.floor(chaseFreeTime - new Date().getTime()) / 1000), 1000)
return () => clearInterval(interval) return () => clearInterval(interval)
}, [game.gameStarted, game.currentRunner, chaseFreeDate]) }, [game.gameStarted, game.currentRunner, chaseFreeDate])

View File

@ -1,27 +1,53 @@
import { StyleSheet } from 'react-native'
import MapLibreGL, { Camera, FillLayer, LineLayer, MapView, PointAnnotation, RasterLayer, RasterSource, ShapeSource, UserLocation, UserTrackingMode } from '@maplibre/maplibre-react-native'
import { FontAwesome5, MaterialIcons } from '@expo/vector-icons' import { FontAwesome5, MaterialIcons } from '@expo/vector-icons'
import MapLibreGL, { Camera, FillLayer, LineLayer, MapView, PointAnnotation, RasterLayer, RasterSource, ShapeSource, UserLocation, UserTrackingMode } from '@maplibre/maplibre-react-native'
import { useQuery } from '@tanstack/react-query'
import { circle } from '@turf/circle' import { circle } from '@turf/circle'
import { useLastOwnLocation, useLastPlayerLocations } from '@/hooks/useLocation' import { reverseGeocodeAsync } from 'expo-location'
import React, { useMemo, useState } from 'react' import React, { useEffect, useMemo, useState } from 'react'
import { PlayerLocation } from '@/utils/features/location/locationSlice' import { StyleSheet } from 'react-native'
import { Button, Dialog, FAB, Portal, Text } from 'react-native-paper'
import { useAuth } from '@/hooks/useAuth'
import { useGame } from '@/hooks/useGame' import { useGame } from '@/hooks/useGame'
import { FAB } from 'react-native-paper' import { useLastOwnLocation, useLastPlayerLocations } from '@/hooks/useLocation'
import { isAuthValid } from '@/utils/features/auth/authSlice'
import { Player } from '@/utils/features/game/gameSlice'
import { PlayerLocation } from '@/utils/features/location/locationSlice'
export default function Map() { export default function Map() {
const [followUser, setFollowUser] = useState(true) const [followUser, setFollowUser] = useState(true)
return ( return (
<> <>
<MapComponent followUser={followUser} setFollowUser={setFollowUser} /> <MapWrapper followUser={followUser} setFollowUser={setFollowUser} />
<FAB <FollowUserButton key={'follow-userr-btn-component'} followUser={followUser} setFollowUser={setFollowUser} />
style={{ position: 'absolute', right: 25, bottom: 25 }}
icon={(props) => <MaterialIcons name={followUser ? 'my-location' : 'location-searching'} {...props} />}
onPress={() => setFollowUser(followUser => !followUser)} />
</> </>
) )
} }
function MapComponent({ followUser, setFollowUser }: { followUser?: boolean, setFollowUser: React.Dispatch<React.SetStateAction<boolean>> }) { type FollowUserProps = {
followUser: boolean,
setFollowUser: React.Dispatch<React.SetStateAction<boolean>>,
}
function MapWrapper({ followUser, setFollowUser }: FollowUserProps) {
const [displayedPlayerId, setDisplayedPlayerId] = useState<number | null>(null)
return (
<>
<MapComponent followUser={followUser} setFollowUser={setFollowUser} setDisplayedPlayerId={setDisplayedPlayerId} />
<Portal>
<PlayerLocationDialog displayedPlayerId={displayedPlayerId} onDismiss={() => setDisplayedPlayerId(null)} />
</Portal>
</>
)
}
type MapComponentProps = {
followUser?: boolean,
setFollowUser: React.Dispatch<React.SetStateAction<boolean>>,
setDisplayedPlayerId: React.Dispatch<React.SetStateAction<number | null>>
}
function MapComponent({ followUser, setFollowUser, setDisplayedPlayerId }: MapComponentProps) {
MapLibreGL.setAccessToken(null) MapLibreGL.setAccessToken(null)
const userLocation = useLastOwnLocation() const userLocation = useLastOwnLocation()
return ( return (
@ -44,22 +70,22 @@ function MapComponent({ followUser, setFollowUser }: { followUser?: boolean, set
<RasterLayer id="railwaymap-layer" sourceID="railwaymap-source" style={{rasterOpacity: 0.7}} /> <RasterLayer id="railwaymap-layer" sourceID="railwaymap-source" style={{rasterOpacity: 0.7}} />
<UserLocation animated={true} renderMode="native" androidRenderMode="compass" showsUserHeadingIndicator={true} /> <UserLocation animated={true} renderMode="native" androidRenderMode="compass" showsUserHeadingIndicator={true} />
<PlayerLocationsMarkers /> <PlayerLocationsMarkers setDisplayedPlayerId={setDisplayedPlayerId} />
</MapView> </MapView>
) )
} }
function PlayerLocationsMarkers() { function PlayerLocationsMarkers({ setDisplayedPlayerId }: { setDisplayedPlayerId: React.Dispatch<React.SetStateAction<number | null>> }) {
const game = useGame() const game = useGame()
const lastPlayerLocations = useLastPlayerLocations() const lastPlayerLocations = useLastPlayerLocations()
return lastPlayerLocations ? lastPlayerLocations return lastPlayerLocations ? lastPlayerLocations
.filter(() => game.currentRunner === true || !game.gameStarted) .filter(() => !game.currentRunner || !game.gameStarted)
.filter(playerLoc => playerLoc.playerId !== game.playerId) .filter(playerLoc => playerLoc.playerId !== game.playerId)
.map(playerLoc => <PlayerLocationMarker key={`player-${playerLoc.playerId}-loc`} playerLocation={playerLoc} />) : <></> .map(playerLoc => <PlayerLocationMarker key={`player-${playerLoc.playerId}-loc`} playerLocation={playerLoc} setDisplayedPlayerId={setDisplayedPlayerId} />) : <></>
} }
function PlayerLocationMarker({ playerLocation }: { playerLocation: PlayerLocation }) { function PlayerLocationMarker({ playerLocation, setDisplayedPlayerId }: { playerLocation: PlayerLocation, setDisplayedPlayerId: React.Dispatch<React.SetStateAction<number | null>> }) {
const accuracyCircle = useMemo(() => circle([playerLocation.longitude, playerLocation.latitude], playerLocation.accuracy, {steps: 64, units: 'meters'}), [playerLocation]) const accuracyCircle = useMemo(() => circle([playerLocation.longitude, playerLocation.latitude], playerLocation.accuracy, {steps: 64, units: 'meters'}), [playerLocation])
return <> return <>
<ShapeSource <ShapeSource
@ -76,7 +102,8 @@ function PlayerLocationMarker({ playerLocation }: { playerLocation: PlayerLocati
style={{lineOpacity: 0.4, lineColor: 'red'}} style={{lineOpacity: 0.4, lineColor: 'red'}}
aboveLayerID={`accuracy-radius-fill-${playerLocation.playerId}`} /> aboveLayerID={`accuracy-radius-fill-${playerLocation.playerId}`} />
<PointAnnotation id={`player-location-marker-${playerLocation.playerId}`} <PointAnnotation id={`player-location-marker-${playerLocation.playerId}`}
coordinate={[playerLocation.longitude, playerLocation.latitude]}> coordinate={[playerLocation.longitude, playerLocation.latitude]}
onSelected={() => { setDisplayedPlayerId(playerLocation.playerId) }}>
<FontAwesome5 name="map-marker-alt" size={24} color="red" /> <FontAwesome5 name="map-marker-alt" size={24} color="red" />
</PointAnnotation> </PointAnnotation>
</> </>
@ -88,3 +115,68 @@ const styles = StyleSheet.create({
alignSelf: 'stretch', alignSelf: 'stretch',
} }
}) })
function FollowUserButton({ followUser, setFollowUser }: FollowUserProps) {
return (
<FAB
key={'follow-user-btn'}
style={{ position: 'absolute', right: 25, bottom: 25 }}
icon={(props) => <MaterialIcons name={followUser ? 'my-location' : 'location-searching'} {...props} />}
onPress={() => setFollowUser(followUser => !followUser)} />
)
}
function PlayerLocationDialog({ displayedPlayerId, onDismiss }: { displayedPlayerId: number | null, onDismiss: () => void }) {
const auth = useAuth()
const lastPlayerLocations = useLastPlayerLocations()
const playersQuery = useQuery({
queryKey: ['get-players', auth.token],
queryFn: () => fetch(`${process.env.EXPO_PUBLIC_TRAINTRAPE_MOI_SERVER}/players/`, {
headers: { "Authorization": `Bearer ${auth.token}` }}
).then(resp => resp.json()),
enabled: isAuthValid(auth),
initialData: { data: [], meta: { currentPage: 0, lastPage: 0, nextPage: 0, prevPage: 0, total: 0, totalPerPage: 0 } },
})
const displayedPlayerLoc = useMemo(() => {
return lastPlayerLocations.find(loc => loc.playerId === displayedPlayerId)
}, [displayedPlayerId, lastPlayerLocations])
const displayedPlayerName = useMemo(() => {
if (!playersQuery.isSuccess || !displayedPlayerId)
return "Chargement…"
const player: Player | undefined = playersQuery.data.data.find((player: Player) => player.id === displayedPlayerId)
if (!player)
return "Chargement…"
return player.name
}, [displayedPlayerId, playersQuery])
const [address, setAddress] = useState("Adresse inconnue")
useEffect(() => {
if (!displayedPlayerLoc)
return setAddress("Adresse inconnue")
reverseGeocodeAsync(displayedPlayerLoc).then(addresses => setAddress(addresses[0].formattedAddress ?? "Adresse inconnue"))
}, [displayedPlayerLoc])
return (
<Dialog visible={displayedPlayerId !== null} onDismiss={onDismiss}>
<Dialog.Title>{displayedPlayerName}</Dialog.Title>
<Dialog.Content>
<Text>
Dernière position : {new Date(displayedPlayerLoc?.timestamp ?? 0).toLocaleString()}
</Text>
<Text>
Précision : {displayedPlayerLoc?.accuracy.toPrecision(3)} m
</Text>
<Text>
Adresse estimée : {address}
</Text>
</Dialog.Content>
<Dialog.Actions>
<Button onPress={onDismiss}>
Fermer
</Button>
</Dialog.Actions>
</Dialog>
)
}

View File

@ -1,3 +1,4 @@
import { Constants } from '@/constants/Constants'
import { useAuth } from '@/hooks/useAuth' import { useAuth } from '@/hooks/useAuth'
import { useChallengeActions, useDownloadChallengeActions } from '@/hooks/useChallengeActions' import { useChallengeActions, useDownloadChallengeActions } from '@/hooks/useChallengeActions'
import { useDownloadChallenges } from '@/hooks/useChallenges' import { useDownloadChallenges } from '@/hooks/useChallenges'
@ -10,7 +11,7 @@ import { Challenge } from '@/utils/features/challenges/challengesSlice'
import { useQuery } from '@tanstack/react-query' import { useQuery } from '@tanstack/react-query'
import { router } from 'expo-router' import { router } from 'expo-router'
import { useShareIntentContext } from 'expo-share-intent' import { useShareIntentContext } from 'expo-share-intent'
import { ReactNode, useEffect } from 'react' import React, { ReactNode, useEffect } from 'react'
export default function GameProvider({ children }: { children: ReactNode }) { export default function GameProvider({ children }: { children: ReactNode }) {
const auth = useAuth() const auth = useAuth()
@ -31,7 +32,7 @@ export default function GameProvider({ children }: { children: ReactNode }) {
headers: { "Authorization": `Bearer ${auth.token}` }} headers: { "Authorization": `Bearer ${auth.token}` }}
).then(resp => resp.json()), ).then(resp => resp.json()),
enabled: isAuthValid(auth), enabled: isAuthValid(auth),
refetchInterval: 5000, refetchInterval: Constants.QUERY_REFETCH_INTERVAL * 1000,
}) })
useEffect(() => { useEffect(() => {
if (gameQuery.isSuccess && gameQuery.data) if (gameQuery.isSuccess && gameQuery.data)
@ -44,7 +45,7 @@ export default function GameProvider({ children }: { children: ReactNode }) {
headers: { "Authorization": `Bearer ${auth.token}` }} headers: { "Authorization": `Bearer ${auth.token}` }}
).then(resp => resp.json()), ).then(resp => resp.json()),
enabled: isAuthValid(auth) && !!game.playerId, enabled: isAuthValid(auth) && !!game.playerId,
refetchInterval: 5000, refetchInterval: Constants.QUERY_REFETCH_INTERVAL * 1000,
}) })
useEffect(() => { useEffect(() => {
if (playerQuery.isSuccess && playerQuery.data) { if (playerQuery.isSuccess && playerQuery.data) {
@ -60,7 +61,7 @@ export default function GameProvider({ children }: { children: ReactNode }) {
).then(resp => resp.json()), ).then(resp => resp.json()),
enabled: isAuthValid(auth) && !!game.playerId, enabled: isAuthValid(auth) && !!game.playerId,
initialData: { data: [], meta: { currentPage: 0, lastPage: 0, nextPage: 0, prevPage: 0, total: 0, totalPerPage: 0 } }, initialData: { data: [], meta: { currentPage: 0, lastPage: 0, nextPage: 0, prevPage: 0, total: 0, totalPerPage: 0 } },
refetchInterval: 5000, refetchInterval: Constants.QUERY_REFETCH_INTERVAL * 1000,
}) })
useEffect(() => { useEffect(() => {
if (trainsQuery.isSuccess && trainsQuery.data) if (trainsQuery.isSuccess && trainsQuery.data)
@ -74,7 +75,7 @@ export default function GameProvider({ children }: { children: ReactNode }) {
).then(resp => resp.json()), ).then(resp => resp.json()),
enabled: isAuthValid(auth), enabled: isAuthValid(auth),
initialData: { data: [], meta: { currentPage: 0, lastPage: 0, nextPage: 0, prevPage: 0, total: 0, totalPerPage: 0 } }, initialData: { data: [], meta: { currentPage: 0, lastPage: 0, nextPage: 0, prevPage: 0, total: 0, totalPerPage: 0 } },
refetchInterval: 5000, refetchInterval: Constants.QUERY_REFETCH_INTERVAL * 1000,
}) })
useEffect(() => { useEffect(() => {
if (challengesQuery.isSuccess && challengesQuery.data) { if (challengesQuery.isSuccess && challengesQuery.data) {
@ -91,7 +92,7 @@ export default function GameProvider({ children }: { children: ReactNode }) {
headers: { "Authorization": `Bearer ${auth.token}` }} headers: { "Authorization": `Bearer ${auth.token}` }}
).then(resp => resp.json()), ).then(resp => resp.json()),
enabled: isAuthValid(auth) && !!game.playerId, enabled: isAuthValid(auth) && !!game.playerId,
refetchInterval: 5000, refetchInterval: Constants.QUERY_REFETCH_INTERVAL * 1000,
}) })
useEffect(() => { useEffect(() => {
if (moneyUpdatesQuery.isSuccess && moneyUpdatesQuery.data) if (moneyUpdatesQuery.isSuccess && moneyUpdatesQuery.data)

View File

@ -1,18 +1,23 @@
import { ReactNode, useEffect } from 'react'
import { useAuth } from '@/hooks/useAuth'
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 { useQuery } from '@tanstack/react-query'
import React, { ReactNode, useEffect } from 'react'
import { Platform } from 'react-native'
import { Constants } from '@/constants/Constants'
import { useAuth } from '@/hooks/useAuth'
import { useSetLocationAccuracy } from '@/hooks/useGame'
import { useGeolocationMutation } from '@/hooks/mutations/useGeolocationMutation'
import { useQueuedLocations, useSetLastPlayerLocation, useSetLastPlayerLocations, useUnqueueLocation } from '@/hooks/useLocation'
import { isAuthValid } from '@/utils/features/auth/authSlice' import { isAuthValid } from '@/utils/features/auth/authSlice'
import { socket } from '@/utils/socket'
import { PlayerLocation } from '@/utils/features/location/locationSlice' import { PlayerLocation } from '@/utils/features/location/locationSlice'
import { useStartGeolocationServiceEffect } from '@/utils/geolocation'
import * as SecureStore from '@/utils/SecureStore'
import { socket } from '@/utils/socket'
import { Accuracy } from 'expo-location'
export default function GeolocationProvider({ children }: { children: ReactNode }) { export default function GeolocationProvider({ children }: { children: ReactNode }) {
useStartGeolocationServiceEffect() useStartGeolocationServiceEffect()
const auth = useAuth() const auth = useAuth()
const setLocationAccuracy = useSetLocationAccuracy()
const geolocationsQueue = useQueuedLocations() const geolocationsQueue = useQueuedLocations()
const unqueueLocation = useUnqueueLocation() const unqueueLocation = useUnqueueLocation()
const setLastPlayerLocations = useSetLastPlayerLocations() const setLastPlayerLocations = useSetLastPlayerLocations()
@ -23,6 +28,17 @@ export default function GeolocationProvider({ children }: { children: ReactNode
onError: ({ response, error }) => console.error(response, error), onError: ({ response, error }) => console.error(response, error),
}) })
useEffect(() => {
SecureStore.getItemAsync('locationAccuracy').then(locationAccuracyString => {
if (!locationAccuracyString)
setLocationAccuracy(Accuracy.Balanced)
else if (locationAccuracyString === 'null')
setLocationAccuracy(null)
else
setLocationAccuracy(+locationAccuracyString)
})
}, [])
if (Platform.OS !== "web") { if (Platform.OS !== "web") {
useEffect(() => { useEffect(() => {
if (geolocationsQueue.length === 0 || geolocationMutation.isPending || !isAuthValid(auth)) if (geolocationsQueue.length === 0 || geolocationMutation.isPending || !isAuthValid(auth))
@ -43,17 +59,21 @@ export default function GeolocationProvider({ children }: { children: ReactNode
}).then(resp => resp.json()), }).then(resp => resp.json()),
initialData: [], initialData: [],
enabled: isAuthValid(auth), enabled: isAuthValid(auth),
refetchInterval: 5000, refetchInterval: Constants.QUERY_REFETCH_INTERVAL * 1000,
}) })
useEffect(() => { useEffect(() => {
if (lastLocationsQuery.isSuccess && lastLocationsQuery.data) if (lastLocationsQuery.isSuccess && lastLocationsQuery.data)
setLastPlayerLocations(lastLocationsQuery.data) setLastPlayerLocations(lastLocationsQuery.data)
}, [lastLocationsQuery.status, lastLocationsQuery.dataUpdatedAt]) }, [lastLocationsQuery.status, lastLocationsQuery.dataUpdatedAt])
socket.on('last-location', (data: PlayerLocation) => { useEffect(() => {
if (data.playerId) const locationListener = async (data: PlayerLocation) => {
setLastPlayerLocation(data) if (data.playerId)
}) setLastPlayerLocation(data)
}
socket.on('last-location', locationListener)
return () => { socket.off('last-location', locationListener) }
}, [])
return <> return <>
{children} {children}

View File

@ -1,6 +1,6 @@
import { Href, useRouter } from 'expo-router' import { Href, useRouter } from 'expo-router'
import { useRouteInfo } from 'expo-router/build/hooks' import { useRouteInfo } from 'expo-router/build/hooks'
import { ReactNode, useEffect } from 'react' import React, { ReactNode, useEffect } from 'react'
import { useAuth, useAuthLogin } from '@/hooks/useAuth' import { useAuth, useAuthLogin } from '@/hooks/useAuth'
import * as SecureStore from '@/utils/SecureStore' import * as SecureStore from '@/utils/SecureStore'
import { useLoginMutation } from '@/hooks/mutations/useLoginMutation' import { useLoginMutation } from '@/hooks/mutations/useLoginMutation'
@ -47,7 +47,7 @@ export default function LoginProvider({ loginRedirect, children }: Props) {
// Renouvellement auto du jeton d'authentification // Renouvellement auto du jeton d'authentification
const { name, token } = auth const { name, token } = auth
const password = SecureStore.getItem('apiPassword') const password = SecureStore.getItem('apiPassword')
if (name === null || (password === null && token === null)) if (name === null || (password === null && token === null) || loginMutation.isPending)
return return
let waitTime = 0 let waitTime = 0
if (token !== null && token !== undefined) { if (token !== null && token !== undefined) {
@ -69,7 +69,7 @@ export default function LoginProvider({ loginRedirect, children }: Props) {
authLogin({ name: name, token: null }) authLogin({ name: name, token: null })
}, waitTime) }, waitTime)
return () => clearTimeout(timeout) return () => clearTimeout(timeout)
}, [auth, authLogin, game, setPlayerId]) }, [auth, authLogin, loginMutation.status, game, setPlayerId])
return <> return <>
{children} {children}

View File

@ -1,3 +1,6 @@
import { Accuracy } from 'expo-location'
export const Constants = { export const Constants = {
MIN_DELAY_LOCATION_SENT: 20 MIN_DELAY_LOCATION_SENT: 20,
QUERY_REFETCH_INTERVAL: 15,
} }

View File

@ -1,7 +1,9 @@
import { Accuracy } from "expo-location"
import { useAppDispatch, useAppSelector } from "./useStore" import { useAppDispatch, useAppSelector } from "./useStore"
import { GamePayload, PenaltyPayload, setPlayerId, updateActiveChallengeId, updateGameState, updateMoney, updatePenalty } from "@/utils/features/game/gameSlice" import { GamePayload, PenaltyPayload, setLocationAccuracy, setPlayerId, updateActiveChallengeId, updateGameState, updateMoney, updatePenalty } from "@/utils/features/game/gameSlice"
export const useGame = () => useAppSelector((state) => state.game) export const useGame = () => useAppSelector((state) => state.game)
export const useSettings = () => useAppSelector((state) => state.game.settings)
export const useSetPlayerId = () => { export const useSetPlayerId = () => {
const dispath = useAppDispatch() const dispath = useAppDispatch()
return (playerId: number) => dispath(setPlayerId(playerId)) return (playerId: number) => dispath(setPlayerId(playerId))
@ -22,3 +24,7 @@ export const useUpdatePenalty = () => {
const dispatch = useAppDispatch() const dispatch = useAppDispatch()
return (penalty: PenaltyPayload) => dispatch(updatePenalty(penalty)) return (penalty: PenaltyPayload) => dispatch(updatePenalty(penalty))
} }
export const useSetLocationAccuracy = () => {
const dispatch = useAppDispatch()
return (accuracy: Accuracy | null) => dispatch(setLocationAccuracy(accuracy))
}

181
client/package-lock.json generated
View File

@ -1,12 +1,12 @@
{ {
"name": "traintrape-moi-client", "name": "traintrape-moi-client",
"version": "1.0.0", "version": "1.0.1",
"lockfileVersion": 3, "lockfileVersion": 3,
"requires": true, "requires": true,
"packages": { "packages": {
"": { "": {
"name": "traintrape-moi-client", "name": "traintrape-moi-client",
"version": "1.0.0", "version": "1.0.1",
"dependencies": { "dependencies": {
"@dev-plugins/react-navigation": "^0.1.0", "@dev-plugins/react-navigation": "^0.1.0",
"@dev-plugins/react-query": "^0.1.0", "@dev-plugins/react-query": "^0.1.0",
@ -25,10 +25,8 @@
"expo-constants": "~17.0.3", "expo-constants": "~17.0.3",
"expo-dev-client": "~5.0.4", "expo-dev-client": "~5.0.4",
"expo-font": "~13.0.1", "expo-font": "~13.0.1",
"expo-haptics": "~14.0.0",
"expo-linking": "~7.0.3", "expo-linking": "~7.0.3",
"expo-location": "^18.0.2", "expo-location": "^18.0.2",
"expo-notifications": "~0.29.11",
"expo-router": "~4.0.9", "expo-router": "~4.0.9",
"expo-secure-store": "~14.0.0", "expo-secure-store": "~14.0.0",
"expo-share-intent": "^3.1.1", "expo-share-intent": "^3.1.1",
@ -38,7 +36,6 @@
"expo-system-ui": "~4.0.4", "expo-system-ui": "~4.0.4",
"expo-task-manager": "^12.0.3", "expo-task-manager": "^12.0.3",
"expo-updates": "~0.26.10", "expo-updates": "~0.26.10",
"expo-web-browser": "~14.0.1",
"maplibre-gl": "^4.7.1", "maplibre-gl": "^4.7.1",
"maplibre-react-components": "^0.1.9", "maplibre-react-components": "^0.1.9",
"react": "18.3.1", "react": "18.3.1",
@ -47,11 +44,10 @@
"react-native": "0.76.3", "react-native": "0.76.3",
"react-native-gesture-handler": "~2.20.2", "react-native-gesture-handler": "~2.20.2",
"react-native-paper": "^5.12.5", "react-native-paper": "^5.12.5",
"react-native-reanimated": "~3.16.1", "react-native-paper-dropdown": "^2.3.1",
"react-native-safe-area-context": "~4.12.0", "react-native-safe-area-context": "~4.12.0",
"react-native-screens": "~4.1.0", "react-native-screens": "~4.1.0",
"react-native-web": "~0.19.13", "react-native-web": "~0.19.13",
"react-native-webview": "13.12.2",
"react-redux": "^9.1.2", "react-redux": "^9.1.2",
"socket.io-client": "^4.8.1" "socket.io-client": "^4.8.1"
}, },
@ -1850,6 +1846,7 @@
"resolved": "https://registry.npmjs.org/@babel/plugin-transform-template-literals/-/plugin-transform-template-literals-7.25.9.tgz", "resolved": "https://registry.npmjs.org/@babel/plugin-transform-template-literals/-/plugin-transform-template-literals-7.25.9.tgz",
"integrity": "sha512-o97AE4syN71M/lxrCtQByzphAdlYluKPDBzDVzMmfCobUjjhAryZV0AIpRPrxN0eAkxXO6ZLEScmt+PNhj2OTw==", "integrity": "sha512-o97AE4syN71M/lxrCtQByzphAdlYluKPDBzDVzMmfCobUjjhAryZV0AIpRPrxN0eAkxXO6ZLEScmt+PNhj2OTw==",
"license": "MIT", "license": "MIT",
"peer": true,
"dependencies": { "dependencies": {
"@babel/helper-plugin-utils": "^7.25.9" "@babel/helper-plugin-utils": "^7.25.9"
}, },
@ -2956,12 +2953,6 @@
"js-yaml": "bin/js-yaml.js" "js-yaml": "bin/js-yaml.js"
} }
}, },
"node_modules/@ide/backoff": {
"version": "1.0.0",
"resolved": "https://registry.npmjs.org/@ide/backoff/-/backoff-1.0.0.tgz",
"integrity": "sha512-F0YfUDjvT+Mtt/R4xdl2X0EYCHMMiJqNLdxHD++jDT5ydEFIyqbCHh51Qx2E211dgZprPKhV7sHmnXKpLuvc5g==",
"license": "MIT"
},
"node_modules/@isaacs/cliui": { "node_modules/@isaacs/cliui": {
"version": "8.0.2", "version": "8.0.2",
"resolved": "https://registry.npmjs.org/@isaacs/cliui/-/cliui-8.0.2.tgz", "resolved": "https://registry.npmjs.org/@isaacs/cliui/-/cliui-8.0.2.tgz",
@ -5686,19 +5677,6 @@
"integrity": "sha512-BSHWgDSAiKs50o2Re8ppvp3seVHXSRM44cdSsT9FfNEUUZLOGWVCsiWaRPWM1Znn+mqZ1OfVZ3z3DWEzSp7hRA==", "integrity": "sha512-BSHWgDSAiKs50o2Re8ppvp3seVHXSRM44cdSsT9FfNEUUZLOGWVCsiWaRPWM1Znn+mqZ1OfVZ3z3DWEzSp7hRA==",
"license": "MIT" "license": "MIT"
}, },
"node_modules/assert": {
"version": "2.1.0",
"resolved": "https://registry.npmjs.org/assert/-/assert-2.1.0.tgz",
"integrity": "sha512-eLHpSK/Y4nhMJ07gDaAzoX/XAKS8PSaojml3M0DM4JpV1LAi5JOJ/p6H/XWrl8L+DzVEvVCW1z3vWAaB9oTsQw==",
"license": "MIT",
"dependencies": {
"call-bind": "^1.0.2",
"is-nan": "^1.3.2",
"object-is": "^1.1.5",
"object.assign": "^4.1.4",
"util": "^0.12.5"
}
},
"node_modules/assign-symbols": { "node_modules/assign-symbols": {
"version": "1.0.0", "version": "1.0.0",
"resolved": "https://registry.npmjs.org/assign-symbols/-/assign-symbols-1.0.0.tgz", "resolved": "https://registry.npmjs.org/assign-symbols/-/assign-symbols-1.0.0.tgz",
@ -5982,12 +5960,6 @@
"@babel/core": "^7.0.0" "@babel/core": "^7.0.0"
} }
}, },
"node_modules/badgin": {
"version": "1.2.3",
"resolved": "https://registry.npmjs.org/badgin/-/badgin-1.2.3.tgz",
"integrity": "sha512-NQGA7LcfCpSzIbGRbkgjgdWkjy7HI+Th5VLxTJfW5EeaAf3fnS+xWQaQOCYiny+q6QSvxqoSO04vCx+4u++EJw==",
"license": "MIT"
},
"node_modules/balanced-match": { "node_modules/balanced-match": {
"version": "1.0.2", "version": "1.0.2",
"resolved": "https://registry.npmjs.org/balanced-match/-/balanced-match-1.0.2.tgz", "resolved": "https://registry.npmjs.org/balanced-match/-/balanced-match-1.0.2.tgz",
@ -7123,23 +7095,6 @@
"node": ">=8" "node": ">=8"
} }
}, },
"node_modules/define-properties": {
"version": "1.2.1",
"resolved": "https://registry.npmjs.org/define-properties/-/define-properties-1.2.1.tgz",
"integrity": "sha512-8QmQKqEASLd5nx0U1B1okLElbUuuttJ/AnYmRXbbbGDWh6uS208EjD4Xqq/I9wK7u0v6O08XhTWnt5XtEbR6Dg==",
"license": "MIT",
"dependencies": {
"define-data-property": "^1.0.1",
"has-property-descriptors": "^1.0.0",
"object-keys": "^1.1.1"
},
"engines": {
"node": ">= 0.4"
},
"funding": {
"url": "https://github.com/sponsors/ljharb"
}
},
"node_modules/del": { "node_modules/del": {
"version": "6.1.1", "version": "6.1.1",
"resolved": "https://registry.npmjs.org/del/-/del-6.1.1.tgz", "resolved": "https://registry.npmjs.org/del/-/del-6.1.1.tgz",
@ -7846,15 +7801,6 @@
} }
} }
}, },
"node_modules/expo-application": {
"version": "6.0.1",
"resolved": "https://registry.npmjs.org/expo-application/-/expo-application-6.0.1.tgz",
"integrity": "sha512-w+1quSmKp8SYKT+GAFHSN5c6u+PqoVRIfpsLyRQrQdOnBA9dA8Hw6JT9sHNFmA30A2v1b/sdYZE3qKuRJFNSWQ==",
"license": "MIT",
"peerDependencies": {
"expo": "*"
}
},
"node_modules/expo-asset": { "node_modules/expo-asset": {
"version": "11.0.1", "version": "11.0.1",
"resolved": "https://registry.npmjs.org/expo-asset/-/expo-asset-11.0.1.tgz", "resolved": "https://registry.npmjs.org/expo-asset/-/expo-asset-11.0.1.tgz",
@ -7981,15 +7927,6 @@
"react": "*" "react": "*"
} }
}, },
"node_modules/expo-haptics": {
"version": "14.0.0",
"resolved": "https://registry.npmjs.org/expo-haptics/-/expo-haptics-14.0.0.tgz",
"integrity": "sha512-5tYJN+2axYF22BtG1elBQAV1aZPUOCtr9sItClfm4jDoekGiPCxZG/nylcA3DVh2bUHMSll4Y98qjFFFhwZ1Cw==",
"license": "MIT",
"peerDependencies": {
"expo": "*"
}
},
"node_modules/expo-json-utils": { "node_modules/expo-json-utils": {
"version": "0.14.0", "version": "0.14.0",
"resolved": "https://registry.npmjs.org/expo-json-utils/-/expo-json-utils-0.14.0.tgz", "resolved": "https://registry.npmjs.org/expo-json-utils/-/expo-json-utils-0.14.0.tgz",
@ -8106,26 +8043,6 @@
"invariant": "^2.2.4" "invariant": "^2.2.4"
} }
}, },
"node_modules/expo-notifications": {
"version": "0.29.11",
"resolved": "https://registry.npmjs.org/expo-notifications/-/expo-notifications-0.29.11.tgz",
"integrity": "sha512-u/Csc3YNOPjjuyjAeyj5ne7XR/Z0ABYVquhSnyjEj2Fp8mSldOPCMvaEA01pTFj+8HTlkjX5RZDvQ7cR62ngOA==",
"license": "MIT",
"dependencies": {
"@expo/image-utils": "^0.6.0",
"@ide/backoff": "^1.0.0",
"abort-controller": "^3.0.0",
"assert": "^2.0.0",
"badgin": "^1.1.5",
"expo-application": "~6.0.0",
"expo-constants": "~17.0.0"
},
"peerDependencies": {
"expo": "*",
"react": "*",
"react-native": "*"
}
},
"node_modules/expo-router": { "node_modules/expo-router": {
"version": "4.0.11", "version": "4.0.11",
"resolved": "https://registry.npmjs.org/expo-router/-/expo-router-4.0.11.tgz", "resolved": "https://registry.npmjs.org/expo-router/-/expo-router-4.0.11.tgz",
@ -8330,16 +8247,6 @@
"integrity": "sha512-ZWc51jO3qegGkVh8Hwpv636EkbesNV5ZNQPCtRa+0qytRYPEs9IYT9qITY9buezqUH5uqyzlWLcufrzU2rffdg==", "integrity": "sha512-ZWc51jO3qegGkVh8Hwpv636EkbesNV5ZNQPCtRa+0qytRYPEs9IYT9qITY9buezqUH5uqyzlWLcufrzU2rffdg==",
"license": "MIT" "license": "MIT"
}, },
"node_modules/expo-web-browser": {
"version": "14.0.1",
"resolved": "https://registry.npmjs.org/expo-web-browser/-/expo-web-browser-14.0.1.tgz",
"integrity": "sha512-QM9F3ie+UyIOoBvqFmT6CZojb1vMc2H+7ZlMT5dEu1PL2jtYyOeK2hLfbt/EMt7CBm/w+P29H9W9Y9gdebOkuQ==",
"license": "MIT",
"peerDependencies": {
"expo": "*",
"react-native": "*"
}
},
"node_modules/exponential-backoff": { "node_modules/exponential-backoff": {
"version": "3.1.1", "version": "3.1.1",
"resolved": "https://registry.npmjs.org/exponential-backoff/-/exponential-backoff-3.1.1.tgz", "resolved": "https://registry.npmjs.org/exponential-backoff/-/exponential-backoff-3.1.1.tgz",
@ -9558,22 +9465,6 @@
"node": ">=0.10.0" "node": ">=0.10.0"
} }
}, },
"node_modules/is-nan": {
"version": "1.3.2",
"resolved": "https://registry.npmjs.org/is-nan/-/is-nan-1.3.2.tgz",
"integrity": "sha512-E+zBKpQ2t6MEo1VsonYmluk9NxGrbzpeeLC2xIViuO2EjU2xsXsBPwTr3Ykv9l08UYEVEdWeRZNouaZqF6RN0w==",
"license": "MIT",
"dependencies": {
"call-bind": "^1.0.0",
"define-properties": "^1.1.3"
},
"engines": {
"node": ">= 0.4"
},
"funding": {
"url": "https://github.com/sponsors/ljharb"
}
},
"node_modules/is-number": { "node_modules/is-number": {
"version": "7.0.0", "version": "7.0.0",
"resolved": "https://registry.npmjs.org/is-number/-/is-number-7.0.0.tgz", "resolved": "https://registry.npmjs.org/is-number/-/is-number-7.0.0.tgz",
@ -12452,49 +12343,6 @@
"node": ">=0.10.0" "node": ">=0.10.0"
} }
}, },
"node_modules/object-is": {
"version": "1.1.6",
"resolved": "https://registry.npmjs.org/object-is/-/object-is-1.1.6.tgz",
"integrity": "sha512-F8cZ+KfGlSGi09lJT7/Nd6KJZ9ygtvYC0/UYYLI9nmQKLMnydpB9yvbv9K1uSkEu7FU9vYPmVwLg328tX+ot3Q==",
"license": "MIT",
"dependencies": {
"call-bind": "^1.0.7",
"define-properties": "^1.2.1"
},
"engines": {
"node": ">= 0.4"
},
"funding": {
"url": "https://github.com/sponsors/ljharb"
}
},
"node_modules/object-keys": {
"version": "1.1.1",
"resolved": "https://registry.npmjs.org/object-keys/-/object-keys-1.1.1.tgz",
"integrity": "sha512-NuAESUOUMrlIXOfHKzD6bpPu3tYt3xvjNdRIQ+FeT0lNb4K8WR70CaDxhuNguS2XG+GjkyMwOzsN5ZktImfhLA==",
"license": "MIT",
"engines": {
"node": ">= 0.4"
}
},
"node_modules/object.assign": {
"version": "4.1.5",
"resolved": "https://registry.npmjs.org/object.assign/-/object.assign-4.1.5.tgz",
"integrity": "sha512-byy+U7gp+FVwmyzKPYhW2h5l3crpmGsxl7X2s8y43IgxvG4g3QZ6CffDtsNQy1WsmZpQbO+ybo0AlW7TY6DcBQ==",
"license": "MIT",
"dependencies": {
"call-bind": "^1.0.5",
"define-properties": "^1.2.1",
"has-symbols": "^1.0.3",
"object-keys": "^1.1.1"
},
"engines": {
"node": ">= 0.4"
},
"funding": {
"url": "https://github.com/sponsors/ljharb"
}
},
"node_modules/on-finished": { "node_modules/on-finished": {
"version": "2.3.0", "version": "2.3.0",
"resolved": "https://registry.npmjs.org/on-finished/-/on-finished-2.3.0.tgz", "resolved": "https://registry.npmjs.org/on-finished/-/on-finished-2.3.0.tgz",
@ -13631,6 +13479,23 @@
"react-native-vector-icons": "*" "react-native-vector-icons": "*"
} }
}, },
"node_modules/react-native-paper-dropdown": {
"version": "2.3.1",
"resolved": "https://registry.npmjs.org/react-native-paper-dropdown/-/react-native-paper-dropdown-2.3.1.tgz",
"integrity": "sha512-IvcHTucAV5+fiX2IVMiVdBDKT6KHxycW0o9QzZe7bpmeZWmuCajHDnwG3OSBGlXhUxrrM3TC0/HJZHwORWGgQg==",
"license": "MIT",
"workspaces": [
"example"
],
"dependencies": {
"react-native-paper": "^5.12.3"
},
"peerDependencies": {
"react": "*",
"react-native": "*",
"react-native-paper": "*"
}
},
"node_modules/react-native-paper/node_modules/color": { "node_modules/react-native-paper/node_modules/color": {
"version": "3.2.1", "version": "3.2.1",
"resolved": "https://registry.npmjs.org/color/-/color-3.2.1.tgz", "resolved": "https://registry.npmjs.org/color/-/color-3.2.1.tgz",
@ -13670,6 +13535,8 @@
"resolved": "https://registry.npmjs.org/react-native-reanimated/-/react-native-reanimated-3.16.5.tgz", "resolved": "https://registry.npmjs.org/react-native-reanimated/-/react-native-reanimated-3.16.5.tgz",
"integrity": "sha512-mq/5k14pimkhCeP9XwFJkEr8XufaHqIekum8fqpsn0fcBzbLvyiqfM2LEuBvi0+DTv5Bd2dHmUHkYqGYfkj3Jw==", "integrity": "sha512-mq/5k14pimkhCeP9XwFJkEr8XufaHqIekum8fqpsn0fcBzbLvyiqfM2LEuBvi0+DTv5Bd2dHmUHkYqGYfkj3Jw==",
"license": "MIT", "license": "MIT",
"optional": true,
"peer": true,
"dependencies": { "dependencies": {
"@babel/plugin-transform-arrow-functions": "^7.0.0-0", "@babel/plugin-transform-arrow-functions": "^7.0.0-0",
"@babel/plugin-transform-class-properties": "^7.0.0-0", "@babel/plugin-transform-class-properties": "^7.0.0-0",
@ -13843,6 +13710,8 @@
"resolved": "https://registry.npmjs.org/react-native-webview/-/react-native-webview-13.12.2.tgz", "resolved": "https://registry.npmjs.org/react-native-webview/-/react-native-webview-13.12.2.tgz",
"integrity": "sha512-OpRcEhf1IEushREax6rrKTeqGrHZ9OmryhZLBLQQU4PwjqVsq55iC8OdYSD61/F628f9rURn9THyxEZjrknpQQ==", "integrity": "sha512-OpRcEhf1IEushREax6rrKTeqGrHZ9OmryhZLBLQQU4PwjqVsq55iC8OdYSD61/F628f9rURn9THyxEZjrknpQQ==",
"license": "MIT", "license": "MIT",
"optional": true,
"peer": true,
"dependencies": { "dependencies": {
"escape-string-regexp": "^4.0.0", "escape-string-regexp": "^4.0.0",
"invariant": "2.2.4" "invariant": "2.2.4"

View File

@ -1,7 +1,7 @@
{ {
"name": "traintrape-moi-client", "name": "traintrape-moi-client",
"main": "expo-router/entry", "main": "expo-router/entry",
"version": "1.0.0", "version": "1.1.1",
"scripts": { "scripts": {
"start": "expo start", "start": "expo start",
"android": "expo run:android", "android": "expo run:android",
@ -31,10 +31,8 @@
"expo-constants": "~17.0.3", "expo-constants": "~17.0.3",
"expo-dev-client": "~5.0.4", "expo-dev-client": "~5.0.4",
"expo-font": "~13.0.1", "expo-font": "~13.0.1",
"expo-haptics": "~14.0.0",
"expo-linking": "~7.0.3", "expo-linking": "~7.0.3",
"expo-location": "^18.0.2", "expo-location": "^18.0.2",
"expo-notifications": "~0.29.11",
"expo-router": "~4.0.9", "expo-router": "~4.0.9",
"expo-secure-store": "~14.0.0", "expo-secure-store": "~14.0.0",
"expo-share-intent": "^3.1.1", "expo-share-intent": "^3.1.1",
@ -44,7 +42,6 @@
"expo-system-ui": "~4.0.4", "expo-system-ui": "~4.0.4",
"expo-task-manager": "^12.0.3", "expo-task-manager": "^12.0.3",
"expo-updates": "~0.26.10", "expo-updates": "~0.26.10",
"expo-web-browser": "~14.0.1",
"maplibre-gl": "^4.7.1", "maplibre-gl": "^4.7.1",
"maplibre-react-components": "^0.1.9", "maplibre-react-components": "^0.1.9",
"react": "18.3.1", "react": "18.3.1",
@ -53,11 +50,10 @@
"react-native": "0.76.3", "react-native": "0.76.3",
"react-native-gesture-handler": "~2.20.2", "react-native-gesture-handler": "~2.20.2",
"react-native-paper": "^5.12.5", "react-native-paper": "^5.12.5",
"react-native-reanimated": "~3.16.1", "react-native-paper-dropdown": "^2.3.1",
"react-native-safe-area-context": "~4.12.0", "react-native-safe-area-context": "~4.12.0",
"react-native-screens": "~4.1.0", "react-native-screens": "~4.1.0",
"react-native-web": "~0.19.13", "react-native-web": "~0.19.13",
"react-native-webview": "13.12.2",
"react-redux": "^9.1.2", "react-redux": "^9.1.2",
"socket.io-client": "^4.8.1" "socket.io-client": "^4.8.1"
}, },

View File

@ -1,4 +1,6 @@
import { createSlice, PayloadAction } from '@reduxjs/toolkit' import { createSlice, PayloadAction } from '@reduxjs/toolkit'
import { Accuracy } from 'expo-location'
import * as SecureStore from '@/utils/SecureStore'
export interface RunPayload { export interface RunPayload {
id: number id: number
@ -20,6 +22,13 @@ export interface PenaltyPayload {
penaltyEnd: number | null penaltyEnd: number | null
} }
export interface Player {
id: number
name: string
money: number
activeChallengeId: number | null
}
export interface GameState { export interface GameState {
playerId: number | null playerId: number | null
runId: number | null runId: number | null
@ -30,6 +39,11 @@ export interface GameState {
chaseFreeTime: number | null // date chaseFreeTime: number | null // date
penaltyStart: number | null // date penaltyStart: number | null // date
penaltyEnd: number | null //date penaltyEnd: number | null //date
settings: Settings
}
export interface Settings {
locationAccuracy: Accuracy | null
} }
const initialState: GameState = { const initialState: GameState = {
@ -42,6 +56,9 @@ const initialState: GameState = {
chaseFreeTime: null, chaseFreeTime: null,
penaltyStart: null, penaltyStart: null,
penaltyEnd: null, penaltyEnd: null,
settings: {
locationAccuracy: Accuracy.Highest,
}
} }
export const gameSlice = createSlice({ export const gameSlice = createSlice({
@ -70,10 +87,14 @@ export const gameSlice = createSlice({
updatePenalty: (state, action: PayloadAction<PenaltyPayload>) => { updatePenalty: (state, action: PayloadAction<PenaltyPayload>) => {
state.penaltyStart = action.payload.penaltyStart state.penaltyStart = action.payload.penaltyStart
state.penaltyEnd = action.payload.penaltyEnd state.penaltyEnd = action.payload.penaltyEnd
},
setLocationAccuracy: (state, action: PayloadAction<Accuracy | null>) => {
state.settings.locationAccuracy = action.payload
SecureStore.setItem('locationAccuracy', action.payload?.toString() ?? 'null')
} }
}, },
}) })
export const { setPlayerId, updateMoney, updateActiveChallengeId, updateGameState, updatePenalty } = gameSlice.actions export const { setLocationAccuracy, setPlayerId, updateMoney, updateActiveChallengeId, updateGameState, updatePenalty } = gameSlice.actions
export default gameSlice.reducer export default gameSlice.reducer

View File

@ -1,6 +1,7 @@
import { Constants } from '@/constants/Constants'
import { createSlice, PayloadAction } from '@reduxjs/toolkit' import { createSlice, PayloadAction } from '@reduxjs/toolkit'
import { LocationObject } from 'expo-location' import { LocationObject } from 'expo-location'
import { Constants } from '@/constants/Constants'
export type PlayerLocation = { export type PlayerLocation = {
id?: number id?: number

View File

@ -5,8 +5,11 @@ import { PlayerLocation, setLastLocation } from './features/location/locationSli
import store from './store' import store from './store'
import { useEffect } from 'react' import { useEffect } from 'react'
import { socket } from './socket' import { socket } from './socket'
import { useSettings } from '@/hooks/useGame'
import { useAuth } from '@/hooks/useAuth'
import { isAuthValid } from './features/auth/authSlice'
const LOCATION_TASK = "fetch-geolocation" const LOCATION_TASK = "TRAINTRAPE_MOI_GEOLOCATION"
TaskManager.defineTask(LOCATION_TASK, async ({ data, error }: any) => { TaskManager.defineTask(LOCATION_TASK, async ({ data, error }: any) => {
if (error) { if (error) {
@ -15,8 +18,9 @@ TaskManager.defineTask(LOCATION_TASK, async ({ data, error }: any) => {
} }
const { locations } = data const { locations } = data
const lastLoc: Location.LocationObject = locations.at(-1) const lastLoc: Location.LocationObject = locations.at(-1)
if (__DEV__)
console.log("Localisation reçue :", lastLoc)
store.dispatch(setLastLocation(lastLoc)) store.dispatch(setLastLocation(lastLoc))
console.log("sending-loc", lastLoc, socket.active)
const playerId = store.getState().game.playerId const playerId = store.getState().game.playerId
if (socket.active && playerId) { if (socket.active && playerId) {
const lastLocToSend: PlayerLocation = { const lastLocToSend: PlayerLocation = {
@ -25,17 +29,20 @@ TaskManager.defineTask(LOCATION_TASK, async ({ data, error }: any) => {
latitude: lastLoc.coords.latitude, latitude: lastLoc.coords.latitude,
speed: lastLoc.coords.speed ?? 0, speed: lastLoc.coords.speed ?? 0,
accuracy: lastLoc.coords.accuracy ?? 0, accuracy: lastLoc.coords.accuracy ?? 0,
altitude: lastLoc.coords.accuracy ?? 0, altitude: lastLoc.coords.altitude ?? 0,
altitudeAccuracy: lastLoc.coords.altitudeAccuracy ?? 0, altitudeAccuracy: lastLoc.coords.altitudeAccuracy ?? 0,
timestamp: new Date(lastLoc.timestamp).toISOString(), timestamp: new Date(lastLoc.timestamp).toISOString(),
} }
socket.emit('last-location', { playerId: playerId, loc: lastLocToSend }) socket.emit('last-location', lastLocToSend)
} }
}) })
export async function startGeolocationService(): Promise<void | (() => void)> { export async function startGeolocationService(locationAccuracy: Location.Accuracy | null): Promise<void | (() => void)> {
if (Platform.OS !== "web" && await Location.hasStartedLocationUpdatesAsync(LOCATION_TASK)) if (Platform.OS !== "web" && await Location.hasStartedLocationUpdatesAsync(LOCATION_TASK))
return async () => await Location.stopLocationUpdatesAsync(LOCATION_TASK) await Location.stopLocationUpdatesAsync(LOCATION_TASK)
if (locationAccuracy === null)
return
await Location.enableNetworkProviderAsync().catch(error => alert(error)) await Location.enableNetworkProviderAsync().catch(error => alert(error))
@ -49,10 +56,10 @@ export async function startGeolocationService(): Promise<void | (() => void)> {
if (Platform.OS !== "web") { if (Platform.OS !== "web") {
await Location.startLocationUpdatesAsync(LOCATION_TASK, { await Location.startLocationUpdatesAsync(LOCATION_TASK, {
accuracy: Location.Accuracy.BestForNavigation, accuracy: locationAccuracy,
activityType: Location.ActivityType.OtherNavigation, activityType: Location.ActivityType.OtherNavigation,
deferredUpdatesInterval: 100, distanceInterval: 10,
timeInterval: 100, timeInterval: 1000,
foregroundService: { foregroundService: {
killServiceOnDestroy: false, killServiceOnDestroy: false,
notificationBody: "Géolocalisation activée pour « Traintrape-moi »", notificationBody: "Géolocalisation activée pour « Traintrape-moi »",
@ -63,13 +70,19 @@ export async function startGeolocationService(): Promise<void | (() => void)> {
return async () => await Location.stopLocationUpdatesAsync(LOCATION_TASK) return async () => await Location.stopLocationUpdatesAsync(LOCATION_TASK)
} }
else { else {
const locationSubscription = await Location.watchPositionAsync({accuracy: Location.Accuracy.BestForNavigation}, location_nouveau => store.dispatch(setLastLocation(location_nouveau))) const locationSubscription = await Location.watchPositionAsync({ accuracy: locationAccuracy }, location_nouveau => store.dispatch(setLastLocation(location_nouveau)))
return locationSubscription.remove return locationSubscription.remove
} }
} }
export const useStartGeolocationServiceEffect = () => useEffect(() => { export const useStartGeolocationServiceEffect = () => {
let cleanup: void | (() => void) = () => {} const auth = useAuth()
startGeolocationService().then(result => cleanup = result) const settings = useSettings()
return cleanup return useEffect(() => {
}, []) if (!isAuthValid(auth))
return
let cleanup: void | (() => void) = () => {}
startGeolocationService(settings.locationAccuracy).then(result => cleanup = result)
return cleanup
}, [auth, settings.locationAccuracy])
}

View File

@ -1,5 +1,3 @@
import { io } from 'socket.io-client' import { io } from 'socket.io-client'
export const socket = io("http://192.168.1.198:3000", { export const socket = io(process.env.EXPO_PUBLIC_TRAINTRAPE_MOI_SOCKET)
reconnection: true,
})

View File

@ -1,3 +1,4 @@
DATABASE_URL="postgres://username:password@localhost:5432/traintrape-moi" DATABASE_URL="postgres://username:password@localhost:5432/traintrape-moi"
JWT_SECRET="CHANGE_ME" JWT_SECRET="CHANGE_ME"
API_GLOBAL_PREFIX="api" API_GLOBAL_PREFIX="api"
API_HOSTNAME="traintrape-moi.luemy.eu"

View File

@ -1,6 +1,6 @@
{ {
"name": "traintrape-moi-server", "name": "traintrape-moi-server",
"version": "0.0.1", "version": "1.1.1",
"description": "", "description": "",
"author": "", "author": "",
"private": true, "private": true,

View File

@ -1,8 +1,13 @@
export const Constants = { export const Constants = {
/** /**
* Nombre de points attribués au début de la partie * Nombre de points attribués au début de la partie pour la première joueuse
*/ */
INITIAL_MONEY: 2000, INITIAL_MONEY_1ST_PLAYER: 1500,
/**
* Nombre de points attribués au début de la partie pour la première joueuse
*/
INITIAL_MONEY_2ND_PLAYER: 1000,
/** /**
* Nombre de points attribués lors d'une nouvelle tentative * Nombre de points attribués lors d'une nouvelle tentative

View File

@ -20,16 +20,16 @@ export class GameService {
const alreadyStarted = game.currentRunId !== null const alreadyStarted = game.currentRunId !== null
let run let run
if (!alreadyStarted) { if (!alreadyStarted) {
const runnerId = players[Math.floor(players.length * Math.random())].id
for (const player of players) { for (const player of players) {
await this.prisma.moneyUpdate.create({ await this.prisma.moneyUpdate.create({
data: { data: {
playerId: player.id, playerId: player.id,
amount: Constants.INITIAL_MONEY, amount: player.id === runnerId ? Constants.INITIAL_MONEY_1ST_PLAYER : Constants.INITIAL_MONEY_2ND_PLAYER,
reason: MoneyUpdateType.START, reason: MoneyUpdateType.START,
} }
}) })
} }
const runnerId = players[Math.floor(players.length * Math.random())].id
run = await this.prisma.playerRun.create({ run = await this.prisma.playerRun.create({
data: { data: {
gameId: game.id, gameId: game.id,

View File

@ -1,7 +1,9 @@
import { SubscribeMessage, WebSocketGateway, WebSocketServer } from '@nestjs/websockets' import { SubscribeMessage, WebSocketGateway, WebSocketServer } from '@nestjs/websockets'
import { Server, Socket } from 'socket.io' import { Server, Socket } from 'socket.io'
@WebSocketGateway() @WebSocketGateway({
cors: { allowedHeaders: process.env.API_HOSTNAME },
})
export class GeolocationsGateway { export class GeolocationsGateway {
@WebSocketServer() @WebSocketServer()
server: Server server: Server

View File

@ -10,10 +10,11 @@ async function bootstrap() {
app.useGlobalPipes(new ValidationPipe({ transform: true })) app.useGlobalPipes(new ValidationPipe({ transform: true }))
app.useGlobalInterceptors(new ClassSerializerInterceptor(app.get(Reflector))) app.useGlobalInterceptors(new ClassSerializerInterceptor(app.get(Reflector)))
const { version } = require('../../package.json')
const config = new DocumentBuilder() const config = new DocumentBuilder()
.setTitle('Traintrape-moi') .setTitle('Traintrape-moi')
.setDescription('API permettant de stocker les données de Traintrape-moi') .setDescription('API permettant de stocker les données de Traintrape-moi')
.setVersion('1.0') .setVersion(version)
.addBearerAuth() .addBearerAuth()
.build() .build()
const document = SwaggerModule.createDocument(app, config) const document = SwaggerModule.createDocument(app, config)