mirror of
https://github.com/clangen/musikcube.git
synced 2024-10-02 13:02:35 +00:00
Fail websocket connection on server version mismatch. In the future
we'll need to make this smarter via semver or something.
This commit is contained in:
parent
463e82c8a3
commit
fbe1eef87f
@ -52,6 +52,7 @@ static const std::string TAG = "RemoteLibrary";
|
||||
using namespace musik::core;
|
||||
using namespace musik::core::db;
|
||||
using namespace musik::core::library;
|
||||
using namespace musik::core::net;
|
||||
using namespace musik::core::runtime;
|
||||
|
||||
#define MESSAGE_QUERY_COMPLETED 5000
|
||||
@ -327,10 +328,8 @@ void RemoteLibrary::ProcessMessage(musik::core::runtime::IMessage &message) {
|
||||
}
|
||||
else if (message.Type() == MESSAGE_UPDATE_CONNECTION_STATE) {
|
||||
auto updatedState = (ConnectionState)message.UserData1();
|
||||
if (updatedState != this->connectionState) {
|
||||
this->connectionState = updatedState;
|
||||
this->ConnectionStateChanged(this->connectionState);
|
||||
}
|
||||
this->connectionState = updatedState;
|
||||
this->ConnectionStateChanged(this->connectionState);
|
||||
}
|
||||
}
|
||||
|
||||
@ -349,7 +348,12 @@ void RemoteLibrary::OnClientStateChanged(Client* client, State newState, State o
|
||||
};
|
||||
|
||||
if (this->messageQueue) {
|
||||
if (newState == State::Disconnected) {
|
||||
const auto reason = this->wsc.LastConnectionError();
|
||||
bool attemptReconnect =
|
||||
newState == State::Disconnected &&
|
||||
reason != WebSocketClient::ConnectionError::InvalidPassword &&
|
||||
reason != WebSocketClient::ConnectionError::IncompatibleVersion;
|
||||
if (attemptReconnect) {
|
||||
this->messageQueue->Remove(this, MESSAGE_RECONNECT_SOCKET);
|
||||
this->messageQueue->Post(Message::Create(this, MESSAGE_RECONNECT_SOCKET), 2500);
|
||||
}
|
||||
|
@ -35,6 +35,7 @@
|
||||
#include "pch.hpp"
|
||||
|
||||
#include <musikcore/net/WebSocketClient.h>
|
||||
#include <musikcore/version.h>
|
||||
#include <nlohmann/json.hpp>
|
||||
|
||||
using namespace musik::core;
|
||||
@ -114,7 +115,13 @@ WebSocketClient::WebSocketClient(Listener* listener) {
|
||||
auto messageId = responseJson["id"].get<std::string>();
|
||||
if (name == "authenticate") {
|
||||
this->connection = connection;
|
||||
this->SetState(State::Connected);
|
||||
auto appVersion = responseJson["options"]["environment"]["app_version"];
|
||||
if (!appVersion.is_string() || appVersion.get<std::string>() != VERSION) {
|
||||
this->SetDisconnected(ConnectionError::IncompatibleVersion);
|
||||
}
|
||||
else {
|
||||
this->SetState(State::Connected);
|
||||
}
|
||||
}
|
||||
else if (name == "send_raw_query") {
|
||||
auto query = this->messageIdToQuery[messageId];
|
||||
|
@ -69,8 +69,9 @@ namespace musik { namespace core { namespace net {
|
||||
enum class ConnectionError : int {
|
||||
None = 0,
|
||||
InvalidPassword = 1,
|
||||
ConnectionFailed = 2,
|
||||
ClosedByServer = 3,
|
||||
IncompatibleVersion = 2,
|
||||
ConnectionFailed = 3,
|
||||
ClosedByServer = 4,
|
||||
};
|
||||
|
||||
class Listener {
|
||||
|
@ -57,6 +57,7 @@ static inline std::string resolveErrorMessage(MasterLibraryPtr library) {
|
||||
{ WebSocketClient::ConnectionError::ClosedByServer, "library_error_closed_by_server" },
|
||||
{ WebSocketClient::ConnectionError::ConnectionFailed, "library_error_connection_failed" },
|
||||
{ WebSocketClient::ConnectionError::InvalidPassword, "library_error_invalid_password" },
|
||||
{ WebSocketClient::ConnectionError::IncompatibleVersion, "library_error_incompatible_version" },
|
||||
};
|
||||
|
||||
auto remoteLibrary = dynamic_cast<const RemoteLibrary*>(library->Wrapped().get());
|
||||
|
@ -252,6 +252,7 @@
|
||||
"library_error_connection_failed": "server offline",
|
||||
"library_error_closed_by_server": "server hung up",
|
||||
"library_error_invalid_password": "incorrect password",
|
||||
"library_error_incompatible_version": "incompatible server version",
|
||||
"library_error_unknown": "???",
|
||||
"library_configuration_in_settings": "the library connection can be configured in settings",
|
||||
"library_remote_connected_banner": "connected to %s",
|
||||
|
Loading…
Reference in New Issue
Block a user