| 25 | } |
| 26 | |
| 27 | void WebSocketWorker::run() |
| 28 | { |
| 29 | if (pingTimer) { |
| 30 | pingTimer->stop(); |
| 31 | delete pingTimer; |
| 32 | pingTimer = nullptr; |
| 33 | } |
| 34 | if (webSocket) { |
| 35 | webSocket->blockSignals(true); |
| 36 | webSocket->abort(); |
| 37 | delete webSocket; |
| 38 | webSocket = nullptr; |
| 39 | } |
| 40 | |
| 41 | webSocket = new QWebSocket; |
| 42 | auto SslConf = webSocket->sslConfiguration(); |
| 43 | SslConf.setPeerVerifyMode( QSslSocket::VerifyNone ); |
| 44 | SslConf.setProtocol( QSsl::TlsV1_2OrLater ); |
| 45 | webSocket->setSslConfiguration( SslConf ); |
| 46 | webSocket->ignoreSslErrors(); |
| 47 | |
| 48 | connect( webSocket, &QWebSocket::connected, this, &WebSocketWorker::is_connected ); |
| 49 | connect( webSocket, &QWebSocket::disconnected, this, &WebSocketWorker::is_disconnected ); |
| 50 | connect( webSocket, &QWebSocket::binaryMessageReceived, this, &WebSocketWorker::is_binaryMessageReceived ); |
| 51 | connect( webSocket, &QWebSocket::pong, this, &WebSocketWorker::is_pong ); |
| 52 | |
| 53 | #if QT_VERSION >= QT_VERSION_CHECK(6, 5, 0) |
| 54 | connect( webSocket, &QWebSocket::errorOccurred, this, &WebSocketWorker::is_error); |
| 55 | #else |
| 56 | connect( webSocket, QOverload<QAbstractSocket::SocketError>::of(&QWebSocket::error), this, &WebSocketWorker::is_error); |
| 57 | #endif |
| 58 | |
| 59 | QJsonObject otpData; |
| 60 | otpData["client_type"] = 1; |
| 61 | otpData["console_team_mode"] = profile->GetConsoleMultiuser(); |
| 62 | QJsonArray subsArray; |
| 63 | for (const QString &sub : profile->GetSubscriptions()) |
| 64 | subsArray.append(sub); |
| 65 | otpData["subscriptions"] = subsArray; |
| 66 | |
| 67 | QString otp; |
| 68 | bool otpResult = HttpReqGetOTP("connect", otpData, profile->GetURL(), profile->GetAccessToken(), &otp); |
| 69 | if (!otpResult) { |
| 70 | this->ok = false; |
| 71 | this->message = "Failed to generate OTP for connect"; |
| 72 | Q_EMIT ws_error(); |
| 73 | return; |
| 74 | } |
| 75 | |
| 76 | QString urlTemplate = "wss://%1:%2%3/connect"; |
| 77 | QString sUrl = urlTemplate.arg( profile->GetHost() ).arg( profile->GetPort() ).arg( profile->GetEndpoint() ); |
| 78 | |
| 79 | QUrl url(sUrl); |
| 80 | QUrlQuery query; |
| 81 | query.addQueryItem("otp", otp); |
| 82 | url.setQuery(query); |
| 83 | |
| 84 | QNetworkRequest request; |
nothing calls this directly
no test coverage detected