@@ -18,11 +18,59 @@ SocketIOclient::~SocketIOclient() {
1818void SocketIOclient::begin (const char * host, uint16_t port, const char * url, const char * protocol) {
1919 WebSocketsClient::beginSocketIO (host, port, url, protocol);
2020 WebSocketsClient::enableHeartbeat (60 * 1000 , 90 * 1000 , 5 );
21+ initClient ();
2122}
2223
2324void SocketIOclient::begin (String host, uint16_t port, String url, String protocol) {
2425 WebSocketsClient::beginSocketIO (host, port, url, protocol);
2526 WebSocketsClient::enableHeartbeat (60 * 1000 , 90 * 1000 , 5 );
27+ initClient ();
28+ }
29+ #if defined(HAS_SSL)
30+ void SocketIOclient::beginSSL (const char * host, uint16_t port, const char * url, const char * protocol) {
31+ WebSocketsClient::beginSocketIOSSL (host, port, url, protocol);
32+ WebSocketsClient::enableHeartbeat (60 * 1000 , 90 * 1000 , 5 );
33+ initClient ();
34+ }
35+
36+ void SocketIOclient::beginSSL (String host, uint16_t port, String url, String protocol) {
37+ WebSocketsClient::beginSocketIOSSL (host, port, url, protocol);
38+ WebSocketsClient::enableHeartbeat (60 * 1000 , 90 * 1000 , 5 );
39+ initClient ();
40+ }
41+ #if defined(SSL_BARESSL)
42+ void SocketIOclient::beginSSLWithCA (const char * host, uint16_t port, const char * url, const char * CA_cert, const char * protocol) {
43+ WebSocketsClient::beginSocketIOSSLWithCA (host, port, url, CA_cert, protocol);
44+ WebSocketsClient::enableHeartbeat (60 * 1000 , 90 * 1000 , 5 );
45+ initClient ();
46+ }
47+
48+ void SocketIOclient::beginSSLWithCA (const char * host, uint16_t port, const char * url, BearSSL::X509List * CA_cert, const char * protocol) {
49+ WebSocketsClient::beginSocketIOSSLWithCA (host, port, url, CA_cert, protocol);
50+ WebSocketsClient::enableHeartbeat (60 * 1000 , 90 * 1000 , 5 );
51+ initClient ();
52+ }
53+
54+ void SocketIOclient::setSSLClientCertKey (const char * clientCert, const char * clientPrivateKey) {
55+ WebSocketsClient::setSSLClientCertKey (clientCert, clientPrivateKey);
56+ }
57+
58+ void SocketIOclient::setSSLClientCertKey (BearSSL::X509List * clientCert, BearSSL::PrivateKey * clientPrivateKey) {
59+ WebSocketsClient::setSSLClientCertKey (clientCert, clientPrivateKey);
60+ }
61+
62+ #endif
63+ #endif
64+
65+ void SocketIOclient::configureEIOping (bool disableHeartbeat) {
66+ _disableHeartbeat = disableHeartbeat;
67+ }
68+
69+ void SocketIOclient::initClient (void ) {
70+ if (_client.cUrl .indexOf (" EIO=4" ) != -1 ) {
71+ DEBUG_WEBSOCKETS (" [wsIOc] found EIO=4 disable EIO ping on client\n " );
72+ configureEIOping (true );
73+ }
2674}
2775
2876/* *
@@ -51,7 +99,7 @@ bool SocketIOclient::send(socketIOmessageType_t type, uint8_t * payload, size_t
5199 if (length == 0 ) {
52100 length = strlen ((const char *)payload);
53101 }
54- if (clientIsConnected (&_client)) {
102+ if (clientIsConnected (&_client) && _client. status == WSC_CONNECTED ) {
55103 if (!headerToPayload) {
56104 // webSocket Header
57105 ret = WebSocketsClient::sendFrameHeader (&_client, WSop_text, length + 2 , true );
@@ -118,8 +166,8 @@ bool SocketIOclient::sendEVENT(String & payload) {
118166void SocketIOclient::loop (void ) {
119167 WebSocketsClient::loop ();
120168 unsigned long t = millis ();
121- if ((t - _lastConnectionFail ) > EIO_HEARTBEAT_INTERVAL) {
122- _lastConnectionFail = t;
169+ if (!_disableHeartbeat && (t - _lastHeartbeat ) > EIO_HEARTBEAT_INTERVAL) {
170+ _lastHeartbeat = t;
123171 DEBUG_WEBSOCKETS (" [wsIOc] send ping\n " );
124172 WebSocketsClient::sendTXT (eIOtype_PING);
125173 }
@@ -135,6 +183,7 @@ void SocketIOclient::handleCbEvent(WStype_t type, uint8_t * payload, size_t leng
135183 DEBUG_WEBSOCKETS (" [wsIOc] Connected to url: %s\n " , payload);
136184 // send message to server when Connected
137185 // Engine.io upgrade confirmation message (required)
186+ WebSocketsClient::sendTXT (" 2probe" );
138187 WebSocketsClient::sendTXT (eIOtype_UPGRADE);
139188 runIOCbEvent (sIOtype_CONNECT , payload, length);
140189 } break ;
@@ -165,6 +214,8 @@ void SocketIOclient::handleCbEvent(WStype_t type, uint8_t * payload, size_t leng
165214 DEBUG_WEBSOCKETS (" [wsIOc] get event (%d): %s\n " , lData, data);
166215 break ;
167216 case sIOtype_CONNECT :
217+ DEBUG_WEBSOCKETS (" [wsIOc] connected (%d): %s\n " , lData, data);
218+ return ;
168219 case sIOtype_DISCONNECT :
169220 case sIOtype_ACK :
170221 case sIOtype_ERROR :
0 commit comments