@collight/dns-sd
    Preparing search index...

    Class DNSSD

    High-level API for Multicast DNS Service Discovery and Advertisement.

    The DNSSD class provides convenient methods for:

    • Publishing services to the local network
    • Browsing and discovering services
    • Unpublishing and cleaning up all registered services
    • Managing underlying mDNS server lifecycle

    It wraps a lower-level MDNSServer and coordinates interactions with the service Registry and service Browser.

    const dnssd = new DNSSD()

    // Advertise a new service
    dnssd.publish({ name: 'My Printer', type: 'printer', port: 9100 })

    // Discover services
    dnssd.startBrowser({ type: 'printer' }, service => {
    console.log('Found service:', service)
    })
    Index

    Methods

    • Destroys the DNSSD instance, stopping all services and shutting down the server.

      No further operations should be performed after destruction.

      Returns Promise<void>

    • Discovers a single service matching the provided criteria, with a timeout.

      Stops discovery after the first match or when the timeout is reached.

      Parameters

      • Optionaloptions: BrowserOptions

        Optional browser options to filter services.

      • timeoutMs: number = 10000

        Maximum time in milliseconds to wait for a match.

      Returns Promise<null | DiscoveredService>

      A promise that resolves with the discovered service or null if none found.

    • Creates a new mDNS browser for discovering services on the network.

      Parameters

      • Optionaloptions: BrowserOptions

        Optional configuration for the browser.

      Returns Browser

      A new Browser instance.

    • Creates a new service instance without publishing it to the network.

      Parameters

      Returns Service

      A new Service instance linked to this registry.

    • Publishes a service to the network using the given options.

      Parameters

      Returns Promise<Service>

      A promise that resolves with the published service.

    • Creates and starts a browser for discovering services, with an optional handler for discovered services.

      Parameters

      • Optionaloptions: BrowserOptions

        Optional configuration for the browser.

      • OptionalonServiceUp: (service: DiscoveredService) => void

        Optional callback invoked when a service is discovered.

      Returns Browser

      A started Browser instance.

    • Unpublishes all services that were previously published.

      Sends goodbye messages and clears internal state.

      Returns Promise<void>