mpetazzoni/sse.js

onmessage handler does not dispatch events for custom event types

Closed this issue · 3 comments

Custom event types do not trigger onmessage handler

The issue is quite simple. If your backend sends a SSE-Event with a custom type, this type will be overwriten and you have to add an event-handler for this event.
But I think this is a bit missleading, because the default interface "only" supports a onmessage handler.

I would propose to also forward all events to this handler, so that developers then can check for event.type in a generalized implementation by themselves.

If this proposal would be fine, I would open a PR with this implementation and link this issue here.

I don't disagree, but unfortunately I think this would go against the EventSource specification. The type of the event being fired is meant to be defined by the SSE event type, defaulting to message if not set. You need to use addEventListener('my_event_type', ...) to handle custom event types.

I don't disagree, but unfortunately I think this would go against the EventSource specification. The type of the event being fired is meant to be defined by the SSE event type, defaulting to message if not set. You need to use addEventListener('my_event_type', ...) to handle custom event types.

Thanks for the reply.
Then I will leave it as is. I already did it the way you described, but I figured, it would be a confinience feature ^^
Will close this discussion.

I agree, I'm thinking about what's the best way to enable this. Maybe allowing for registering an event listener that gets all events, regardless of event type. It would help for use cases like #61 for example.