Open vigie opened 4 years ago
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?
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
I am connecting to a broker that expects an
auth-token
header on everyCONNECT
,SUBSCRIBE
,UNSUBSCRIBE
andDISCONNECT
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: