Realtime

From tinh2/skills-hub-registry · View interactive version

Realtime is an AI agent skill from the GitHub repository tinh2/skills-hub-registry. Add realtime features to my app — set up WebSockets or SSE with Socket.io, Pusher, Ably, Supabase Realtime, or Firebase using channels, presence tracking, typing indicators, reconnection with exponential backoff, offline message queuing, and rate limiting

How to use this skill

Skill file

You are in AUTONOMOUS MODE. Do NOT ask questions. Detect everything from the codebase and proceed.

PURPOSE:

Set up production-ready realtime communication. Auto-detect the project's framework and the

requested realtime provider. Install the SDK, create a realtime service with subscribe/publish/

presence methods, implement robust connection management, handle authentication for private

channels, and manage offline/online state transitions.

TASK:

$ARGUMENTS

============================================================ PHASE 0: DETECTION ============================================================

  1. FRAMEWORK DETECTION — scan the project root to identify the tech stack:
  1. PROVIDER DETECTION — determine realtime provider from $ARGUMENTS or existing config:
  1. EXISTING REALTIME CHECK — search for existing realtime implementations:
  1. AUTH DETECTION — identify the project's authentication system:

============================================================ PHASE 1: SDK INSTALLATION ============================================================

Install the correct SDK for the detected provider and framework:

SOCKET.IO:

PUSHER:

ABLY:

SUPABASE REALTIME:

FIREBASE REALTIME:

After installing:

============================================================ PHASE 2: REALTIME SERVICE ============================================================

Create a realtime service that abstracts the provider.

FILE LOCATION:

THE SERVICE MUST EXPOSE:

init(config)

Initialize the realtime client. Set up connection with auth token.

connect()

Establish the WebSocket/SSE connection. Returns a promise that resolves when connected.

disconnect()

Gracefully close the connection. Clean up all subscriptions.

subscribe(channel, event, callback)

Subscribe to an event on a channel. Returns an unsubscribe function.

Callback receives: { data, channel, event, timestamp }.

unsubscribe(channel, event?)

Unsubscribe from a specific event on a channel, or all events on that channel.

publish(channel, event, data)

Publish an event to a channel (server-side, or client-side if provider allows).

subscribeToChannel(channel, handlers)

Subscribe to all events on a channel with a handler map: { [event]: callback }.

Returns an unsubscribe function for the entire channel.

presence(channel)

Returns a presence object for the channel with:

setPresenceState(channel, state)

Update the current user's presence state (e.g., { status: "typing" }).

getConnectionState()

Returns: "connected" | "connecting" | "disconnected" | "reconnecting".

onConnectionChange(callback)

Subscribe to connection state changes. Fires on connect, disconnect, reconnect.

IMPLEMENTATION REQUIREMENTS:

============================================================ PHASE 3: CONNECTION MANAGEMENT ============================================================

Implement robust connection handling. This is the most critical part of any realtime system.

  1. RECONNECTION:
  1. HEARTBEAT:
  1. CONNECTION QUALITY:
  1. GRACEFUL DEGRADATION:

============================================================ PHASE 4: CHANNEL ARCHITECTURE ============================================================

Define a channel naming convention and access control model:

  1. CHANNEL TYPES:

PUBLIC CHANNELS — anyone can subscribe:

Pattern: public:{resource} (e.g., public:feed, public:announcements)

No authentication required.

PRIVATE CHANNELS — authenticated users only:

Pattern: private:{resource}:{id} (e.g., private:user:123, private:team:abc)

Requires auth token validation before subscribing.

PRESENCE CHANNELS — private + who's online:

Pattern: presence:{resource}:{id} (e.g., presence:room:456)

Requires auth. Provides member list and join/leave events.

  1. AUTH ENDPOINT (for Pusher/Ably/managed providers):
  1. CHANNEL PERMISSIONS:

============================================================ PHASE 5: PRESENCE ============================================================

Implement presence (who's online) functionality:

  1. PRESENCE DATA STRUCTURE:

```typescript

interface PresenceMember {

userId: string;

name: string;

avatar?: string;

status: "online" | "away" | "busy";

joinedAt: Date;

customState?: Record<string, unknown>;

}

```

  1. PRESENCE EVENTS:
  1. PRESENCE UI HELPER (framework-specific):

REACT:

Create src/hooks/usePresence.ts:

FLUTTER:

Create lib/widgets/presence_indicator.dart:

VUE:

Create src/composables/usePresence.ts with equivalent functionality.

  1. TYPING INDICATORS:

============================================================ PHASE 6: OFFLINE HANDLING ============================================================

Handle the transition between online and offline states:

  1. OFFLINE DETECTION:
  1. MESSAGE QUEUING:
  1. MISSED EVENT RECOVERY:
  1. STATE SYNC:
  1. UI INDICATORS:

============================================================ PHASE 7: RATE LIMITING & SAFETY ============================================================

  1. CLIENT-SIDE RATE LIMITING:
  1. SERVER-SIDE RATE LIMITING (if Socket.io or custom server):
  1. MESSAGE VALIDATION:
  1. SECURITY:

============================================================ PHASE 8: VALIDATION ============================================================

  1. Run the project's build/compile step — fix any errors.
  2. Run existing tests — fix any failures caused by the realtime integration.
  3. Write at least 4 unit tests:
  1. Verify no memory leaks: subscriptions are cleaned up on unsubscribe and disconnect.
  2. Commit all changes with descriptive messages:

============================================================ DO NOT ============================================================

============================================================ OUTPUT ============================================================

Realtime Setup

NEXT STEPS:

After realtime is set up:

============================================================

SELF-HEALING VALIDATION (max 3 iterations)

============================================================

After completing the integration, validate:

  1. Run the project's test suite to verify the integration works end-to-end.
  2. Run build/compile to confirm no breakage.
  3. Verify the integration responds correctly (health checks, test calls, smoke tests).
  4. If failures occur, diagnose from error output and apply minimal fixes.
  5. Repeat up to 3 iterations.

IF STILL FAILING after 3 iterations:

============================================================

SELF-EVOLUTION TELEMETRY

============================================================

After producing output, record execution metadata for the /evolve pipeline.

Check if a project memory directory exists:

Entry format:

### /realtime — {{YYYY-MM-DD}}
- Outcome: {{SUCCESS | PARTIAL | FAILED}}
- Self-healed: {{yes — what was healed | no}}
- Iterations used: {{N}} / {{N max}}
- Bottleneck: {{phase that struggled or "none"}}
- Suggestion: {{one-line improvement idea for /evolve, or "none"}}

Only log if the memory directory exists. Skip silently if not found.

Keep entries concise — /evolve will parse these for skill improvement signals.

Use this skill with your AI agent: Open on Skill Issue to copy, download, or add to your library. Works with Claude, ChatGPT, Gemini, Cursor, Windsurf and more.