Cursor prompt
Build Real-Time Feature with WebSockets
Implement a real-time feature using WebSockets or SSE with presence tracking, reconnection logic, and proper resource cleanup.
Build a real-time {{feature_type}} feature for {{project_name}}. ## Transport: {{transport}} ## Requirements: {{requirements}} ### Server Implementation - WebSocket server using {{server_library}} - Connection registry: Map<userId, Set<WebSocket>> to track per-user connections - Heartbeat ping/pong every 30 seconds to detect dead connections - On disconnect: remove from registry, cancel any active subscriptions - Authentication: verify JWT token on connection handshake before accepting - Per-connection rate limit: max 20 messages/second ### Client Implementation - Auto-reconnect with exponential backoff: 1s → 2s → 4s → 8s → max 30s - Connection state machine: idle | connecting | connected | reconnecting | disconnected - Queue outbound messages while disconnected; drain queue after reconnection - Visible connection status indicator (dot: green/yellow/red) - Cleanup: close connection and remove all listeners on component unmount ### Message Protocol ```typescript type Message = { type: string; payload: unknown; id: string; // for deduplication timestamp: number; } ``` - Client acknowledges critical messages - Server deduplicates using id field ### Optimistic UI - Apply state changes immediately without waiting for server confirmation - Revert to previous state if server returns an error ### Output Server handler, useRealtime() hook, connection status component, and message queue utility.
Fill in: {{feature_type}}, {{project_name}}, {{transport}}, {{requirements}}, {{server_library}}. In Loopy you fill these in a form and copy the finished prompt in one click.
More coding prompts
- CursorAdd File Upload with Cloud StorageMulti-file upload with type checking, size limits, virus scanning, cloud storage, and progress tracking.
- CursorAdd Redis Caching LayerCache-aside Redis caching with typed get/set helpers, TTL management, pattern-based invalidation, and monitoring.
- CursorAdd Stripe Payment IntegrationComplete Stripe checkout, webhooks, subscription management, and billing portal with idempotent webhook handling.
- LovableBooking and Scheduling SystemCalendar-based booking with availability management, confirmations, reminders, and payment collection.
- CursorBuild Admin Dashboard with CRUDData table with server-side CRUD, column sorting and filtering, bulk actions, and role-protected admin panel.
- CursorBuild Data Export FeatureExport large datasets to CSV or Excel with streaming for memory efficiency, background jobs, and signed download links.

