Skip to content

About

No description, website, or topics provided.

Resources

Stars

0 stars

Watchers

0 watching

Forks

Latest commit

ย 

History

5 Commits

Folders and files

Repository files navigation

๐Ÿšจ Emergency SOS & Live Location Tracking

A modern, high-reliability web application designed to broadcast emergency alerts, share precise live GPS location coordinates, and immediately notify emergency contacts through rich email alerts and Web Push notifications.

Developed with a tactical cyberpunk design, this application enables users to trigger an emergency alert with a single tap, continuously refine GPS accuracy, maintain a real-time audit log of activations, and manage emergency contacts directly through an intuitive dashboard interface.


โœจ Features

  • ๐Ÿšจ One-Click Emergency SOS: Instant activation with confirmation prompt, animated visual feedback, and local siren audio alerts.
  • ๐Ÿ“ High-Precision GPS Location Detection: Integrates Web Geolocation API with continuous sample refinement (watchPosition) to capture tight accuracy margins (ยฑX meters).
  • ๐Ÿ—บ๏ธ Google Maps Pinpoint Location Link: Automatically generates official Google Maps pin-drop search URLs for instant responder navigation.
  • ๐Ÿ“ง Emergency Email Alerts: Sends rich HTML emergency emails via Nodemailer (Gmail SMTP) containing sender details, coordinates, accuracy radius, map link, and timestamp.
  • ๐Ÿ“ฒ Firebase Web Push Notifications (FCM): Public receiver opt-in page (/receive) that registers browser push tokens to deliver background alerts even when tabs are closed.
  • ๐Ÿ‘ฅ Dynamic Contact Management: Add emergency email contacts directly from the dashboard UI, share opt-in links, or remove contacts with one click.
  • ๐Ÿ‘ค Configurable Sender Profile: Customized sender profile name displayed in emergency broadcast emails.
  • โฐ Timestamped Emergency Broadcasts: Tracks exact activation time in Indian Standard Time (IST) / local device timezone.
  • ๐Ÿ“œ Real-Time SOS Alert History Logs: Dedicated audit log table capturing timestamped alert activations, GPS coordinates, recipient counts, and dispatch status.
  • โš™๏ธ Interactive Multi-Tab Dashboard: Smooth single-page navigation across Dashboard (OVERVIEW), Contacts (DIRECTORY), Alert Logs (LOGS), and Settings (PREFERENCES).
  • ๐Ÿงช One-Click Diagnostic Test Email: On-demand SMTP test trigger in Settings to verify email delivery without starting a full emergency alarm.
  • ๐Ÿ”Š Alarm Sound Control: Toggle loud emergency siren audio on/off from the Settings panel.
  • ๐Ÿ“ฑ Tactical Cyberpunk UI: Fully responsive glassmorphic dark-mode user interface tailored for desktop and mobile displays.

๐Ÿ“ง Emergency Email

When the SOS alert is activated, the application generates and dispatches an emergency email notification via Gmail SMTP to all designated contacts.

Email Payload Details:

  • User's Name: Displayed in the subject line and email body.
  • Emergency Message: High-priority alert banner requesting immediate assistance.
  • Latitude & Longitude: High-precision GPS coordinates.
  • GPS Accuracy Margin: Radius precision indicator (e.g., ยฑ12 m).
  • Google Maps Pin Drop Link: Direct URL to open the exact coordinates in Google Maps.
  • Live Tracking Link: URL to access the web application interface.
  • SOS Activation Timestamp: Formatted date and time of the alert trigger.

Multiple Contact Support:

The system automatically queries active contacts stored in Firestore (both Web Push recipients and direct Email contacts) and sends emergency broadcast emails to all contact email addresses simultaneously.


๐Ÿ—บ๏ธ Live Location Tracking

The application uses the browser's native Geolocation API combined with position refinement logic to track and display the user's location.

