| 386 | } |
| 387 | |
| 388 | void SIOClientImpl::handshakeResponse(HttpClient * /*sender*/, HttpResponse *response) { |
| 389 | CC_LOG_INFO("SIOClientImpl::handshakeResponse() called"); |
| 390 | |
| 391 | if (0 != strlen(response->getHttpRequest()->getTag())) { |
| 392 | CC_LOG_INFO("%s completed", response->getHttpRequest()->getTag()); |
| 393 | } |
| 394 | |
| 395 | auto statusCode = static_cast<int32_t>(response->getResponseCode()); |
| 396 | char statusString[64] = {}; |
| 397 | sprintf(statusString, "HTTP Status Code: %d, tag = %s", statusCode, response->getHttpRequest()->getTag()); |
| 398 | CC_LOG_INFO("response code: %ld", statusCode); |
| 399 | |
| 400 | if (!response->isSucceed() || statusCode >= 400) { |
| 401 | CC_LOG_ERROR("SIOClientImpl::handshake() failed"); |
| 402 | CC_LOG_ERROR("error buffer: %s", response->getErrorBuffer()); |
| 403 | |
| 404 | for (auto &client : _clients) { |
| 405 | client.second->getDelegate()->onError(client.second, response->getErrorBuffer()); |
| 406 | } |
| 407 | |
| 408 | onClose(nullptr, 1015, "handshake_failure", false); |
| 409 | return; |
| 410 | } |
| 411 | |
| 412 | CC_LOG_INFO("SIOClientImpl::handshake() succeeded"); |
| 413 | |
| 414 | ccstd::vector<char> *buffer = response->getResponseData(); |
| 415 | std::stringstream s; |
| 416 | s.str(""); |
| 417 | |
| 418 | for (const auto &iter : *buffer) { |
| 419 | s << iter; |
| 420 | } |
| 421 | |
| 422 | CC_LOG_INFO("SIOClientImpl::handshake() dump data: %s", s.str().c_str()); |
| 423 | |
| 424 | ccstd::string res = s.str(); |
| 425 | ccstd::string sid; |
| 426 | int heartbeat = 0; |
| 427 | int timeout = 0; |
| 428 | |
| 429 | if (res.find('}') != ccstd::string::npos) { |
| 430 | CC_LOG_INFO("SIOClientImpl::handshake() Socket.IO 1.x detected"); |
| 431 | _version = SocketIOPacket::SocketIOVersion::V10X; |
| 432 | // sample: 97:0{"sid":"GMkL6lzCmgMvMs9bAAAA","upgrades":["websocket"],"pingInterval":25000,"pingTimeout":60000} |
| 433 | // 96:0{"sid":"jzrjDlQusSUxLTd3AAAV","upgrades":["websocket"],"pingInterval":25000,"pingTimeout":5000}2:40 |
| 434 | ccstd::string::size_type a; |
| 435 | ccstd::string::size_type b; |
| 436 | a = res.find('{'); |
| 437 | ccstd::string temp = res.substr(a, res.size() - a); |
| 438 | |
| 439 | // find the sid |
| 440 | a = temp.find(':'); |
| 441 | b = temp.find(','); |
| 442 | |
| 443 | sid = temp.substr(a + 2, b - (a + 3)); |
| 444 | |
| 445 | temp = temp.erase(0, b + 1); |
no test coverage detected