[SOLVED] MQTT connected status

Hi all.

I am looking at MQTT as a replacement for a ‘hack’ I currently use for a turn based game. I noticed that I can’t check in a easy way if the MQTT client is connected successfully to the server. tried looking at the JS code for the extension but it seems it’s minified, so I can’t actually modify/edit it. Any ideas what I could look to be able to check for the connected status or should I just trust the client to always connect to the server?

I think I managed to do it. I added a couple of listeners under the connect function in the MQTT extension:

// Set the connection flag
gdjs.evtTools.mqtt.connection.on("open", function(e) {
    gdjs.evtTools.mqtt.connected = "1";
});

// Reset the connection flag
gdjs.evtTools.mqtt.connection.on("close", function(e) {
    gdjs.evtTools.mqtt.connected = "0";
});

I also created a new condition function “IsConnected”

// Return the connected flag
eventsFunctionContext.returnValue = gdjs.evtTools.mqtt.connected;

It does seem to do what I need at the moment.

3 Likes

Maybe @nzandydean will be interested. :wink:

2 Likes

Very cool. Thanks steliosm for sharing and gruk for pointing it out

@arthuro555 do you think those changes can be added back into the library?

I am currently a bit busy with personal life and other GDevelop contributions, but sure, as soon as I get the time to do so.