Skip to content

mahmud-r-farhan/Realtime-Location-Tracker

Folders and files

NameName
Last commit message
Last commit date

Latest commit

Β 

History

28 Commits
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 

Real-Time Location Tracker Documentation

The Real-Time Location Tracker is a web application designed to monitor and track the real-time locations of connected devices. It leverages interactive map visualizations (Leaflet), instant communication (WebSockets), and real-time audio communication (WebRTC). The application is suitable for various use cases, including:

  • Fleet management
  • Delivery tracking
  • Team coordination
  • Personal location sharing
  • Emergency response with SOS alerts

The application provides a responsive design for a consistent user experience across desktops, tablets, and smartphones. It also supports offline map functionality and PWA installation.


πŸš€ Features

Core Features

  • Real-Time Tracking: Track device locations with continuous real-time updates
  • Smart Device Identification: Recognizes and categorizes devices based on user agent strings
  • Device Connection Panel: View a list of connected devices and their active status
  • Customizable Icons: Unique icons for different device types
  • Offline Map Support: Intelligent switching between online and offline map modes
  • Responsive Design: Optimized for all devices
  • Interactive Popups: View details of connected devices

Communication Features

  • Audio Communication (WebRTC): Real-time voice communication among connected devices
  • Broadcast Call: "Megaphone" feature to invite all users to a call
  • Live Chat Messaging: Send instant text messages using WebSockets
  • Locate via Chat: Click any message to instantly find the sender on the map
  • Activity Logs: A comprehensive log system that tracks server notifications, connection events, and disconnections

πŸ†˜ Emergency SOS Feature (NEW in v4.0)

  • SOS Button: Hold for 2 seconds to send an emergency alert to ALL connected users
  • Instant Location Sharing: Your real-time GPS coordinates are immediately shared
  • Device Details: Includes battery level, connection type, and platform info
  • IP Geolocation: Shows approximate location based on IP address
  • Audio Alert: Alarm sound plays on all receiving devices
  • SOS Modal: View and manage all SOS alerts in one place
  • Browser Notifications: Push notifications for SOS alerts (when permitted)
  • Vibration Support: Mobile devices vibrate when receiving SOS

πŸ“± Progressive Web App (PWA)

  • Installable: Install the app on your home screen like a native app
  • Offline Support: Core functionality works even without internet
  • Push Notifications: Receive alerts even when the app is closed
  • Auto Updates: Automatically update to the latest version

Prerequisites

  • Node.js: v18 or higher
  • npm: v8 or higher

Folder Structure

realtime-location-tracker/
β”œβ”€β”€ public/
β”‚   β”œβ”€β”€ assets/
β”‚   β”‚   β”œβ”€β”€ icons/              # PWA icons
β”‚   β”‚   β”œβ”€β”€ android-log.png
β”‚   β”‚   β”œβ”€β”€ ios-log.png
β”‚   β”‚   β”œβ”€β”€ windows-log.png
β”‚   β”‚   β”œβ”€β”€ mac-log.png
β”‚   β”‚   β”œβ”€β”€ unknown-log.png
β”‚   β”‚   β”œβ”€β”€ microphone-*.png
β”‚   β”‚   β”œβ”€β”€ speaker-*.png
β”‚   β”‚   └── favico.png
β”‚   β”œβ”€β”€ css/
β”‚   β”‚   β”œβ”€β”€ style.css
β”‚   β”‚   β”œβ”€β”€ panel.css
β”‚   β”‚   β”œβ”€β”€ device.css
β”‚   β”‚   β”œβ”€β”€ chat.css
β”‚   β”‚   β”œβ”€β”€ audio.css
β”‚   β”‚   β”œβ”€β”€ notification.css
β”‚   β”‚   β”œβ”€β”€ popup.css
β”‚   β”‚   β”œβ”€β”€ responsive.css
β”‚   β”‚   β”œβ”€β”€ icon.css
β”‚   β”‚   β”œβ”€β”€ sos.css
β”‚   β”œβ”€β”€ js/
β”‚   β”‚   β”œβ”€β”€ main.js             # Main app orchestrator
β”‚   β”‚   β”œβ”€β”€ config.js           # Configuration constants
β”‚   β”‚   β”œβ”€β”€ device.js           # Device detection
β”‚   β”‚   β”œβ”€β”€ map.js              # Leaflet map management
β”‚   β”‚   β”œβ”€β”€ socket.js           # Socket.IO handlers
β”‚   β”‚   β”œβ”€β”€ ui.js               # UI components
β”‚   β”‚   β”œβ”€β”€ notification.js     # Notification system
β”‚   β”‚   β”œβ”€β”€ chat.js             # Chat functionality
β”‚   β”‚   β”œβ”€β”€ audio.js            # WebRTC audio
β”‚   β”‚   β”œβ”€β”€ sos.js              # πŸ†˜ SOS emergency module
β”‚   β”‚   └── pwa.js              # PWA management
β”‚   β”œβ”€β”€ manifest.json           # PWA manifest
β”‚   β”œβ”€β”€ sw.js                   # Service Worker
β”‚   └── offline.html            # Offline fallback page
β”œβ”€β”€ views/
β”‚   └── index.ejs               # Main view template
β”œβ”€β”€ app.js                      # Express server
β”œβ”€β”€ package.json
β”œβ”€β”€ dockerfile
└── README.md

