wifi-densepose/ui
ruv 3b72f35306 fix: UI auto-detects server port from page origin (#55)
The UI had hardcoded localhost:8080 for HTTP and localhost:8765 for
WebSocket, causing "Backend unavailable" when served from Docker
(port 3000) or any non-default port.

Changes:
- api.config.js: BASE_URL now uses window.location.origin instead
  of hardcoded localhost:8080
- api.config.js: buildWsUrl() uses window.location.host instead of
  hardcoded localhost:8080
- sensing.service.js: WebSocket URL derived from page origin instead
  of hardcoded localhost:8765
- main.rs: Added /ws/sensing route to the HTTP server so WebSocket
  and REST are reachable on a single port

Fixes #55

Co-Authored-By: claude-flow <ruv@ruv.net>
2026-03-01 02:09:23 -05:00
..
components Merge pull request #42 from ruvnet/security/fix-critical-vulnerabilities 2026-02-28 21:44:00 -05:00
config fix: UI auto-detects server port from page origin (#55) 2026-03-01 02:09:23 -05:00
services fix: UI auto-detects server port from page origin (#55) 2026-03-01 02:09:23 -05:00
tests updates 2025-06-07 13:55:28 +00:00
utils feat: Sensing-only UI mode with Gaussian splat visualization and Rust migration ADR 2026-02-28 14:37:29 -05:00
README.md updates 2025-06-07 13:55:28 +00:00
TEST_REPORT.md I've successfully completed a full review of the WiFi-DensePose system, testing all functionality across every major 2025-06-09 17:13:35 +00:00
app.js feat: Rust sensing server with full DensePose-compatible API 2026-02-28 21:29:45 -05:00
index.html feat: Sensing-only UI mode with Gaussian splat visualization and Rust migration ADR 2026-02-28 14:37:29 -05:00
start-ui.sh docs: Revamp README and UI documentation; enhance CLI usage instructions and API configuration details 2025-06-07 13:40:52 +00:00
style.css feat: Sensing-only UI mode with Gaussian splat visualization and Rust migration ADR 2026-02-28 14:37:29 -05:00
viz.html feat: Add Three.js visualization entry point and data processor 2026-02-28 06:29:28 +00:00

README.md

WiFi DensePose UI

A modular, modern web interface for the WiFi DensePose human tracking system. This UI provides real-time monitoring, configuration, and visualization of WiFi-based pose estimation.

๐Ÿ—๏ธ Architecture

The UI follows a modular architecture with clear separation of concerns:

ui/
โ”œโ”€โ”€ app.js                 # Main application entry point
โ”œโ”€โ”€ index.html            # Updated HTML with modular structure
โ”œโ”€โ”€ style.css             # Complete CSS with additional styles
โ”œโ”€โ”€ config/               # Configuration modules
โ”‚   โ””โ”€โ”€ api.config.js     # API endpoints and configuration
โ”œโ”€โ”€ services/             # Service layer for API communication
โ”‚   โ”œโ”€โ”€ api.service.js    # HTTP API client
โ”‚   โ”œโ”€โ”€ websocket.service.js # WebSocket client
โ”‚   โ”œโ”€โ”€ pose.service.js   # Pose estimation API wrapper
โ”‚   โ”œโ”€โ”€ health.service.js # Health monitoring API wrapper
โ”‚   โ””โ”€โ”€ stream.service.js # Streaming API wrapper
โ”œโ”€โ”€ components/           # UI components
โ”‚   โ”œโ”€โ”€ TabManager.js     # Tab navigation component
โ”‚   โ”œโ”€โ”€ DashboardTab.js   # Dashboard component with live data
โ”‚   โ”œโ”€โ”€ HardwareTab.js    # Hardware configuration component
โ”‚   โ””โ”€โ”€ LiveDemoTab.js    # Live demo with streaming
โ”œโ”€โ”€ utils/               # Utility functions and helpers
โ”‚   โ””โ”€โ”€ mock-server.js   # Mock server for testing
โ””โ”€โ”€ tests/               # Comprehensive test suite
    โ”œโ”€โ”€ test-runner.html  # Test runner UI
    โ”œโ”€โ”€ test-runner.js    # Test framework and cases
    โ””โ”€โ”€ integration-test.html # Integration testing page

๐Ÿš€ Features

Smart Backend Detection

  • Automatic Detection: Automatically detects if your FastAPI backend is running
  • Real Backend Priority: Always uses the real backend when available
  • Mock Fallback: Falls back to mock server only when backend is unavailable
  • Testing Mode: Can force mock mode for testing and development

Real-time Dashboard

  • Live system health monitoring
  • Real-time pose detection statistics
  • Zone occupancy tracking
  • System metrics (CPU, memory, disk)
  • API status indicators

Hardware Configuration

  • Interactive antenna array visualization
  • Real-time CSI data display
  • Configuration panels
  • Hardware status monitoring

Live Demo

  • WebSocket-based real-time streaming
  • Signal visualization
  • Pose detection visualization
  • Interactive controls

API Integration

  • Complete REST API coverage
  • WebSocket streaming support
  • Authentication handling
  • Error management
  • Request/response interceptors

๐Ÿ“‹ API Coverage

The UI integrates with all WiFi DensePose API endpoints:

Health Endpoints

  • GET /health/health - System health check
  • GET /health/ready - Readiness check
  • GET /health/live - Liveness check
  • GET /health/metrics - System metrics
  • GET /health/version - Version information

Pose Estimation

  • GET /api/v1/pose/current - Current pose data
  • POST /api/v1/pose/analyze - Trigger analysis
  • GET /api/v1/pose/zones/{zone_id}/occupancy - Zone occupancy
  • GET /api/v1/pose/zones/summary - All zones summary
  • POST /api/v1/pose/historical - Historical data
  • GET /api/v1/pose/activities - Recent activities
  • POST /api/v1/pose/calibrate - System calibration
  • GET /api/v1/pose/stats - Statistics

Streaming

  • WS /api/v1/stream/pose - Real-time pose stream
  • WS /api/v1/stream/events - Event stream
  • GET /api/v1/stream/status - Stream status
  • POST /api/v1/stream/start - Start streaming
  • POST /api/v1/stream/stop - Stop streaming
  • GET /api/v1/stream/clients - Connected clients
  • DELETE /api/v1/stream/clients/{client_id} - Disconnect client

๐Ÿงช Testing

Test Runner

Open tests/test-runner.html to run the complete test suite:

# Serve the UI directory on port 3000 (to avoid conflicts with FastAPI on 8000)
cd /workspaces/wifi-densepose/ui
python -m http.server 3000
# Open http://localhost:3000/tests/test-runner.html

Test Categories

  • API Configuration Tests - Configuration and URL building
  • API Service Tests - HTTP client functionality
  • WebSocket Service Tests - WebSocket connection management
  • Pose Service Tests - Pose estimation API wrapper
  • Health Service Tests - Health monitoring functionality
  • UI Component Tests - Component behavior and interaction
  • Integration Tests - End-to-end functionality

Integration Testing

Use tests/integration-test.html for visual integration testing:

# Open http://localhost:3000/tests/integration-test.html

Features:

  • Mock server with realistic API responses
  • Visual testing of all components
  • Real-time data simulation
  • Error scenario testing
  • WebSocket stream testing

๐Ÿ› ๏ธ Usage

Basic Setup

<!DOCTYPE html>
<html>
<head>
    <link rel="stylesheet" href="style.css">
</head>
<body>
    <div class="container">
        <!-- Your content -->
    </div>
    <script type="module" src="app.js"></script>
</body>
</html>

Using Services

import { poseService } from './services/pose.service.js';
import { healthService } from './services/health.service.js';

// Get current pose data
const poseData = await poseService.getCurrentPose();

// Subscribe to health updates
healthService.subscribeToHealth(health => {
    console.log('Health status:', health.status);
});

// Start pose streaming
poseService.startPoseStream({
    minConfidence: 0.7,
    maxFps: 30
});

poseService.subscribeToPoseUpdates(update => {
    if (update.type === 'pose_update') {
        console.log('New pose data:', update.data);
    }
});

Using Components

import { TabManager } from './components/TabManager.js';
import { DashboardTab } from './components/DashboardTab.js';

// Initialize tab manager
const container = document.querySelector('.container');
const tabManager = new TabManager(container);
tabManager.init();

// Initialize dashboard
const dashboardContainer = document.getElementById('dashboard');
const dashboard = new DashboardTab(dashboardContainer);
await dashboard.init();

๐Ÿ”ง Configuration

API Configuration

Edit config/api.config.js to modify API settings:

export const API_CONFIG = {
  BASE_URL: window.location.origin,
  API_VERSION: '/api/v1',
  
  // Rate limiting
  RATE_LIMITS: {
    REQUESTS_PER_MINUTE: 60,
    BURST_LIMIT: 10
  },
  
  // WebSocket configuration
  WS_CONFIG: {
    RECONNECT_DELAY: 5000,
    MAX_RECONNECT_ATTEMPTS: 5,
    PING_INTERVAL: 30000
  }
};

Authentication

import { apiService } from './services/api.service.js';

// Set authentication token
apiService.setAuthToken('your-jwt-token');

// Add request interceptor for auth
apiService.addRequestInterceptor((url, options) => {
    // Modify request before sending
    return { url, options };
});

๐ŸŽจ Styling

The UI uses a comprehensive CSS design system with:

  • CSS Custom Properties for theming
  • Dark/light mode support
  • Responsive design
  • Component-based styling
  • Smooth animations and transitions

Key CSS Variables

:root {
  --color-primary: rgba(33, 128, 141, 1);
  --color-background: rgba(252, 252, 249, 1);
  --color-surface: rgba(255, 255, 253, 1);
  --color-text: rgba(19, 52, 59, 1);
  --space-16: 16px;
  --radius-lg: 12px;
}

๐Ÿ” Monitoring & Debugging

Health Monitoring

import { healthService } from './services/health.service.js';

// Start automatic health checks
healthService.startHealthMonitoring(30000); // Every 30 seconds

// Check if system is healthy
const isHealthy = healthService.isSystemHealthy();

// Get specific component status
const apiStatus = healthService.getComponentStatus('api');

Error Handling

// Global error handling
window.addEventListener('error', (event) => {
    console.error('Global error:', event.error);
});

// API error handling
apiService.addResponseInterceptor(async (response, url) => {
    if (!response.ok) {
        console.error(`API error: ${response.status} for ${url}`);
    }
    return response;
});

๐Ÿš€ Deployment

Development

Option 1: Use the startup script

cd /workspaces/wifi-densepose/ui
./start-ui.sh

Option 2: Manual setup

# First, start your FastAPI backend (runs on port 8000)
wifi-densepose start
# or from the main project directory:
python -m wifi_densepose.main

# Then, start the UI server on a different port to avoid conflicts
cd /workspaces/wifi-densepose/ui
python -m http.server 3000
# or
npx http-server . -p 3000

# Open the UI at http://localhost:3000
# The UI will automatically detect and connect to your backend

Backend Detection Behavior

  • Real Backend Available: UI connects to http://localhost:8000 and shows โœ… "Connected to real backend"
  • Backend Unavailable: UI automatically uses mock server and shows โš ๏ธ "Mock server active - testing mode"
  • Force Mock Mode: Set API_CONFIG.MOCK_SERVER.ENABLED = true for testing

Production

  1. Configure API_CONFIG.BASE_URL for your backend
  2. Set up HTTPS for WebSocket connections
  3. Configure authentication if required
  4. Optimize assets (minify CSS/JS)
  5. Set up monitoring and logging

๐Ÿค Contributing

  1. Follow the modular architecture
  2. Add tests for new functionality
  3. Update documentation
  4. Ensure TypeScript compatibility
  5. Test with mock server

๐Ÿ“„ License

This project is part of the WiFi-DensePose system. See the main project LICENSE file for details.