Skip to content

feat: add sse notifications functionality - #114

Open
mr-andrew919 wants to merge 1 commit into
nomeyy:mainfrom
mr-andrew919:main
Open

feat: add sse notifications functionality#114
mr-andrew919 wants to merge 1 commit into
nomeyy:mainfrom
mr-andrew919:main

Conversation

@mr-andrew919

Copy link
Copy Markdown

Pull Request: Implement Server-Sent Events (SSE) Service and Notification Endpoints

Description

This pull request introduces a new Server-Sent Events (SSE) service and related endpoints to enable real-time notifications for users. The implementation includes both backend and frontend components to support seamless communication.

Changes

  • Created features/sse/services/manager.ts Service:

    • Implemented createClientConnection: Establishes an SSE stream and registers a new user in the state with write (send message) and close (close connection) methods.
    • Implemented removeClient: Removes a user from the active client list.
    • Implemented sendToClient: Sends a message to a specific user by ID.
    • Implemented broadcast: Sends a message to all connected users.
  • Added SSE Endpoint:

    • GET /api/sse: Allows users to establish an SSE connection.
  • Added Test Notification Endpoints:

    • POST /api/sse/broadcast: Sends a message to all connected users.
    • POST /api/sse/user/[userId]: Sends a message to a specific user by their ID.
  • Added tRPC Notification Endpoints:

    • POST /api/trpc/sse.broadcast: Broadcasts a message to all users via tRPC.
    • POST /api/trpc/sse.sendToUser: Sends a message to a specific user via tRPC.
  • Additional Features:

    • Implemented system-level ping/pong messages to keep connections alive.
    • Added connection health checks to detect and remove disconnected users from the sender list.
    • Created a frontend hook to simplify SSE connection and message handling for the frontend.

Purpose

This implementation enables real-time notifications for users through SSE, providing a scalable and efficient way to deliver updates. The tRPC endpoints and frontend hook enhance developer experience and integration flexibility.

Go to Demo Video

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.

1 participant