mysterious-toddler-20573
02/15/2021, 3:58 PMuser
02/15/2021, 3:58 PMmysterious-toddler-20573
02/15/2021, 3:59 PMmysterious-toddler-20573
02/15/2021, 3:59 PMmysterious-toddler-20573
02/15/2021, 4:00 PMuser
02/15/2021, 4:00 PMmysterious-toddler-20573
02/15/2021, 4:00 PMuser
02/15/2021, 4:01 PMmysterious-toddler-20573
02/15/2021, 4:01 PMmysterious-toddler-20573
02/15/2021, 4:02 PMuser
02/15/2021, 4:10 PMmysterious-toddler-20573
02/15/2021, 4:15 PMmysterious-toddler-20573
02/15/2021, 4:15 PMmysterious-toddler-20573
02/15/2021, 4:16 PMmysterious-toddler-20573
02/15/2021, 4:16 PMuser
02/15/2021, 4:16 PMuser
02/15/2021, 4:17 PMuser
02/15/2021, 4:18 PMuser
02/15/2021, 4:21 PMjs
htmx.on("htmx:historyCacheMiss", function(){
location.reload();
})blue-manchester-57655
02/15/2021, 4:32 PM<div hx-ws="connect wss:/chatroom">
<div id="chat_room">
...
</div>
<form hx-ws="send:submit">
<input name="chat_message">
</form>
</div>
Which is the approach I'd like. I want to specify ws: if I'm on local and wss: otherwise (I can swap the prefix via django templates very easily)
When I do so, though, I get this error:
htmx.js:1054 Uncaught TypeError: Cannot read property 'indexOf' of undefined
at processWebSocketSource (htmx.js:1054)
at processWebSocketInfo (htmx.js:1045)
at initNode (htmx.js:1316)
at htmx.js:1325
at forEach (htmx.js:209)
at processNode (htmx.js:1325)
at HTMLDocument.<anonymous> (htmx.js:2317)
Using the approach at https://htmx.org/attributes/hx-ws/ I do this
<div hx-ws="connect:/chatroom">
<div id="chat_room">
...
</div>
<form hx-ws="send">
<input name="chat_message">
</form>
</div>
But HTMX automatically substitutes wss: as the prefix:
function processWebSocketSource(elt, wssSource) {
if (wssSource.indexOf("ws:") !== 0 && wssSource.indexOf("wss:") !== 0) {
wssSource = "wss:" + wssSource;
}
...
Should that first approach be working, or am I confused somewhere? Still pretty new to WebSockets, so it may just be me.mysterious-toddler-20573
02/15/2021, 4:54 PMmysterious-toddler-20573
02/15/2021, 4:54 PMmysterious-toddler-20573
02/15/2021, 4:57 PMmysterious-toddler-20573
02/15/2021, 4:57 PMmysterious-toddler-20573
02/15/2021, 4:59 PMblue-manchester-57655
02/15/2021, 5:00 PMhx-ws="connect ws:/chatroom" does not work
hx-ws="connect:ws:/chatroom" doesmysterious-toddler-20573
02/15/2021, 5:01 PMmysterious-toddler-20573
02/15/2021, 5:01 PMhx-ws="connect:ws:/chatroom" is the correct syntax