Skip to content

Add WebSocket infrastructure for shared sessions with Azure deployment and persistence#3

Draft
Copilot wants to merge 5 commits intomainfrom
copilot/investigate-shared-sessions-websocket
Draft

Add WebSocket infrastructure for shared sessions with Azure deployment and persistence#3
Copilot wants to merge 5 commits intomainfrom
copilot/investigate-shared-sessions-websocket

Conversation

Copy link

Copilot AI commented Nov 3, 2025

Implements complete WebSocket infrastructure to enable real-time collaboration across multiple clients with session persistence. The solution is opt-in via environment variables and falls back gracefully to localStorage when disabled.

Architecture

Server (server/)

  • Node.js WebSocket server with session-based room management
  • Broadcasts state changes to all clients in a session
  • Session persistence with Azure Table Storage
  • Configurable session expiration (default 24 hours)
  • Automatic cleanup of expired sessions
  • Auto-cleanup of stale connections, graceful shutdown handling
  • Single required dependency: ws library (Azure SDK optional)

Client (src/)

  • useWebSocket - Connection management with exponential backoff reconnection
  • useSharedState - Drop-in replacement for existing useKV hook, syncs via WebSocket when connected
  • sessionManager - Secure session ID generation and URL-based session sharing
  • ConnectionStatus - Real-time connection status indicator with active user count

Session Persistence

Sessions are persisted to Azure Table Storage with configurable expiration:

  • Durable: Session data survives server restarts
  • Configurable: Set max duration via SESSION_MAX_DURATION_HOURS (default 24 hours)
  • Automatic cleanup: Expired sessions cleaned up hourly
  • Fallback: Memory storage for development/testing

Usage

// Replace localStorage-only state
const [teams, setTeams] = useKV("hackathon-teams", []);

// With synchronized state
const sessionId = getOrCreateSessionId();
const [teams, setTeams, syncStatus] = useSharedState("hackathon-teams", [], sessionId);

// Add connection status UI
<ConnectionStatus 
  isConnected={isConnected}
  connectionStatus={connectionStatus}
  activeClients={activeClients}
  sessionId={sessionId}
/>

Configuration

# Frontend .env
VITE_WEBSOCKET_URL=wss://your-server.azurewebsites.net
VITE_ENABLE_WEBSOCKET=true  # false to disable

# Server .env
PORT=8080
ENABLE_PERSISTENCE=true
STORAGE_TYPE=azure-table
AZURE_STORAGE_CONNECTION_STRING=DefaultEndpointsProtocol=https;...
SESSION_MAX_DURATION_HOURS=24

Documentation

  • AZURE_DEPLOYMENT.md - Azure deployment guide (recommended)
  • WEBSOCKET_INVESTIGATION.md - Technical architecture and design decisions
  • WEBSOCKET_SETUP.md - Deployment guide for all platforms (Azure/Railway/Render/Heroku)
  • INTEGRATION_EXAMPLE.md - Code examples and migration patterns
  • WEBSOCKET_SUMMARY.md - Complete feature overview

Deployment

Recommended: Azure - Both frontend and backend hosted on Azure App Service with Azure Table Storage for session persistence.

Alternative: Frontend on GitHub Pages, WebSocket server on Railway/Render/Heroku with memory-only sessions.

The app functions identically with WebSocket disabled - no breaking changes.

Original prompt

investigate required additions to allow shared sessions via websocket


💬 We'd love your input! Share your thoughts on Copilot coding agent in our 2 minute survey.

Copilot AI and others added 3 commits November 3, 2025 20:11
- Add WebSocket server implementation (server/)
- Add client-side hooks (useWebSocket, useSharedState)
- Add connection status UI component
- Add session management utilities
- Add comprehensive documentation and examples
- Update README with WebSocket setup instructions
- Add .env.example for configuration
- Fix linting errors in App.jsx

Co-authored-by: aatmmr <15815012+aatmmr@users.noreply.github.com>
Co-authored-by: aatmmr <15815012+aatmmr@users.noreply.github.com>
Use Node.js built-in crypto.randomUUID() instead of external uuid package.
Update documentation to reflect this change.

Co-authored-by: aatmmr <15815012+aatmmr@users.noreply.github.com>
Copilot AI changed the title [WIP] Investigate additions for shared sessions via websocket Add WebSocket infrastructure for shared sessions Nov 3, 2025
Copilot AI requested a review from aatmmr November 3, 2025 20:21
@aatmmr
Copy link
Owner

aatmmr commented Nov 3, 2025

@copilot Consider:

  • Both, front and backend are hosted on Azure
  • Session data is persisted for a set and max duration

- Add Azure Table Storage persistence for session data
- Implement configurable session expiration (default 24 hours)
- Add automatic cleanup of expired sessions
- Create comprehensive Azure deployment guide
- Update documentation for Azure-first architecture
- Support both Azure and alternative hosting platforms
- Add environment variables for persistence configuration

Co-authored-by: aatmmr <15815012+aatmmr@users.noreply.github.com>
Copy link
Author

Copilot AI commented Nov 3, 2025

@copilot Consider:

  • Both, front and backend are hosted on Azure
  • Session data is persisted for a set and max duration

Updated the implementation to support:

  1. Azure hosting for both frontend and backend: Added comprehensive Azure deployment guide (AZURE_DEPLOYMENT.md) with options for Azure App Service, Static Web Apps, and Container Instances.

  2. Session persistence with configurable duration:

    • Implemented Azure Table Storage integration for durable session data
    • Configurable max duration (default 24 hours) via SESSION_MAX_DURATION_HOURS
    • Automatic cleanup of expired sessions every hour
    • Fallback to memory storage for development

Server now supports:

  • STORAGE_TYPE=azure-table for Azure Table Storage
  • AZURE_STORAGE_CONNECTION_STRING for connection
  • SESSION_MAX_DURATION_HOURS for expiration control

See commit 63cf63c for all changes.

Copilot AI changed the title Add WebSocket infrastructure for shared sessions Add WebSocket infrastructure for shared sessions with Azure deployment and persistence Nov 3, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants

Comments