I have posted quite a few bit of log information on this thread:
And found that restarting Lucee twice in a row will get the websocket to connect and return a message, then close after 60 seconds as noted here:
However I am either quite ignorant/clueless on how this websocket works or it is broken.
My 1st issue is, I have no way of figuring out who just connected to my websocket. I was hoping to get some guidance from the wsclient argument, but when I send that back as JSON data, it empty, so I do not know what parts there are to look at.
When I try to store the wsclient into a Session, or Application Scope, it does not modify the variable.
I tried to read the Session Scope and the websocket would disconnect.
I see I can use WebsocketInfo() and run thru the instances, but I still do not know how I would compare that to a list because I do not know who just connected. I thought for a moment I could add them to an Application list, but when I have more then 1 person in the list, I still do not know how I can identify who just connected if all I can do is loop through the websocketInfo() instance of connections.
My code is pretty much a copy of the examples
In Application.cfc OnApplicationStart() I set
Application.thisClient = "";
websocket.cfc
component hint="websockets"
{
public static function onFirstOpen( wsclients )
{
static.wsclients = arguments.wsclients;
Session.thisClient = 'hello';
Application.thisClient = 'merpsies';
}
function onOpen( wsclient )
{
//var thisClient = Session.sessionObj.getUserId(); //this will close the connection
Application.thisClient = 'Oh my';
var thisAppClient = Application.thisClient;
//static.wsclients.broadcast("There are now #static.wsclients.size()# connections");
//var wsInfo = websocketInfo(false);
//var wsInstances = wsInfo.instances;
arguments.wsclient.send( Application.thisClient );
}
function onOpenAsync( wsclient )
{
}
function onMessage( wsclient, message )
{
}
function onClose( wsclient, reasonPhrase )
{
}
function onError( wsclient, cfcatch )
{
}
public static function onLastClose()
{
}
}
My test.cfm
<!--- "directory":"{lucee-config}/websockets/", --->
<cfset thisUUID = CreateUUID() >
<!---
<cfset Application.thisClient = 'new' />
<cfset Session.thisClient = "Me" /> --->
<script type="text/javascript">
const socket = new WebSocket("wss://dev.example.com:446/ws/websocket?uuid=<cfoutput>#thisUUID#</cfoutput>");
socket.onopen = function (evt) {
console.log("Connected");
socket.send("Hello, Lucee Extension!");
};
socket.onmessage = function (event) {
console.log("Received:", event.data);
};
socket.onclose = function (evt) {
console.log("Connection closed");
};
socket.onerror = function (error) {
console.error("WebSocket error:", error);
};
</script>
<cfdump var="#Session.thisClient#" />
<cfdump var="#Application.thisClient#" />
<cfdump var="#Session.sessionObj.getUserId()#" />
A page setup so I can look at what was altered
<cfdump var="#websocketInfo()#" />
<cfdump var="#Session.thisClient#" />
<cfdump var="#Application.thisClient#" />
In the onOpen() section, you can see I set the Application.thisClient to “Oh my” And the websocket will recieve “Oh my” but if I refresh the page I setup to look at the variables, it is still set to “”.
So even if I knew how to pull the id from the wsclient onOpen() I have no way of saving it to the application scope.
What am I missing? Any direction is much appreciated as I am now scratching my head.