Installation

  1. Clone the Repository:
git clone https://github.com/mahmud-r-farhan/realtime-location-tracker.git
cd realtime-location-tracker
  1. Install Dependencies:
npm install
  1. Run the Application:
npm start
  1. Open in Browser:
http://localhost:3007

Usage

  1. Open http://localhost:3007 in a web browser
  2. Grant location access when prompted
  3. View the real-time locations of connected devices on the map
  4. Click on device markers to view detailed information

Using SOS Emergency Feature

  1. Quick Access: Look for the red SOS button in the top-right corner
  2. Sending SOS:
    • Hold the SOS button for 2 seconds to send an emergency alert
    • The button will show a progress indicator while holding
    • Upon release after 2 seconds, an SOS is sent to ALL connected users
  3. SOS Information Shared:
    • Your real-time GPS location (latitude, longitude, accuracy)
    • Device information (platform, battery level, connection type)
    • IP address and approximate location
    • Timestamp
  4. Receiving SOS:
    • An alarm sound will play
    • Mobile devices will vibrate
    • A modal will open showing the SOS details
    • You can click "View on Map" to see the sender's location
  5. Managing SOS Alerts:
    • Click the SOS button (short press) to open the SOS modal
    • View all recent SOS alerts in the "SOS Alerts" tab
    • Dismiss alerts once addressed

Installing as PWA

  1. Chrome/Firefox (Desktop): Click the install icon in the address bar
  2. Chrome (Android): Tap "Add to Home Screen" from the menu
  3. Safari (iOS): Tap Share β†’ "Add to Home Screen"

API Events

Socket.IO Events

Event Direction Description
join-room Client β†’ Server Join a specific Organization/Fleet
send-location Client β†’ Server Send device location
receive-location Server β†’ Client Receive location updates (Room Scoped)
sos-alert Bidirectional Emergency SOS broadcast (Room Scoped)
request-join-call Client β†’ Server Broadcast invitation to join call
chat-message Bidirectional Chat messages (Room Scoped)
join-audio Client β†’ Server Join audio channel (Room Scoped)
user-connected Server β†’ Client New user notification
user-disconnect Server β†’ Client User left notification

Live Demo

  • Live: Render Deployment
  • Invite multiple users to test tracking, chat, and SOS features!

Deployment Options

Docker Deployment

# Build the image
docker build -t realtime-location-tracker .

# Run the container
docker run -p 3007:3007 --name tracker -d realtime-location-tracker

# Access at http://localhost:3007

Docker Compose

docker-compose up -d

Contact


FAQ

Q: How accurate is the GPS? A: Depends on device hardware (typically Β±5-50 meters).

Q: Can I use custom map providers? A: Yes! Use the new Layer Control to switch between default maps, or edit map.js to add more.

Q: Is the SOS feature secure? A: SOS alerts are broadcast to all connected users only. Data is sanitized server-side.

Q: Does the app work offline? A: Yes! The PWA caches assets and shows an offline page when connectivity is lost.


Troubleshooting

  • Location Not Updating: Ensure geolocation is enabled and the browser has permission
  • WebSocket Errors: Verify port 3007 is open and not blocked by a firewall
  • SOS Not Working: Check browser notification permissions and microphone access
  • PWA Not Installing: Ensure you're accessing via HTTPS or localhost
  • WebRTC Issues: Check STUN/TURN server configurations and network connectivity

Star this project if you find it helpful! ⭐

Checkout: https://github.com/mahmud-js/realtime-tracker (Golang powered!)

About

The Real-Time Location Tracker is a PWA designed to monitor and track the real-time locations of connected devices. It leverages interactive map visualizations (Leaflet), instant communication (WebSockets), and real-time audio communication (WebRTC).

Topics

Resources

License

Code of conduct

Contributing

Security policy

Stars

Watchers

Forks