34 lines
823 B
C++
34 lines
823 B
C++
|
#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);
|
||
|
}
|
||
|
}
|
||
|
}
|
||
|
};
|