diff --git a/ESP/lib/src/network/mDNS/MDNSManager.cpp b/ESP/lib/src/network/mDNS/MDNSManager.cpp index c267b3d..cbc2472 100644 --- a/ESP/lib/src/network/mDNS/MDNSManager.cpp +++ b/ESP/lib/src/network/mDNS/MDNSManager.cpp @@ -1,38 +1,39 @@ #include "MDNSManager.hpp" -MDNSHandler::MDNSHandler(StateManager *stateManager, - ProjectConfig *configManager) : stateManager(stateManager), - configManager(configManager) {} +MDNSHandler::MDNSHandler(StateManager* stateManager, + ProjectConfig* configManager) + : stateManager(stateManager), configManager(configManager) {} -bool MDNSHandler::startMDNS() -{ - ProjectConfig::MDNSConfig_t *mdnsConfig = configManager->getMDNSConfig(); - if (!MDNS.begin(mdnsConfig->hostname.c_str())) // lowercase only - as this will be the url - { - stateManager->setState(MDNSState_e::MDNSState_Error); - log_e("Error initializing MDNS"); - return false; - } +bool MDNSHandler::startMDNS() { + const std::string service = "_openiristracker"; + ProjectConfig::MDNSConfig_t* mdnsConfig = configManager->getMDNSConfig(); + if (!MDNS.begin(mdnsConfig->hostname + .c_str())) // lowercase only - as this will be the url + { + stateManager->setState(MDNSState_e::MDNSState_Error); + log_e("Error initializing MDNS"); + return false; + } - stateManager->setState(MDNSState_e::MDNSState_Starting); - MDNS.addService(("_" + mdnsConfig->hostname).c_str(), "_tcp", 80); - char port[20]; - //! Add service needs leading _ on ESP32 implementation for some reason (according to the docs) - MDNS.addServiceTxt(("_" + mdnsConfig->hostname).c_str(), "_tcp", "stream_port", "80"); //! convert int to const char* using a very efficient implemenation of itoa - log_i("MDNS initialized!"); - stateManager->setState(MDNSState_e::MDNSState_Started); - return true; + stateManager->setState(MDNSState_e::MDNSState_Starting); + MDNS.addService(service.c_str(), "_tcp", 80); + char port[20]; + //! Add service needs leading _ on ESP32 implementation for some reason + //! (according to the docs) + MDNS.addServiceTxt(service.c_str(), "_tcp", "stream_port", + "80"); + log_i("MDNS initialized!"); + stateManager->setState(MDNSState_e::MDNSState_Started); + return true; } -void MDNSHandler::update(ObserverEvent::Event event) -{ - switch (event) - { - case ObserverEvent::Event::mdnsConfigUpdated: - MDNS.end(); - startMDNS(); - break; - default: - break; - } +void MDNSHandler::update(ObserverEvent::Event event) { + switch (event) { + case ObserverEvent::Event::mdnsConfigUpdated: + MDNS.end(); + startMDNS(); + break; + default: + break; + } }