@collight/dns-sd
Version:
A DNS Service Discovery implementation in modern TypeScript
88 lines (87 loc) • 3.14 kB
TypeScript
import { MDNSServer } from '../utils';
import { Service, ServiceOptions } from './Service';
export declare class Registry {
static MAX_PROBE_AUTO_RESOLVE_ATTEMPTS: number;
static REANNOUNCE_MAX_MS: number;
static REANNOUNCE_FACTOR: number;
private server;
private startedServices;
constructor(server: MDNSServer);
/**
* Creates a new `Service` instance with the given options,
* and links it to this registry.
*
* @param options - The configuration options for the service.
* @returns A new `Service` instance.
*/
makeService(options: ServiceOptions): Service;
/**
* Publishes a service to the network using the given options.
* This includes optional probing and sending announcement packets.
*
* @param options - The configuration options for the service.
* @returns A promise that resolves with the published `Service`.
*/
publish(options: ServiceOptions): Promise<Service>;
/**
* Stops and unpublishes all currently running services.
*
* Sends goodbye messages and clears internal service state.
*/
unpublishAll(): Promise<void>;
/**
* Marks all services as destroyed without unpublishing them.
*
* Used when permanently shutting down the registry and disable future operations.
*/
destroy(): void;
/**
* Internal handler invoked when a service is started.
*
* This will initiate probing (if enabled) and trigger the initial announcement.
*
* @internal
* @param service - The service being started.
* @param options - Optional configuration to override probing behavior.
*/
onServiceStart(service: Service): Promise<void>;
/**
* Internal handler invoked when a service is stopped.
*
* Sends goodbye messages and updates internal state.
*
* @internal
* @param service - The service being stopped.
*/
onServiceStop(service: Service): Promise<void>;
/**
* Probes the network to detect service name conflicts before announcing.
*
* Follows RFC 6762 §8.1–8.3 to ensure uniqueness by sending multiple queries
* and listening for conflicting responses.
*
* @param service - The service to probe for potential name conflicts.
*/
private probe;
/**
* Announces a newly registered service to the network.
*
* Sends initial responses immediately, then exponentially spaced re-announcements
* (3s, 9s, 27s...) up to one hour intervals per RFC 6762 §8.3.
*
* @param service - The service to announce.
*
* @see {@link https://datatracker.ietf.org/doc/html/rfc6762#section-8.3 | Announcing}
*/
private announce;
/**
* Send goodbye messages for a list of services and unregistering them.
*
* Each record's TTL is set to 0 to indicate that the service is going offline.
*
* @param services - Array of services to remove from the network.
*
* @see {@link https://datatracker.ietf.org/doc/html/rfc6762#section-10.1 | Goodbye Packets}
*/
private goodbye;
}