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

Introduce API for registering message interceptors #290

Open
vigie opened this issue Oct 12, 2020 · 2 comments
Open

Introduce API for registering message interceptors #290

vigie opened this issue Oct 12, 2020 · 2 comments
Labels
help wanted Extra attention is needed

Comments

@vigie
Copy link

vigie commented Oct 12, 2020

I am connecting to a broker that expects an auth-token header on every CONNECT, SUBSCRIBE, UNSUBSCRIBE and DISCONNECT message. If the token that is sent is bad, it will disconnect the websocket.

I would like a clean mechanism by which to proactively ensure the token I am sending is good, rather than cleaning up the mess in an onError callback. This mechanism must of course be async so that I am able to refresh the token before sending, should this be necessary.

The interceptor pattern is commonly used with HTTP clients. It could be applied here also:

before any message is sent, allow the execution of a chain of client-provided asynchronous functions that can make arbitrary modifications to that frame, before forwarding along the chain, ultimately terminating in the library's client.send method. Something like:

intercept(frame: IFrame): Promise<IFrame>
@kum-deepak
Copy link
Member

I get your problem and I believe that the approach you have suggested is proper. Would you like to submit a PR or you would like me to make the change?

@vigie
Copy link
Author

vigie commented Oct 14, 2020

I'm not sure how soon I could start, but if I do start I'll let you know here. Please also post here if you (or anybody else) starts work on this

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
help wanted Extra attention is needed
Projects
None yet
Development

No branches or pull requests

2 participants