ralscha / sse-eventbus

EventBus library for sending events from a Spring appliction to the web browser with SSE
Apache License 2.0
79 stars 26 forks source link

Subscribe to any event #3

Closed smithtonson closed 6 years ago

smithtonson commented 6 years ago

Is there a way to subscribe to all events when connecting a client? It seems like right now I have to manually give a list of all my event types as not giving a list causes the client to be subscribed only to the default "message" type.

Perhaps the eventSubscribers hashMap could have a "*" key that clients get added to if no list of events are passed during connection? That way the isUserSubscribed() method can look for the clientId in the named event key or in the "*" all events key.

ralscha commented 6 years ago

I like the idea. But the problem is as far as I know there is no why to subscribe to all events on the client. https://stackoverflow.com/questions/9933619/html5-eventsource-listener-for-all-events?rq=1

smithtonson commented 6 years ago

There isn’t a way to handle that case on the client, but any events without matching client handler are discarded without error.

The client I’m working on has a lot of event types so we’re just looking to make the code cleaner by registering for everything and not having a handler on the client side for the ones that the client doesn’t want/care about.

—josh

On Dec 14, 2017, at 12:34 PM, Ralph Schaer notifications@github.com wrote:

I like the idea. But the problem is as far as I know there is no why to subscribe to all events on the client. https://stackoverflow.com/questions/9933619/html5-eventsource-listener-for-all-events?rq=1

— You are receiving this because you authored the thread. Reply to this email directly, view it on GitHub, or mute the thread.

ralscha commented 6 years ago

With these changes it's possible to create your own registry. Would this solve your problem?

@Component
public class CustomSubscriptionRegistry extends DefaultSubscriptionRegistry {

    @Override
    public boolean isClientSubscribedToEvent(String clientId, String eventName) {
        return super.isClientSubscribedToEvent(clientId, eventName)
                || super.isClientSubscribedToEvent(clientId, "*");
    }

}
smithtonson commented 6 years ago

Seems like it. I’ll have to give a test. Thanks again!

—josh

On Dec 16, 2017, at 8:10 AM, Ralph Schaer notifications@github.com wrote:

With these changes it's possible to create your own registry. Would this solve your problem?

@Component public class CustomSubscriptionRegistry extends DefaultSubscriptionRegistry {

@Override public boolean isClientSubscribedToEvent(String clientId, String eventName) { return super.isClientSubscribedToEvent(clientId, eventName) || super.isClientSubscribedToEvent(clientId, "*"); }

} — You are receiving this because you authored the thread. Reply to this email directly, view it on GitHub, or mute the thread.