How Location Refinement Works:

  1. Continuous Sampling: When SOS is triggered, watchPosition() streams continuous GPS position updates over a 3-second window.
  2. Accuracy Selection: The system evaluates incoming position samples and selects the coordinate with the smallest accuracy margin (tightest precision).
  3. UI Display: The status header bar updates in real time displaying live coordinates and precision radius (e.g., Live: 13.07028, 77.57053 (ยฑ12m)).
  4. Responder View: Emergency contacts receive a direct Google Maps link (https://www.google.com/maps/search/?api=1&query=LAT,LNG) that drops a target pin exactly on the user's location.

๐Ÿ› ๏ธ Technologies Used

Frontend:

  • HTML5: Semantic web structure and accessible forms.
  • Vanilla JavaScript (ES6+): ES Modules, Async/Await, Web Geolocation API, Web Audio API, Service Workers API.
  • CSS3: Custom CSS Variables, Glassmorphism backdrop-filters, CSS Grid, Flexbox, Keyframe Animations.

Backend:

  • Node.js: Asynchronous JavaScript runtime.
  • Express.js: Lightweight REST API web framework.
  • Nodemailer: Email engine for Gmail SMTP transport.
  • Firebase Admin SDK: Server-side Firestore database operations and FCM multicast messaging.

Database & Cloud Services:

  • Firebase Firestore: Cloud NoSQL database storing registered contacts and alert history logs.
  • Firebase Cloud Messaging (FCM): Web Push notification delivery service.

Utilities & Developer Tools:

  • Dotenv: Environment variable configuration management.
  • CORS: Cross-Origin Resource Sharing middleware.
  • Nodemon: Development server auto-reloader.

๐Ÿ“ Project Structure

SOS-EmergencyApp/
โ”œโ”€โ”€ index.html                  # Main Dashboard UI (Dashboard, Contacts, Logs, Settings)
โ”œโ”€โ”€ script.js                   # Main Frontend Application Logic & View Navigation
โ”œโ”€โ”€ style.css                   # Custom CSS Design Tokens & Glassmorphism Styling
โ”œโ”€โ”€ receive.html                # Public Contact Opt-in Page (FCM Token & Email Registration)
โ”œโ”€โ”€ receive.js                  # ES Module for FCM Browser Push Registration
โ”œโ”€โ”€ firebase-messaging-sw.js    # Service Worker handling background Web Push Notifications
โ”œโ”€โ”€ server.js                   # Node.js Express Server (Nodemailer, Firestore & API Endpoints)
โ”œโ”€โ”€ package.json                # Dependencies, Scripts, and Project Metadata
โ”œโ”€โ”€ .env.example                # Example Environment Configuration Template
โ””โ”€โ”€ README.md                   # Project Documentation

โš™๏ธ Installation

Follow these steps to run the application locally on your system:

1. Clone Repository

git clone https://github.com/tejas-coder28/SOS-EmergencyApp.git

2. Enter Project Directory

cd SOS-EmergencyApp

3. Install Dependencies

npm install

4. Configure Environment Variables

Copy .env.example to create your local .env file:

cp .env.example .env

5. Start Development Server

npm run dev

(or run npm start to run in standard Node.js mode).

Open your browser and navigate to http://localhost:3000.


๐Ÿ” Environment Variables

The application relies on environment variables configured in .env.

.env.example Template:

# โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€
# Email โ€” Emergency Alert (Nodemailer + Gmail SMTP)
# โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€
EMAIL_USER="your_email@gmail.com"
EMAIL_PASS="your_16_char_app_password"
EMAIL_TO=""
ALERT_USER_NAME="Your Name"

# Server Configuration
PORT="3000"
NODE_ENV="development"

# โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€
# Firebase โ€” FCM Web Push & Firestore
# โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€
GOOGLE_APPLICATION_CREDENTIALS="./firebase-service-account.json"
FIREBASE_PROJECT_ID="your_project_id"
FIREBASE_API_KEY="your_api_key"
FIREBASE_AUTH_DOMAIN="your_auth_domain.firebaseapp.com"
FIREBASE_STORAGE_BUCKET="your_storage_bucket.appspot.com"
FIREBASE_MESSAGING_SENDER_ID="your_messaging_sender_id"
FIREBASE_APP_ID="your_app_id"
FIREBASE_VAPID_KEY="your_web_push_vapid_key"

โš ๏ธ IMPORTANT: .env and firebase-service-account.json contain sensitive private credentials. They are listed in .gitignore and must NEVER be committed to GitHub.


๐Ÿ“ง Email Configuration

Email alerts use Nodemailer configured with Gmail SMTP.

How to Configure Gmail App Password:

  1. Enable 2-Step Verification on your Google Account: https://myaccount.google.com/security
  2. Generate a 16-character App Password: https://myaccount.google.com/apppasswords
  3. Set EMAIL_USER to your Gmail address and EMAIL_PASS to the 16-character App Password in .env:
    EMAIL_USER="user@gmail.com"
    EMAIL_PASS="abcd efgh ijkl mnop"

๐Ÿš€ How to Use

  1. Launch App: Open http://localhost:3000 in your web browser.
  2. Grant Location Permission: Allow the browser to access device location when prompted.
  3. Add Emergency Contacts:
    • Option A: Click "๐Ÿ“ฒ INVITE CONTACT" and share the /receive link with contacts so they can enable browser push notifications & register their email.
    • Option B: Type a contact's Name and Email directly into the Add Recipient Email Directly form on the modal or Contacts tab.
  4. Activate SOS: Press the large red SOS button on the Dashboard and confirm in the prompt modal.
  5. Alert Broadcast:
    • The status bar displays SENDING SOSโ€ฆ and starts the local audio alarm (if enabled).
    • The backend fetches all active contacts from Firestore and dispatches emergency emails and Web Push alerts.
    • Button updates to โœ“ ALERT SENT and resets after 8 seconds.
  6. Audit & Verification:
    • View the activation log in the Alert Logs tab.
    • Run diagnostic email checks anytime from the Settings tab.

๐Ÿงช Testing

You can safely test all components of the application:

  • Location Tracking Test: Verify that the top header pill displays Live: LAT, LNG (ยฑXm) with location active.
  • Test Email Trigger: Go to the Settings tab and click ๐Ÿงช Send Test Email Alert to test SMTP delivery without sounding the SOS alarm.
  • Contact Management Test: Add an email contact using Option 2 on the modal, then verify it appears in the Contacts panel with an EMAIL tag. Click the red โœ• button to test deletion.
  • Full SOS Activation Test: Click SOS on the dashboard, confirm activation, and verify that emergency alert emails are received in recipient inboxes (check Inbox and Spam folders).

๐Ÿ”’ Security

Implemented Security Practices:

  • Environment Isolation: Sensitive credentials (EMAIL_PASS, Firebase Service Account keys) remain strictly on the backend.
  • Git Protection: .env and credential JSON files are excluded via .gitignore.
  • Placeholder Sanitization: Server automatically filters out placeholder default emails (emergency_contact@gmail.com) to prevent accidental mail loops.
  • Frontend Config Exposure via API: Firebase public client config is fetched via /api/firebase-config rather than hardcoded into public static scripts.
  • Firestore Document Deduplication: Registration tokens are sanitized and hashed as document IDs to prevent duplicate token pollution.

โš ๏ธ Limitations

  • Browser Location Permission Required: Location features depend on the user granting browser geolocation permissions.
  • Hardware Accuracy Differences: Desktop and laptop computers without hardware GPS chips rely on Wi-Fi/IP location services (accuracy ~30โ€“80m). Mobile devices with hardware GPS achieve ~3โ€“5m accuracy.
  • Internet Connectivity Required: Emergency alerts require active internet connection to communicate with backend API endpoints and SMTP servers.
  • Email Delivery Dependencies: Email delivery speeds depend on Google SMTP service availability and recipient mail server spam filters.
  • Not a Replacement for Emergency Services: This web application is a personal/college project demonstration and does not directly connect to local 911 / emergency dispatcher lines.

๐Ÿ”ฎ Future Improvements

  • ๐Ÿ“ž Twilio Voice Call Integration: Trigger automated phone calls when SOS is activated.
  • ๐Ÿ’ฌ WhatsApp & Telegram Bot Alerts: Multi-channel emergency messaging integration.
  • ๐Ÿ“ฑ Native Mobile App: React Native or Flutter wrapper for background hardware GPS execution.
  • ๐ŸŽ™๏ธ Voice Activation: Voice-command recognition (e.g. "Emergency Help") to trigger hands-free SOS.
  • ๐Ÿ—บ๏ธ Geofencing Safety Zones: Automated warnings when entering or leaving specified geographical zones.
  • ๐Ÿ“ด Offline SMS Fallback: WebSMS / GSM modem integration for connectivity blackouts.

๐Ÿ‘จโ€๐Ÿ’ป Developer

Tejas


๐Ÿ“„ License

This project does not currently contain a license file. A license (e.g., MIT License) can be added to the repository later.

About

No description, website, or topics provided.

Resources

Stars

0 stars

Watchers

0 watching

Forks

Releases

Packages

Contributors

Languages