mirror of
https://github.com/sle118/squeezelite-esp32.git
synced 2026-05-04 12:29:37 +01:00
move to new cspot
This commit is contained in:
@@ -0,0 +1,45 @@
|
||||
#include "MDNSService.h"
|
||||
#include "dns_sd.h"
|
||||
#include <arpa/inet.h>
|
||||
|
||||
using namespace bell;
|
||||
|
||||
/**
|
||||
* MacOS implementation of MDNSService.
|
||||
* @see https://developer.apple.com/documentation/dnssd/1804733-dnsserviceregister
|
||||
**/
|
||||
void* MDNSService::registerService(
|
||||
const std::string& serviceName,
|
||||
const std::string& serviceType,
|
||||
const std::string& serviceProto,
|
||||
const std::string& serviceHost,
|
||||
int servicePort,
|
||||
const std::map<std::string, std::string> txtData
|
||||
) {
|
||||
DNSServiceRef* ref = new DNSServiceRef();
|
||||
TXTRecordRef txtRecord;
|
||||
TXTRecordCreate(&txtRecord, 0, NULL);
|
||||
for (auto& data : txtData) {
|
||||
TXTRecordSetValue(&txtRecord, data.first.c_str(), data.second.size(), data.second.c_str());
|
||||
}
|
||||
DNSServiceRegister(
|
||||
ref, /* sdRef */
|
||||
0, /* flags */
|
||||
0, /* interfaceIndex */
|
||||
serviceName.c_str(), /* name */
|
||||
(serviceType + "." + serviceProto).c_str(), /* regType (_spotify-connect._tcp) */
|
||||
NULL, /* domain */
|
||||
NULL, /* host */
|
||||
htons(servicePort), /* port */
|
||||
TXTRecordGetLength(&txtRecord), /* txtLen */
|
||||
TXTRecordGetBytesPtr(&txtRecord), /* txtRecord */
|
||||
NULL, /* callBack */
|
||||
NULL /* context */
|
||||
);
|
||||
TXTRecordDeallocate(&txtRecord);
|
||||
return ref;
|
||||
}
|
||||
|
||||
void MDNSService::unregisterService(void* ref) {
|
||||
DNSServiceRefDeallocate((DNSServiceRef)ref);
|
||||
}
|
||||
Reference in New Issue
Block a user