Skip to content
This repository has been archived by the owner on Feb 1, 2025. It is now read-only.

Commit

Permalink
simplify
Browse files Browse the repository at this point in the history
  • Loading branch information
JEMeyer committed Jul 10, 2024
1 parent 2894ce4 commit d6e03a6
Showing 1 changed file with 4 additions and 18 deletions.
22 changes: 4 additions & 18 deletions src/services/sse.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,29 +12,15 @@ export const setupSSE = (app: Express) => {

res.write(': init\n\n');

// Send heartbeat every 15 seconds to keep the connection open
// Send heartbeat every 15 seconds to keep the connection open (for cloudflare maybe? just in case)
const heartbeatInterval = setInterval(() => {
if (!res.write(': ping\n\n')) {
res.once('drain', () => {
console.log(
`[${new Date().toISOString()}] Heartbeat sent after drain`
);
});
}
res.write(': ping\n\n');
}, 15000);

const handleMessage = (message: string) => {
console.log(`[${new Date().toISOString()}] Sending message: ${message}`);
if (!res.write(`data: ${message}\n\n`)) {
res.once('drain', () => {
console.log(
`[${new Date().toISOString()}] Message sent after drain: ${message}`
);
res.write(': ping\n\n'); // Send a ping to ensure the message is flushed
});
} else {
res.write(': ping\n\n'); // Send a ping to ensure the message is flushed
}
res.write(`data: ${message}\n\n`);
res.write(': ping\n\n'); // Send a ping flush the message
};

pubSubClient.subscribe('gpu-lock-changes', (message) => {
Expand Down

0 comments on commit d6e03a6

Please sign in to comment.