htmx
htmx copied to clipboard
Add support for websocket binary data
This change enables ws extension user to handle binary data.
Hello, thank you for htmx, it's great :) Please let me know if this change is appropriate.
@Renerick do you mind reviewing this?
Hi! Thanks for your PR, I'll review this ASAP
Hello, @TristanCacqueray and thank you again for your contribution. I've reviewed this PR and here are my some of my thoughts.
First of all, I'm 100% on board with adding support for raw binary data in websockets. There already were some discussions regarding files support in outgoing messages so it is only logical to support it in the incoming messages as well.
That being said, having a page global callback in the config is not exactly htmx style. Typically this is done through events and I think we should stick with it. Unfortunately, this means I can not approve this change in its current state.
However, you may have noticed that at the moment WS extension has basically no events support, and this is entirely on me. While I've been doing some tinkering with it, I had no chance to publish anything finished yet. To signify that this should be fixed at the first opportunity (there are already two PRs including yours that could be done through events), I opened the issue (see above). I cannot give any estimations right now, which is not perfect predicament, but I have some ideas and scratches in the code, so hopefully it won't take too long.
For now, I'll leave this PR open and will get back to it once WS events are implemented, so you can see for yourself if the implementation is satisfactory for your use-case.
Alternatively, @1cg if you wish to close this PR to keep the list clear, it can be migrated into an issue
@Renerick thanks for the review, good to hear ws binary data support is planned, I'd be happy to use another API you see fit for htmx.
I am going to close this PR to help clean up my backlog.
@TristanCacqueray @Renerick do you want me to create an issue or discussion for this?
This will be covered by #1110
FYI, I just finished #1126. It introduces wsBinaryType configuration option that control corresponding WebSocket property. You can then access message content through htmx:wsBeforeMessage and htmx:wsAfterMessage events.
Any feedback about this solution will be much appreciated. Thank you for raising this issue!