serkyron / nestjs-sse

Middleware for Nest.js to send Server-Sent Events (SSE)
20 stars 4 forks source link

add full type definitions to Response #1

Closed irreal closed 4 years ago

irreal commented 4 years ago

Hey, I made this adjustment so that when you install and use this package, you get full typing support on your Response parameter (all the usual Express things, plus the .sse from this package)

I don't have a lot of experience with typescript type definitions, but I tested it and it works just fine.

serkyron commented 4 years ago

Thanks a lot man, good job! Хвала брате!

janeshjain commented 4 years ago

Hey. Instead of broadcasting the response to all clients, how can I filter my response to a particular client out of all connected clients?

irreal commented 4 years ago

This thread is about my PR which adds better type support.

However, to give a short answer to your question: there is no broadcasting being done. The SSE method is an extension on the response object which is tied to a single specific client. You are supposed to analyze the request object (parse auth token, queru parameters, etc) then store the response object somewhere for later lookup. Then when you have a message for that specific client, you dig up the response object and use the sse method to send them the payload.