This document describes the new location tracking and direction features added to the ETH Date NFC scanner app.
- GPS Tracking: Continuously tracks your device's GPS location
- WebSocket Communication: Sends location updates to the backend server in real-time
- Auto-reconnection: Automatically reconnects to the WebSocket server if connection is lost
- Selected Users: Shows directions to randomly selected male and female users
- Distance Calculation: Displays distance in meters or kilometers
- Compass View: Visual compass showing direction arrows
- Cardinal Directions: Shows N, S, E, W, NE, SW, etc.
- Location Status: Shows current GPS coordinates and accuracy
- Connection Status: Displays WebSocket connection status
- User Cards: Separate cards for male and female selected users
- Real-time Updates: Direction and distance update as you move
The app connects to the WebSocket server defined in etgl.ts at ws://localhost:3002. The backend:
- Receives GPS coordinates from all connected users
- Randomly selects one male and one female user every hour
- Broadcasts selected users to all connected clients
- Handles proximity verification for user interactions
- Distance: Uses the Haversine formula to calculate distances between coordinates
- Bearing: Calculates the compass bearing from your location to target users
- Direction: Converts bearing to cardinal directions (N, NE, E, SE, etc.)
The app sends and receives these message types:
gps_update: Location coordinatesselected_users: Currently selected male/female usersping/pong: Keep-alive messages
For development and testing purposes, you can use a fixed user ID:
# Using npm
DEV=true npm run dev
# Using bun
DEV=true bun run dev
# Or use the predefined script
npm run dev:debugWhen DEV=true is set, the app will:
- Use the fixed user ID
1d7s7plinstead of generating a random one - Display "DEV MODE" badge in the UI
- Log development information to the console
- Bypass NFC support checks - works on desktop browsers without NFC
- Mock NFC scanning - simulate NFC tag detection with test profile URLs
- Show "Simulate Scan" instead of "Start Scan" button
- Use localhost URLs - automatically connects to local backend services
The app uses the following priority for determining user ID:
- Development Mode: Fixed ID
1d7s7pl(whenDEV=true) - Profile UUID: Uses
profileData.uuidfrom scanned ETHGlobal profile - Fallback: Generates random ID if no profile is available
Visual indicators show which ID source is being used:
- 🟡 DEV MODE: Development fixed ID
- 🟢 PROFILE UUID: Real ETHGlobal profile UUID
- ⚪ FALLBACK: Generated random ID
When DEV=true, the app automatically uses localhost URLs for all backend services:
API Endpoints:
- Development:
http://localhost:3000/api/etgl - Production:
https://arweave.tech/api/etgl
WebSocket Connection:
- Development:
ws://localhost:3002 - Production:
wss://arweave.tech:3002
Mock Profile URLs:
http://localhost:3000/connect/1d7s7plhttp://localhost:3000/connect/testuser1http://localhost:3000/connect/testuser2
Environment Variable Overrides: You can override the default URLs using environment variables:
# Custom API URL
NEXT_PUBLIC_API_URL=http://localhost:8080/api/etgl
# Custom WebSocket URL
NEXT_PUBLIC_WS_URL=ws://localhost:8081
# Run with custom URLs
DEV=true NEXT_PUBLIC_API_URL=http://localhost:8080/api/etgl npm run devIn development mode, the NFC functionality is enhanced for desktop testing:
- No NFC Hardware Required: Works on any desktop browser
- Mock Profile URLs: Uses localhost URLs for testing with local backend
- Simulated Delay: 2-second delay to mimic real NFC tag detection
- Visual Feedback: Shows "Simulating..." and "DEV MODE" badges
- Open the app in a compatible browser (Chrome/Edge with HTTPS)
- Grant location permissions when prompted
- Location tracking starts automatically
- The WebSocket connection establishes automatically
- Wait for users to be selected (happens automatically)
- View the direction cards showing:
- Gender symbol (♂️/♀️)
- Direction arrow pointing toward the user
- Cardinal direction (N, NE, E, etc.)
- Distance in meters/kilometers
- Exact bearing in degrees
- Blue arrow points to selected male user
- Pink arrow points to selected female user
- Compass shows N, E, S, W directions
- Arrows update in real-time as you move
- Chrome 89+ or Edge 89+ (NFC and WebSocket support)
- HTTPS required for location services
- Location permissions must be granted
- WebSocket server running on port 3002
- Backend API at
https://arweave.tech/api/etgl/ - Selected users data available from backend
- Location: Required for GPS tracking
- NFC: Required for profile scanning (existing feature)
- GPS coordinates are only shared with the backend server
- Data is used for proximity calculations and direction finding
- No location history is permanently stored
- User IDs are randomly generated and stored locally
- Connection uses standard WebSocket protocol
- Consider upgrading to WSS (secure WebSocket) for production
- Location data transmission should be encrypted in production
"Location access denied"
- Grant location permissions in browser settings
- Ensure HTTPS is being used
- Check if location services are enabled on device
"WebSocket connection failed"
- Verify backend server is running on port 3002
- Check firewall settings
- Ensure WebSocket server is properly initialized
"No users selected"
- Wait for backend to select users (happens every hour)
- Check if other users are connected and sharing locations
- Verify backend has user profiles with gender data
Inaccurate directions
- Wait for GPS accuracy to improve (may take 30-60 seconds)
- Move to an area with better GPS signal
- Check if target users are also sharing accurate locations
The app displays:
- Current GPS coordinates and accuracy
- WebSocket connection status
- User ID for debugging
- Selected users timestamp
app/hooks/useLocation.js: Location tracking and WebSocket logicapp/components/LocationTracker.js: UI component for location displayapp/components/NFCScanner.js: Main component with integrated location features
startTracking(): Begins GPS tracking and WebSocket connectiongetDirectionInfo(): Calculates directions to selected userscalculateDistance(): Haversine distance calculationcalculateBearing(): Compass bearing calculation
- Connection management with auto-reconnection
- Real-time location broadcasting
- Selected user updates
- Ping/pong keep-alive mechanism