Class MDNS

Hierarchy

  • StartStop
    • MDNS

Constructors

Properties

[initLock]: RWLockWriter
_groups: Host[]
_hostname: Hostname
_id: number = 0
_localServices: Map<FQDN, Service> = ...
_networkServices: Map<FQDN, Service> = ...
_port: Port
_unicast: boolean = false
advertisements: Map<string, PromiseCancellable<void>> = ...
getNetworkInterfaces: (() => NetworkInterfaces | PromiseLike<NetworkInterfaces>)

Type declaration

localRecordCache: ResourceRecordCache
localRecordCacheDirty: boolean = true
logger: Logger
networkRecordCache: ResourceRecordCache
queries: Map<string, PromiseCancellable<void>> = ...
runningTasks: Set<PromiseCancellable<void>> = ...

Represents the advertisements and queries that have been cancelled and are in the process of stopping

socketHostTable: Table<SocketHostRow> = ...
socketMap: WeakMap<Socket, SocketInfo> = ...
sockets: Socket[] = []

Accessors

  • get [eventHandled](): ReadonlyWeakSet<Event>
  • Returns ReadonlyWeakSet<Event>

  • get [eventHandlers](): ReadonlyMap<string, Set<EventHandlerInfo>>
  • Returns ReadonlyMap<string, Set<EventHandlerInfo>>

  • get [eventTarget](): EventTarget
  • Returns EventTarget

  • get [handleEventError](): ((evt) => void)
  • Returns ((evt) => void)

      • (evt): void
      • Parameters

        • evt: EventError

        Returns void

  • get [running](): boolean
  • Returns boolean

  • get [statusP](): Promise<Status>
  • Returns Promise<Status>

  • get [status](): Status
  • Returns Status

  • get groups(): readonly Host[]
  • Gets the multicast groups MDNS is bound to. There will always be at least 1 value.

    Returns readonly Host[]

  • get hostname(): string
  • Gets the multicast hostname this socket is bound to. This will always end in .local.

    Returns string

  • get id(): number
  • Gets the id used for DNS packets. This is 16 bit.

    Returns number

  • get localServices(): ReadonlyMap<string, ServicePOJO>
  • Returns a Map of services that you have registered. The Key is a FQDN.

    Returns ReadonlyMap<string, ServicePOJO>

  • get networkServices(): ReadonlyMap<string, ServicePOJO>
  • Returns a Map of services on the network. The Key is a FQDN.

    Returns ReadonlyMap<string, ServicePOJO>

  • get port(): Port
  • Gets the bound resolved port. This cannot be 0. Because 0 is always resolved to a specific port.

    Returns Port

  • get unicast(): boolean
  • Gets the unicast flag. This will be true if a socket is deemed able to receive unicast responses.

    Returns boolean

Methods

  • Parameters

    • type: string
    • callback: null | EventListenerOrEventListenerObject
    • Optional options: boolean | AddEventListenerOptions

    Returns void

  • Parameters

    • event: Event

    Returns boolean

  • Parameters

    • e: any
    • socket: Socket

    Returns Promise<void>

  • Parameters

    Returns Promise<undefined | boolean>

  • Parameters

    Returns Promise<void>

  • Parameters

    Returns Promise<void>

  • Parameters

    Returns Promise<void>

  • Registers a service

    Parameters

    • opts: {
          advertise?: boolean;
          name: string;
          port: number;
          protocol: "udp" | "tcp";
          txt?: Record<string, string>;
          type: string;
      }
      • Optional advertise?: boolean

        Allows MDNS to advertise the service on registration. Defaults to true.

      • name: string

        The name of the service you want to register.

      • port: number

        The port of the service you want to register.

      • protocol: "udp" | "tcp"

        The protocol of service you want to register. This is either 'udp' or 'tcp'.

      • Optional txt?: Record<string, string>

        The TXT data of the service you want to register. This is represented as a key-value POJO.

      • type: string

        The type of service you want to register.

    Returns void

  • Parameters

    • type: string
    • callback: null | EventListenerOrEventListenerObject
    • Optional options: boolean | EventListenerOptions

    Returns void

  • Starts MDNS

    Parameters

    • opts: {
          advertise?: boolean;
          disableLinuxMulticastAllOption?: boolean;
          groups?: string[];
          hostname?: string;
          id?: number;
          ipv6Only?: boolean;
          port?: number;
      }
      • Optional advertise?: boolean

        Allows MDNS to advertise it's hostnames. Defaults to true.

      • Optional disableLinuxMulticastAllOption?: boolean
      • Optional groups?: string[]

        The multicast group IP addresses to multi-cast on. This must as least have one element. This can have both IPv4 and IPv6 and must. Defaults to ['224.0.0.251', 'ff02::fb'].

      • Optional hostname?: string

        The hostname to use for the MDNS stack. Defaults to the OS hostname.

      • Optional id?: number

        The unique unsigned 16 bit integer ID used for all outgoing MDNS packets. Defaults to a random number.

      • Optional ipv6Only?: boolean

        Makes MDNS to bind exclusively IPv6 sockets. Defaults to false.

      • Optional port?: number

        The port to bind to. Defaults to 5353 the default MDNS port. Defaults to 5353.

    Returns Promise<void>

    Throws

    • If opts.groups is empty.

    Throws

    • If a socket cannot bind.

    Throws

    • If no valid interfaces have been found.
  • Start a query for services of a specific type and protocol. If there already is a query running for the type and protocol combination, it will be cancelled and restarted.

    Parameters

    • opts: {
          maxDelay?: number;
          minDelay?: number;
          protocol: "udp" | "tcp";
          type: string;
      }
      • Optional maxDelay?: number

        The maximum delay between queries in seconds. Defaults to 3600 (1 hour).

      • Optional minDelay?: number

        The minimum delay between queries in seconds. Defaults to 1.

      • protocol: "udp" | "tcp"

        The protocol of service you want to query for. This is either 'udp' or 'tcp'.

      • type: string

        The type of service you want to query for.

    Returns void

  • Stops MDNS This will unregister all services and hosts, sending a goodbye packet. This will flush all records from the cache. This will close all sockets.

    Returns Promise<void>

  • Stops a service query that you have started with startQuery

    Parameters

    • opts: {
          protocol: "udp" | "tcp";
          type: string;
      }
      • protocol: "udp" | "tcp"

        The protocol of service you want to stop querying for. This is either 'udp' or 'tcp'.

      • type: string

        The type of service you want to stop querying for.

    Returns void

  • Un-registers a service that you have registered with registerService

    Parameters

    • opts: {
          name: string;
          protocol: "udp" | "tcp";
          type: string;
      }
      • name: string

        The name of the service you want to unregister.

      • protocol: "udp" | "tcp"

        The protocol of service you want to unregister. This is either 'udp' or 'tcp'.

      • type: string

        The type of service you want to unregister.

    Returns void

Generated using TypeDoc