The goal with this is to have a full implementation of MDNS standarts for decoding and encoding in type script.
yarn add @airpie/mdns
Start will create a socket using a random port. This is event driven. Whenever an event is triggered a global event will be fired along side with the specific event.
An event with packet will trigger a new event with the packt decoded.
This sends a query.
import { start, events as mdnsEvents, send, PACKET_RECEIVED } from '@airpie/mdns';
const questions = [
`_airplay_._tcp.local`,
].map((q) => ({
name: q,
type: 0xff,
class: 0x8001,
}));
const TRANSACTION_ID = 0x1111; // any number that would identify queries and responses.
const encodedQuery = encode.header(questions, TRANSACTION_ID);
send(encodedQuery);
mdnsEvents.on(PACKET_RECEIVED, (decodedPacket: DecodedPacket) => {
console.log(decodedPacket);
});
Lots of documentation is necessary specifically around
- Store & State Management
- Event management
- Encoding & Decoding
- Better logging
The idea is to have a close as possible to 100% coverage (I know overrated), but because there are some many nuances from the protocol definition it's better to have all basis covered
This is written from the ground up. Many libraries found were incomplete, lacked documentation and/or reference to resources. This is to start clean and make it as straight forward as possible.
Please PRs are welcome, and emails as well. Feel free to contact me to chat about this.
Coming soon