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

    Class Service

    Represents a service registered on the local network via mDNS/DNS-SD.

    This class manages the service's DNS resource records such as PTR, SRV, TXT, A, and AAAA, constructed according to the DNS-Based Service Discovery specification.

    Hierarchy

    • EventEmitter<ServiceEventMap>
      • Service

    Implements

    Index

    Properties

    disableIPv6: boolean

    Whether to disable publishing IPv6 addresses for this service.

    false
    
    host: string

    The hostname of the machine offering the service.

    os.hostname()
    
    name: string

    The instance name of the service. This will be sanitized by replacing dots with dashes.

    'MyPrinter'
    
    port: number

    The port number on which the service is listening.

    probe: boolean = true

    Whether to perform probing to detect name conflicts before publishing.

    true
    
    probeAutoResolve: boolean = true

    Whether to automatically resolve name conflicts by appending a number to the service name.

    true
    
    protocol: string

    The protocol used by the service, typically "tcp" or "udp".

    'tcp'
    
    subtypes: string[]

    Optional list of subtype identifiers for selective discovery.

    ttl: number

    The TTL (time to live) in seconds for the all records.

    The same TTL is set to all records (PTR, SRV, TXT, A, AAAA) for simplicity and compatibility.

    4500
    
    txt: Record<string, string | number | boolean | Buffer>

    Optional TXT record key-value pairs to advertise service metadata.

    type: string

    The service type (e.g., "http", "ipp"). Used to form the full service type domain.

    Methods

    • Generates all DNS resource records representing this service instance.

      This includes:

      • PTR record for the service type
      • SRV record with host and port
      • TXT record with metadata
      • PTR record advertising the service type in the _services._dns-sd._udp.local domain
      • PTR records for any declared subtypes
      • A and AAAA records for each network interface address (unless IPv6 is disabled)

      Returns MDNSRecord[]

      An array of DNS resource records suitable for publishing via mDNS.

    • Starts the registered service, initiating its publication on the network.

      If the service has already been started, this method does nothing.

      Returns Promise<void>

    • Stops the registered service and removes it from the network.

      Returns Promise<void>