-
Notifications
You must be signed in to change notification settings - Fork 21
Ping events propagated to main code socketIO events #18
Description
Is your feature request related to a problem? Please describe.
Using SocketIO with your library, I could really use the "ping"/"pong" events in the main code to detect when I am off internet.
One application of this feature-request is to trigger my watchdog timer in my Arduino board. If, for some reason, the internet is off then the Arduino board would get restarted.
Describe the solution you'd like
In order to make the above feature work, all we have to add is the following:
(of course not knowing if you have an even better solution to this - if you do, please let me know....)
Inside SocketIOclient_Generic.h file, you can add an event enum (see last line case 7):
typedef enum
{
sIOtype_CONNECT = '0',
sIOtype_DISCONNECT = '1',
sIOtype_EVENT = '2',
sIOtype_ACK = '3',
sIOtype_ERROR = '4',
sIOtype_BINARY_EVENT = '5',
sIOtype_BINARY_ACK = '6',
sIOtype_PING = '7',
} socketIOmessageType_t;
And inside SocketIOclient_Generic-Impl.h file, you can add one line of code to "deviate" the ping to the events-listener in the main code (please not the extra line with runIOCbEvent(sIOtype_PING, payload, length);)
case eIOtype_PING:
payload[0] = eIOtype_PONG;
WSK_LOGWARN1("[wsIOc] get ping send pong:", (char *) payload);
WebSocketsClient::sendTXT(payload, length, false);
runIOCbEvent(sIOtype_PING, payload, length);
break;
This allows in the main code:
void socketIOEvent(socketIOmessageType_t type, uint8_t* payload, size_t length) {
// switch socketIO events
switch (type) {
case sIOtype_PING:
/* PING */
watchdog.kick();
break;
// ...
}
}
Additional context
I tried to make a pull-request with this but the appropriate permissions are not available.
Feel free to implement the above solution if you find it helpful for others. Thank you.