Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

From version 6.0.0, the response component doesn´t call a close or abort event when the SSE client is closed #217

Closed
penadeurubu opened this issue Jan 21, 2024 · 1 comment

Comments

@penadeurubu
Copy link

penadeurubu commented Jan 21, 2024

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)

@kartikk221
Copy link
Owner

Hi, this bug has been fixed in the recent v6.14.10 version. Let me know If you have any other issues.

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

No branches or pull requests

2 participants