<@U0F134LG2> it appears you will need to use the <...
# cfml-general
j
@brendan it appears you will need to use the htmx:wsBeforeMessage event to parse out the data you need as you can not change how the message that is sent from ColdFusion is packaged, and you would not want to as it contains important information regarding the type of message it is, the publisher and content. You can look at how I handle a message receipt on the
onmessage
function on the
cfwebsocket.js
file. The following link should have those specific lines highlighted for you. https://github.com/GiancarloGomez/ColdFusion-Realtime-With-WebSockets-Demo-Code/blob/master/html-to-coldfusion/cfwebsocket.js#L34-L57
b
Thanks @jc I looked into the wsBeforeMessage event and even though I had trouble making changes to the ws message using it, searching about it I found a solution using a custom extension/function to pull out the data from the object. For reference, here's my final, simplified, code for using HTMX to listen to CF's websocket server:
<div hx-ext="ws,transform-response" ws-connect="<ws://127.0.0.1:8585/cfusion/cfusion>" ws-send hx-trigger="load"></div>
<script>
document.body.addEventListener('htmx:wsConfigSend', function(evt) {
var subscribe = {"type":"welcome","subscribeTo":"feed","appName":"snake"}
evt.detail.messageBody = JSON.stringify(subscribe);
});
htmx.defineExtension("transform-response", {
transformResponse : function(text, xhr, elt) {
var data = JSON.parse(text).data;
return data;
}
});
</script>