htmx icon indicating copy to clipboard operation
htmx copied to clipboard

Add support for websocket binary data

Open TristanCacqueray opened this issue 3 years ago • 5 comments
trafficstars

This change enables ws extension user to handle binary data.

TristanCacqueray avatar Oct 23 '22 23:10 TristanCacqueray

Hello, thank you for htmx, it's great :) Please let me know if this change is appropriate.

TristanCacqueray avatar Oct 23 '22 23:10 TristanCacqueray

@Renerick do you mind reviewing this?

1cg avatar Oct 29 '22 03:10 1cg

Hi! Thanks for your PR, I'll review this ASAP

Renerick avatar Oct 29 '22 12:10 Renerick

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 avatar Oct 31 '22 09:10 Renerick

@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.

TristanCacqueray avatar Nov 05 '22 15:11 TristanCacqueray

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?

1cg avatar Nov 09 '22 17:11 1cg

This will be covered by #1110

Renerick avatar Nov 09 '22 17:11 Renerick

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!

Renerick avatar Dec 03 '22 20:12 Renerick