mDNS browser
TypeScript/JavaScript library for discovery and publishing of services using Multicast DNS (mDNS) and DNS-SD also known as Zeroconf/Bonjour.
To install:
npm install tinkerhub-mdns
Example:
const MDNSServiceDiscovery = ; const discovery = type: 'spotify-connect'; // Listen for services as they become availablediscovery; // And for updates to them, such as new network addressesdiscovery; // And for when they are no longer availablediscovery; // When discovery is no longer needed destroy itdiscovery;
Service data
Every service discovered using this discovery will have some data available:
id: string
- the identifier of the service, the hostname as used in DNS-SDname: string
- the parsed nametype: string
- the type of serviceprotocol: 'tcp' | 'udp'
- the protocol used in the registrationsubtypes: string[]
- subtypes found for the serviceaddresses: HostAndPort[]
- addresses where the service can be reacheddata: Map<string, string | boolean>
- decoded data for the servicebinaryData: Buffer[]
- raw binary data
Publishing services
This library supports publishing of services using MDNSServicePublisher
:
; const publisher = name: 'unique-name-of-service' type: 'http' protocol: 'tcp' port: 8080; // To unpublish call destroy()await publisher;