question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Discussion for WebSockets extension syntax

See original GitHub issue

We’re moving WebSockets support into an extension (so it was decreed by @1cg). This thread is to collect suggestions/feedback on the syntax that we use in the new code. I’m going to start on this after I work out SSEs (#618), so please let me know if I’m missing anything, or if there’s something we should add. Now is the time 😃

I would like to keep it as close to the existing syntax as possible, but there are some funny things with the existing code, so now might be our chance to normalize it a little.

Questions:

  1. Do we want to keep the swap-oob syntax for received messages? Or is there another way to target DIVs that might be better? This would be cool, but I don’t think the WebSocket protocol gives us anything standard to work with. Would love to get input from someone using the current hx-ws tag.

  2. Is there a better / more convenient way to send messages? I’m going to propose multiple encoding options for this data, including JSON (the current encoding), URL encoded, and multipart FormData.

Here’s my first pass:

<div hx-ext="websocket" ws-connect="/my-websocket-address">
    <form ws-send="json | url | form ">
        <input name="message"/>
    </form>
</div>

Issue Analytics

  • State:closed
  • Created 2 years ago
  • Comments:6 (1 by maintainers)

github_iconTop GitHub Comments

1reaction
benpatecommented, Oct 29, 2021

I’m posting progress on this extension to https://github.com/benpate/htmx/tree/pr-websocket-extension. It’s not at all ready to use, but it’s starting to take shape, in case anyone wants to follow along or add comments/suggestions.

1reaction
benpatecommented, Oct 26, 2021

Perhaps we could allow WebSockets to parse/execute arbitrary JavaScript or hyperscript? It would work pretty cleanly as

<script type="text/hyperscript">
go to "http://location"
</script>
Read more comments on GitHub >

github_iconTop Results From Across the Web

Discussion for SSE extension syntax · Issue #618
We're moving SSE support into an extension (so it was decreed by @1cg). This thread is to collect suggestions/feedback on the syntax that...
Read more >
WebSockets - Quick Guide
Web sockets are defined as a two-way communication between the servers and the clients, which mean both the parties communicate and exchange data...
Read more >
Writing WebSocket servers - Web APIs | MDN
Extensions control the WebSocket frame and modify the payload, while subprotocols structure the WebSocket payload and never modify anything.
Read more >
The WebSocket protocol
The WebSocket protocol enables two-way communication between a client running untrusted code running in a controlled environment to a remote ...
Read more >
Browser APIs and Protocols: WebSocket
WebSocket is a set of multiple standards: the WebSocket API is defined by the W3C, and the WebSocket protocol (RFC 6455) and its...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found