the code to write to the EEPROM when there isn't a socket message for 5 sec must be outside of any code that is waiting for a socket message. the code to reset the state and msecLast doesn't need to be in the code to process a socket message, it can be reset when the function that does process the message is called.
i don't see a main() and where onWebSocketEvent() is called, so this doesn't look like the entire code.