Skip to content

Commit

Permalink
Server: Implement doSendEvents Function
Browse files Browse the repository at this point in the history
The doSendEvents function has been added to eventRecipients.ts. This function sends the events array as the response body and clears the event queue after sending. Additionally, the client is removed from the clients map after events are sent.

Fixes: #61
  • Loading branch information
sksmagr23 authored and kuv2707 committed Jun 7, 2024
1 parent 29ff99f commit 4acd8fe
Showing 1 changed file with 9 additions and 3 deletions.
12 changes: 9 additions & 3 deletions backend/src/eventRecipients.ts
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,13 @@ export function scheduleSend(clientId: ClientId, event: AppEvent) {
//todo: Enqueue the event for sending.
}

// eslint-disable-next-line @typescript-eslint/no-unused-vars
export function doSendEvent(clientId: ClientId) {
//todo: Send all the events in the queue to the client, only if the response object is available.
export function doSendEvents(clientId: ClientId) {
const res = clients.get(clientId);
const events = eventQueue.get(clientId) || [];

if (res && events.length > 0) {
res.json({ events });
eventQueue.set(clientId, []);
clients.delete(clientId);
}
}

0 comments on commit 4acd8fe

Please sign in to comment.