I am just getting started with cfwebsockets and I am having a bit of trouble. What I found from online, is that since this is public-facing application, it is best to use a websocket proxy.
CF2021, Version: 2021.0.03.329779
Ubuntu 20.04LTS
Steps so far:
I added the websocket package to my server and enabled web-sockets. Restarted Server.
Added this to my application.cfc:
<cfset this.wschannels = [ {name="chat"} ] />
(the application has a this.name= set from a variable as well 3. created a simple page that has this:
<cfwebsocket
name="wSocketObj"
onMessage="wsOnMessage"
onOpen="wsOnOpen"
onClose="wsOnClose"
onError="wsOnError"
subscribeTo="chat"
secure="true"/>
<script type="text/javascript">
wsOnMessage = function(aEvent,aToken) {
console.log('wsOnMessage',aevent);
var message = ColdFusion.JSON.encode(atoken);
var txt=document.getElementById("myDiv");
txt.innerHTML +=message +"<br>";
}
wsOnOpen = function() {
alert("wsOnOpen Connection is open");
}
wsOnClose = function() {
alert("wsOnClose Connection Closed");
}
wsOnError = function() {
alert("wsOnError!");
console.log(arguments);
}
sendMessage = function() {
var text = window.prompt("Enter some text","");
if (text) {
wSocketObj.publish("chat", text);
}
}
</script>
<cfdiv id="myDiv"></cfdiv>
<div id="myChatArea"></div>
<input type="text" id="myMessage" /><input id="myButton" type="button" value="Send Message" onClick="sendMessage()" />
got this in the Chrome Console:
WebSocket connection to 'wss://myhost.mydomain.com:8555/cfusion/cfusion' failed: CFWebSocketWrapper.open @ cfwebsocketCore.js:21 init @ cfwebsocketChannel.js:49 _cf_websockets_init_6322652258206397 @ client.cfm:35 fire @ cfajax.js:1214 $E.windowLoadHandler @ cfajax.js:1321 cfwebsocketCore.js:54 Uncaught TypeError: Cannot set properties of undefined (setting 'readyState') at WebSocket.wsConnection.onerror (cfwebsocketCore.js:54:29)
thinking it was a firewall issue, I disabled it in Ubuntu
- It was at this point that it seemed to be that I needed to configure a proxy.
- I ran /opt/ColdFusion/cfusion/bin/wsproxyconfig.sh from the command line and verified that both the line in apache2.conf was there and the folder "/opt/ColdFusion/config/wsproxy/1/mod_wsproxy.conf" was created. Restarted apache2 and CF2021
- Same Result
- Realized I need to change the websocket config in CF Admin,
- When I select the Use Proxy in CF Admin, the Save Changes button disappears and I cannot save it.
Obviously I am missing something very fundamental here. Any help that anyone can provide would be appreciated.
thanks in advance