Livelocd is a lightweight Axum-compatible plugin for real-time location tracking via WebSockets and a JSON API. Easily drop it into any Rust backend to enable live geolocation dashboards, game user tracking, or delivery fleet monitoring.
- 📡 WebSocket support for sending real-time location updates
- 👂 Subscribe to all users or individual users' locations
- 🌐 REST API to query current locations
- 🔐 Token-based authentication for WebSocket connections
- 🧩 Designed as a plugin for Axum apps
- ⚡ Built with minimal dependencies, powered by
tokio,axum, andserde_json
📚 For detailed documentation, please see docs.md.
In your project’s Cargo.toml:
[dependencies]
livelocd = { git = "https://github.com/Burnsedia/livelocd" }In your Axum project:
use axum::Router;
use livelocd::{livelocd_routes, set_token_validator, ClosureValidator};
use std::sync::Arc;
#[tokio::main]
async fn main() {
// 1. Set up your token validator
let validator = ClosureValidator::new(|token: String| token.starts_with("valid-"));
set_token_validator(Arc::new(validator));
// 2. Add the livelocd routes
let app = Router::new().merge(livelocd_routes());
// 3. Start the server
let listener = tokio::net::TcpListener::bind("0.0.0.0:3000").await.unwrap();
println!("Listening on: {}", listener.local_addr().unwrap());
axum::serve(listener, app).await.unwrap();
}All WebSocket endpoints require a token query parameter.
GET /ws/send-location?token=<your-token>— Send JSON with auser_idand any arbitrary fields (e.g., lat/lng)GET /ws/subscribe?token=<your-token>— Receive real-time updates for all usersGET /ws/subscribe/:user_id?token=<your-token>— Subscribe to updates for a specific user
{
"user_id": "user123",
"lat": 33.7489954,
"lng": -84.3879824,
"status": "moving"
}GET /api/users— Get current known location for all usersGET /api/users/:user_id— Get most recent location for a single user
Use websocat:
# Send location
websocat "ws://localhost:3000/ws/send-location?token=valid-token"
# Then, send the JSON payload:
{"user_id": "car-1", "lat": 40.7, "lng": -74.0}
# Subscribe to all
websocat "ws://localhost:3000/ws/subscribe?token=valid-token"MIT
Pull requests welcome! Let’s make real-time dashboards in Rust even easier.