jcubic / wayne

Service Worker Routing library for in browser HTTP requests
https://jcubic.github.io/wayne
MIT License
556 stars 29 forks source link

SSE should support event names #35

Closed 7flash closed 4 months ago

7flash commented 4 months ago

I am using wayne along with htmx and I would like elements to subscribe for specific events as in docs

<div hx-sse="connect:/sse">
  <div hx-sse="swap:eventName1">
    ...
  </div>
  <div hx-sse="swap:eventName2">
    ...
  </div>
</div>

then accordingly broadcast named events

app.get('/sse', function(req, res) {
//...
      stream.send({ name: 'eventName1', data: '' } );
});
jcubic commented 4 months ago

According to Server-Sent Events spec the name of the event is event: not name:.

See this tutorial https://javascript.info/server-sent-events#event-types

So you need:

stream.send({ event: 'eventName1', data: '' });