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

Wildcard / catch-all namespace for event handlers #1285

Closed
mooomooo opened this issue Dec 28, 2023 · 1 comment
Closed

Wildcard / catch-all namespace for event handlers #1285

mooomooo opened this issue Dec 28, 2023 · 1 comment
Assignees

Comments

@mooomooo
Copy link

Is your feature request related to a problem? Please describe.
It's possible to accept connections on any namespace by specifying namespaces='*' in either Server init, but you can't actually handle arbitrary namespaces: unless a namespace is explicitly defined by an event handler, any client packets using it will get silently dropped.

Describe the solution you'd like
Allow specifying an event handler with namespace='*' to be a catch-all handler in the absence of an explicit namespace match. In that case, the handler should also be given an explicit namespace parameter with the namespace from the client packet.

Additional context
Such a thing is already implemented for catch-all event handlers in the server's _trigger_event (e.g.

elif event not in self.reserved_events and \
'*' in self.handlers[namespace]:
), so similar logic could probably be used at the namespace level as well.

This is could perhaps allow a high level approach to #1166 with less library overhead since there'd be no regex comparison (though it could nonetheless be done by a user if so desired).

@miguelgrinberg
Copy link
Owner

Yes, in principle I like this idea as it is consistent with previous work for event handlers. The event handlers attached to the catch all namespace will need to receive the namespace as an additional argument, so that they can implement logic that depends on which namespace the client used.

Would you like to give this idea a try and send a PR?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants