feat: add sse notifications functionality - #114
Open
mr-andrew919 wants to merge 1 commit into
Open
Conversation
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
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.tsService:createClientConnection: Establishes an SSE stream and registers a new user in the state withwrite(send message) andclose(close connection) methods.removeClient: Removes a user from the active client list.sendToClient: Sends a message to a specific user by ID.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:
ping/pongmessages to keep connections alive.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