diff --git a/src/core/library/RemoteLibrary.cpp b/src/core/library/RemoteLibrary.cpp index 3c021e22b..2eb0f18b7 100644 --- a/src/core/library/RemoteLibrary.cpp +++ b/src/core/library/RemoteLibrary.cpp @@ -38,6 +38,7 @@ #include #include #include +#include #include #include #include @@ -57,10 +58,6 @@ using namespace musik::core::runtime; #define MESSAGE_RECONNECT_SOCKET 5001 #define MESSAGE_UPDATE_CONNECTION_STATE 5002 -static const std::string kServerHost = "192.168.1.227"; -static const std::string kServerPassword = "842655"; -static const short kServerPort = 7905; - class NullIndexer: public musik::core::IIndexer { public: virtual ~NullIndexer() override { } @@ -101,9 +98,9 @@ RemoteLibrary::RemoteLibrary(std::string name, int id) , exit(false) , messageQueue(nullptr) , wsc(this) { - this->wsc.Connect(kServerHost, kServerPort, kServerPassword); this->identifier = std::to_string(id); this->thread = new std::thread(std::bind(&RemoteLibrary::ThreadProc, this)); + this->ReloadConnectionFromPreferences(); } RemoteLibrary::~RemoteLibrary() { @@ -325,7 +322,7 @@ void RemoteLibrary::ProcessMessage(musik::core::runtime::IMessage &message) { } else if (message.Type() == MESSAGE_RECONNECT_SOCKET) { if (this->wsc.ConnectionState() == Client::State::Disconnected) { - this->wsc.Connect(kServerHost, kServerPort, kServerPassword); + this->ReloadConnectionFromPreferences(); } } else if (message.Type() == MESSAGE_UPDATE_CONNECTION_STATE) { @@ -386,17 +383,31 @@ std::string RemoteLibrary::GetTrackUri(musik::core::sdk::ITrack* track, const st } } - const std::string uri = "http://" + kServerHost + ":7906/audio/id/" + std::to_string(track->GetId()); + auto prefs = Preferences::ForComponent(core::prefs::components::Settings); + auto host = prefs->GetString(core::prefs::keys::RemoteLibraryHostname, "127.0.0.1"); + auto port = (short) prefs->GetInt(core::prefs::keys::RemoteLibraryHttpPort, 7905); + auto password = prefs->GetString(core::prefs::keys::RemoteLibraryPassword, ""); + + const std::string uri = "http://" + host + ":" + std::to_string(port) + "/audio/id/" + std::to_string(track->GetId()); nlohmann::json path = { { "uri", uri }, { "type", type }, - { "password", kServerPassword } + { "password", password } }; return "musikcore://remote-track/" + path.dump(); } /* RemoteLibrary */ + const net::WebSocketClient& RemoteLibrary::WebSocketClient() const { return this->wsc; +} + +void RemoteLibrary::ReloadConnectionFromPreferences() { + auto prefs = Preferences::ForComponent(core::prefs::components::Settings); + auto host = prefs->GetString(core::prefs::keys::RemoteLibraryHostname, "127.0.0.1"); + auto port = (short) prefs->GetInt(core::prefs::keys::RemoteLibraryWssPort, 7905); + auto password = prefs->GetString(core::prefs::keys::RemoteLibraryPassword, ""); + this->wsc.Connect(host, port, password); } \ No newline at end of file diff --git a/src/core/library/RemoteLibrary.h b/src/core/library/RemoteLibrary.h index 6144f713e..a9db3f96a 100644 --- a/src/core/library/RemoteLibrary.h +++ b/src/core/library/RemoteLibrary.h @@ -95,6 +95,7 @@ namespace musik { namespace core { namespace library { virtual std::string GetTrackUri(musik::core::sdk::ITrack* track, const std::string& defaultUri) override; /* RemoteLibrary */ + void ReloadConnectionFromPreferences(); const musik::core::net::WebSocketClient& WebSocketClient() const; private: diff --git a/src/core/support/PreferenceKeys.cpp b/src/core/support/PreferenceKeys.cpp index a992e69eb..decb5e896 100644 --- a/src/core/support/PreferenceKeys.cpp +++ b/src/core/support/PreferenceKeys.cpp @@ -67,7 +67,8 @@ namespace musik { namespace core { namespace prefs { const std::string keys::AuddioApiToken = "AuddioApiToken"; const std::string keys::LibraryType = "LibraryType"; const std::string keys::RemoteLibraryHostname = "RemoteLibraryHostname"; - const std::string keys::RemoteLibraryPort = "RemoteLibraryPort"; + const std::string keys::RemoteLibraryWssPort = "RemoteLibraryWssPort"; + const std::string keys::RemoteLibraryHttpPort = "RemoteLibraryHttpPort"; const std::string keys::RemoteLibraryPassword = "RemoteLibraryPassword"; } } } diff --git a/src/core/support/PreferenceKeys.h b/src/core/support/PreferenceKeys.h index fe7c29795..fd479a31d 100644 --- a/src/core/support/PreferenceKeys.h +++ b/src/core/support/PreferenceKeys.h @@ -71,7 +71,8 @@ namespace musik { namespace core { namespace prefs { extern const std::string AuddioApiToken; extern const std::string LibraryType; extern const std::string RemoteLibraryHostname; - extern const std::string RemoteLibraryPort; + extern const std::string RemoteLibraryWssPort; + extern const std::string RemoteLibraryHttpPort; extern const std::string RemoteLibraryPassword; } diff --git a/src/musikcube/app/layout/RemoteLibrarySettingsLayout.cpp b/src/musikcube/app/layout/RemoteLibrarySettingsLayout.cpp index 9774950ce..09936edc1 100644 --- a/src/musikcube/app/layout/RemoteLibrarySettingsLayout.cpp +++ b/src/musikcube/app/layout/RemoteLibrarySettingsLayout.cpp @@ -72,7 +72,8 @@ RemoteLibrarySettingsLayout::~RemoteLibrarySettingsLayout() { void RemoteLibrarySettingsLayout::OnLayout() { size_t labelWidth = longestStringLength({ "settings_library_type_remote_hostname", - "settings_library_type_remote_port", + "settings_library_type_remote_wss_port", + "settings_library_type_remote_http_port", "settings_library_type_remote_password" }); @@ -81,10 +82,13 @@ void RemoteLibrarySettingsLayout::OnLayout() { int y = 0; this->hostLabel->MoveAndResize(0, y, labelWidth, 1); this->hostInput->MoveAndResize(labelWidth + 1, y++, inputWidth, 1); - this->portLabel->MoveAndResize(0, y, labelWidth, 1); - this->portInput->MoveAndResize(labelWidth + 1, y++, 5, 1); + this->wssPortLabel->MoveAndResize(0, y, labelWidth, 1); + this->wssPortInput->MoveAndResize(labelWidth + 1, y++, 5, 1); + this->httpPortLabel->MoveAndResize(0, y, labelWidth, 1); + this->httpPortInput->MoveAndResize(labelWidth + 1, y++, 5, 1); this->pwLabel->MoveAndResize(0, y, labelWidth, 1); this->pwInput->MoveAndResize(labelWidth + 1, y++, inputWidth, 1); + ++y; this->ipv6Cb->MoveAndResize(0, y++, cx, 1); } @@ -95,9 +99,13 @@ void RemoteLibrarySettingsLayout::InitializeWindows() { this->hostLabel->SetText(_TSTR("settings_library_type_remote_hostname"), text::AlignRight); this->hostInput.reset(new TextInput(TextInput::StyleLine)); - this->portLabel.reset(new TextLabel()); - this->portLabel->SetText(_TSTR("settings_library_type_remote_port"), text::AlignRight); - this->portInput.reset(new TextInput(TextInput::StyleLine)); + this->wssPortLabel.reset(new TextLabel()); + this->wssPortLabel->SetText(_TSTR("settings_library_type_remote_wss_port"), text::AlignRight); + this->wssPortInput.reset(new TextInput(TextInput::StyleLine)); + + this->httpPortLabel.reset(new TextLabel()); + this->httpPortLabel->SetText(_TSTR("settings_library_type_remote_http_port"), text::AlignRight); + this->httpPortInput.reset(new TextInput(TextInput::StyleLine)); this->pwLabel.reset(new TextLabel()); this->pwLabel->SetText(_TSTR("settings_library_type_remote_password"), text::AlignRight); @@ -108,15 +116,20 @@ void RemoteLibrarySettingsLayout::InitializeWindows() { this->AddWindow(this->hostLabel); this->AddWindow(this->hostInput); - this->AddWindow(this->portLabel); - this->AddWindow(this->portInput); + this->AddWindow(this->hostLabel); + this->AddWindow(this->hostInput); + this->AddWindow(this->wssPortLabel); + this->AddWindow(this->wssPortInput); + this->AddWindow(this->httpPortLabel); + this->AddWindow(this->httpPortInput); this->AddWindow(this->pwLabel); this->AddWindow(this->pwInput); this->AddWindow(this->ipv6Cb); int order = 0; this->hostInput->SetFocusOrder(order++); - this->portInput->SetFocusOrder(order++); + this->wssPortInput->SetFocusOrder(order++); + this->httpPortInput->SetFocusOrder(order++); this->pwInput->SetFocusOrder(order++); this->ipv6Cb->SetFocusOrder(order++); } diff --git a/src/musikcube/app/layout/RemoteLibrarySettingsLayout.h b/src/musikcube/app/layout/RemoteLibrarySettingsLayout.h index 382124dab..e5affa674 100644 --- a/src/musikcube/app/layout/RemoteLibrarySettingsLayout.h +++ b/src/musikcube/app/layout/RemoteLibrarySettingsLayout.h @@ -61,8 +61,8 @@ namespace musik { namespace cube { musik::core::ILibraryPtr library; std::shared_ptr prefs; - std::shared_ptr portLabel, hostLabel, pwLabel; - std::shared_ptr portInput, hostInput, pwInput; + std::shared_ptr httpPortLabel, wssPortLabel, hostLabel, pwLabel; + std::shared_ptr httpPortInput, wssPortInput, hostInput, pwInput; std::shared_ptr ipv6Cb; }; } } diff --git a/src/musikcube/app/layout/SettingsLayout.cpp b/src/musikcube/app/layout/SettingsLayout.cpp index 06a3bd76d..c655a47c9 100755 --- a/src/musikcube/app/layout/SettingsLayout.cpp +++ b/src/musikcube/app/layout/SettingsLayout.cpp @@ -334,7 +334,7 @@ void SettingsLayout::OnLayout() { } else { this->localLibraryLayout->Hide(); - this->remoteLibraryLayout->MoveAndResize(2, 3, cx - 4, 4); + this->remoteLibraryLayout->MoveAndResize(2, 3, cx - 4, 6); libraryLayout = this->remoteLibraryLayout; } libraryLayout->Show(); diff --git a/src/musikcube/data/locales/en_US.json b/src/musikcube/data/locales/en_US.json index 899f9ade5..c6b985a48 100644 --- a/src/musikcube/data/locales/en_US.json +++ b/src/musikcube/data/locales/en_US.json @@ -109,7 +109,8 @@ "settings_library_type_local": "local", "settings_library_type_remote": "remote", "settings_library_type_remote_hostname": "hostname:", - "settings_library_type_remote_port": "port:", + "settings_library_type_remote_wss_port": "metadata port:", + "settings_library_type_remote_http_port": "audio port:", "settings_library_type_remote_password": "password:", "settings_library_type_overlay_title": "library type",