renderbug-cpp/firmware/MDNSService.cpp

34 lines
823 B
C++
Raw Normal View History

2021-03-28 01:19:55 +00:00
#include "MDNS/MDNS.h"
#include "Figments/Figments.h"
#include "Figments/MainLoop.h"
#include "Figments/Input.h"
#include "colors.h"
class MDNSService : public Task {
private:
mdns::MDNS m_mdns;
bool m_online = false;
public:
MDNSService() : Task("MDNS") {
}
void handleEvent(const InputEvent &evt) {
if (evt.intent == InputEvent::NetworkStatus) {
m_mdns.setHostname("renderbug");
m_mdns.addService("tcp", "http", 80, "Renderbug");
m_mdns.begin(true);
m_online = true;
}
}
void loop() override {
if (m_online) {
// Returns true when it reads at least one byte
if (m_mdns.processQueries()) {
MainLoop::instance()->dispatch(InputEvent::NetworkActivity);
}
}
}
};