JavaScript: sendHeartbeat

Sends a heartbeat message if the socket is connected.