SEND WEBSOCKET MESSAGES
After you have created a WebSocket client framework, you can begin to tie outgoing messages as soon as the onOpen() function has started. This function will be run by the open event, after the connection handshake process is complete, indicating that a connection is active.
Because WebSockets are a full-duplex protocol, you can technically send a WebSocket message at any time to the server, after, that is, you have established a successful connection, of course. There is not much point in limiting your outgoing messages to only the onOpen() function, unless the WebSocket service does not require any additional messages.
Therefore, you need a way to be able to send commands, but only while online. This is accomplished by ...