diff --git a/client/controller.cpp b/client/controller.cpp index 0802f484..907b762e 100644 --- a/client/controller.cpp +++ b/client/controller.cpp @@ -212,6 +212,8 @@ void Controller::worker() logS(kLogErr) << "Exception in Controller::worker(): " << e.what() << endl; logO << "Stopping clientConnection" << endl; clientConnection_->stop(); + if (player_ != nullptr) + player_->stop(); logO << "Deleting stream" << endl; if (stream_ != NULL) delete stream_; diff --git a/server/streamServer.cpp b/server/streamServer.cpp index 03895ddd..0f3f1fa3 100644 --- a/server/streamServer.cpp +++ b/server/streamServer.cpp @@ -34,7 +34,6 @@ using json = nlohmann::json; StreamServer::StreamServer(const StreamServerSettings& streamServerSettings) : settings_(streamServerSettings), sampleFormat_(streamServerSettings.sampleFormat) { - serverSettings_.bufferMs = settings_.bufferMs; } @@ -118,6 +117,8 @@ void StreamServer::onMessageReceived(ControlSession* connection, const std::stri json response; ClientInfoPtr clientInfo = nullptr; + msg::ServerSettings serverSettings; + serverSettings.bufferMs = settings_.bufferMs; if (request.method.find("Client.Set") == 0) { @@ -148,21 +149,18 @@ void StreamServer::onMessageReceived(ControlSession* connection, const std::stri } else if (request.method == "Client.SetVolume") { - serverSettings_.volume = request.getParam("volume", 0, 100); - response = serverSettings_.volume; - clientInfo->volume.percent = serverSettings_.volume; + clientInfo->volume.percent = request.getParam("volume", 0, 100); + response = clientInfo->volume.percent; } else if (request.method == "Client.SetMute") { - serverSettings_.muted = request.getParam("mute", false, true); - response = serverSettings_.muted; - clientInfo->volume.muted = serverSettings_.muted; + clientInfo->volume.muted = request.getParam("mute", false, true); + response = clientInfo->volume.muted; } else if (request.method == "Client.SetLatency") { - serverSettings_.latency = request.getParam("latency", -10000, serverSettings_.bufferMs); - response = serverSettings_.latency; - clientInfo->latency = serverSettings_.latency; + clientInfo->latency = request.getParam("latency", -10000, settings_.bufferMs); + response = clientInfo->latency; } else if (request.method == "Client.SetName") { @@ -174,9 +172,13 @@ void StreamServer::onMessageReceived(ControlSession* connection, const std::stri if (clientInfo != nullptr) { + serverSettings.volume = clientInfo->volume.percent; + serverSettings.muted = clientInfo->volume.muted; + serverSettings.latency = clientInfo->latency; + ClientSession* session = getClientSession(request.getParam("client").get()); if (session != NULL) - session->send(&serverSettings_); + session->send(&serverSettings); Config::instance().save(); json notification = JsonNotification::getJson("Client.OnUpdate", clientInfo->toJson()); @@ -216,8 +218,14 @@ void StreamServer::onMessageReceived(ClientSession* connection, const msg::BaseM else if (requestMsg.request == kServerSettings) { std::unique_lock mlock(mutex_); - serverSettings_.refersTo = requestMsg.id; - connection->send(&serverSettings_); + ClientInfoPtr clientInfo = Config::instance().getClientInfo(connection->macAddress, true); + msg::ServerSettings serverSettings; + serverSettings.volume = clientInfo->volume.percent; + serverSettings.muted = clientInfo->volume.muted; + serverSettings.latency = clientInfo->latency; + serverSettings.refersTo = requestMsg.id; + serverSettings.bufferMs = settings_.bufferMs; + connection->send(&serverSettings); } else if (requestMsg.request == kSampleFormat) { @@ -318,6 +326,7 @@ void StreamServer::start() void StreamServer::stop() { + controlServer->stop(); acceptor_->cancel(); io_service_.stop(); acceptThread_.join(); diff --git a/server/streamServer.h b/server/streamServer.h index 0a47485d..badfa24d 100644 --- a/server/streamServer.h +++ b/server/streamServer.h @@ -103,7 +103,6 @@ private: StreamServerSettings settings_; msg::SampleFormat sampleFormat_; - msg::ServerSettings serverSettings_; std::thread acceptThread_; Queue> messages_; std::unique_ptr controlServer;