From version 6.0.0, the response component doesn´t call a close or abort event when the SSE client is closed
penadeurubu opened this issue · comments
penadeurubu commented
When I tested the code below on versions 6.14.9 and 6.0.0, the response component didn´t call a close or abort event when the SSE client was closed.
When I tested the code below on version 5.9.2, the response component called an abort event when the SSE client was closed.
Test code - Server.js
const { Server } = require("hyper-express")
const crypto = require('crypto')
const server = new Server()
const sse_streams = {};
server.get('/news/events', (request, response) => {
// You may perform some authentication here as this is just a normal HTTP GET request
if (response.sse) {
response.sse.open();
response.sse.send('data: Some initial message \n\n');
response.sse.id = crypto.randomUUID();
sse_streams[response.sse.id] = response.sse;
console.log("New Connection - ID =",response.sse.id)
response.on('close', () => {
console.log("Close Connection - delete ID =", response.sse.id)
delete sse_streams[response.sse.id]
});
response.on('abort',() => {
console.log("Close Connection - Delete ID =", response.sse.id)
delete sse_streams[response.sse.id]
});
}
else {
console.log("Server-Sent Events Not Supported")
response.sse.send('data: Server-Sent Events Not Supported!\n\n');
}
});
server.listen(8000)
Test code - Client.js
const eventSource = require('eventsource');
const evtSource = new eventSource('http://localhost:8000/news/events', {});
evtSource.onmessage = (event) => {
console.log(event)
};
evtSource.addEventListener('error', function(e) {
if (e.readyState == EventSource.CLOSED) {
console.log("Connection was closed")
}
}, false)
Kartik commented
Hi, this bug has been fixed in the recent v6.14.10
version. Let me know If you have any other issues.