A lightweight, WebRTC-based push-to-talk system designed for dispatch and bus drivers. Built with minimal dependencies using vanilla JavaScript and Web Workers.
# Clone and install
git clone <your-repo-url> ptt-system
cd ptt-system
npm install
# Start the server
npm start
# Or with auto-restart during development:
npm run dev
# Open in browser
open http://localhost:3000Open multiple browser windows/tabs and log in with different usernames to see real-time presence in action!
Quick 2-Minute Test:
- Open two browser windows (or tabs)
- Login as
driver1in first window - Login as
dispatchin second window - Allow microphone access when prompted in both
- Wait for "Microphone ready" status (green)
- In window 1: Hold down the blue PTT button and speak
- In window 2: You should hear the audio!
What to expect:
- PTT button lights up bright cyan when pressed
- Status shows "Transmitting..." on sender
- Status shows "Receiving from [user]" on receiver
- Clear audio with <200ms latency
- Works on mobile with touch (tap and hold)
See TESTING_GUIDE.md for comprehensive testing scenarios.
- β Simple Authentication - Username-based login with automatic registration
- β File-based User Storage - No database required, users stored as JSON files
- β Real-time Presence - See who's online in real-time
- β Heartbeat System - Automatic connection health monitoring
- β Status Management - Online, Busy, Away status indicators
- β WebSocket Worker - All network communication in separate thread
- β Responsive UI - Works on desktop, tablet, and mobile
- β Auto-reconnection - Automatically reconnects if connection drops
- β WebRTC P2P Audio - Direct peer-to-peer audio streaming [NEW!]
- β PTT Functionality - Push-to-talk audio transmission [NEW!]
- β Group Broadcasting - Send audio to multiple users simultaneously [NEW!]
- β Mobile Touch Support - Optimized touch controls for iOS/Android [NEW!]
- β Audio Feedback - Visual indicators for transmitting/receiving [NEW!]
- β PWA Support - Install as app on iOS/Android
- π Push Notifications - Notify offline users (Web Push API)
- π Audio Worklet - Advanced audio processing
- π Recording - Record PTT messages for playback
- π Channels - Create separate communication channels
βββ server/
β βββ index.js # Node.js HTTP + WebSocket server
βββ public/
β βββ index.html # Main application UI
β βββ css/
β β βββ styles.css # Application styles
β βββ js/
β β βββ main.js # Main application logic
β βββ workers/
β βββ ws-worker.js # WebSocket worker thread
βββ users/ # User data storage (JSON files)
- Backend: Node.js (ES Modules)
- WebSocket: ws library
- Frontend: Vanilla JavaScript (no frameworks)
- Workers: Web Workers for network handling
- Styling: Pure CSS with CSS variables
- Future: WebRTC for P2P audio, Service Workers for PWA
- Node.js 18+ (ES Modules support)
- Modern browser with Web Worker support
- Install dependencies:
cd ptt-system
npm install- Start the server:
npm startOr for development with auto-restart:
npm run dev- Open your browser:
http://localhost:3000
- Open the app in multiple browser windows/tabs
- Enter a username in each window (e.g., "Driver1", "Dispatch", "Driver2")
- You should see other users appear in the "Online Users" list
- Try changing your status (click the settings icon)
- The status changes should reflect in all connected clients
-
POST /api/register- Register new user{ "username": "driver1" } -
POST /api/login- Login existing user{ "username": "driver1" } -
GET /api/users- Get all registered users
Client β Server:
auth- Authenticate connectionheartbeat- Keep connection alivestatus_change- Update user statussignal- WebRTC signaling (future)
Server β Client:
auth_success- Authentication successfuluser_joined- New user connecteduser_left- User disconnecteduser_status_changed- User changed statusheartbeat_ack- Heartbeat acknowledgedsignal- WebRTC signaling (future)
Edit server/index.js to configure:
PORT- Server port (default: 3000)HEARTBEAT_INTERVAL- How often to check connections (30s)HEARTBEAT_TIMEOUT- When to consider connection dead (45s)
Edit workers/ws-worker.js to configure:
HEARTBEAT_INTERVAL- How often to send heartbeat (25s)RECONNECT_DELAY- Delay before reconnection attempt (3s)
Users are stored as JSON files in the users/ directory:
{
"username": "driver1",
"createdAt": "2025-01-13T12:00:00.000Z",
"lastLogin": "2025-01-13T14:30:00.000Z"
}- Chrome/Edge 90+
- Firefox 88+
- Safari 14+
- iOS Safari 14+
- Chrome Android 90+
- Basic server infrastructure
- User authentication & presence
- WebSocket communication
- Heartbeat system
- Peer-to-peer connection setup
- Audio capture and streaming
- PTT button functionality
- One-to-one audio calls
- Multi-peer connections
- Group audio routing
- SFU consideration for larger groups
- Audio mixing
- Service Worker implementation
- Install prompts
- Web Push API integration
- Background notifications
- Error handling & logging
- Performance optimization
- Security hardening
- Deployment guide
Users not appearing online:
- Check browser console for errors
- Verify WebSocket connection (should show "Connected")
- Check server logs for connection messages
Connection keeps dropping:
- Check network stability
- Verify firewall isn't blocking WebSocket
- Increase HEARTBEAT_TIMEOUT if needed
Worker errors:
- Ensure browser supports Web Workers
- Check browser console for worker errors
- Verify workers/ directory is accessible
MIT