UNPKG

3.31 kBTypeScriptView Raw
1// Type definitions for bonjour 3.5
2// Project: https://github.com/watson/bonjour
3// Definitions by: Quentin Lampin <https://github.com/quentin-ol>
4// Definitions: https://github.com/DefinitelyTyped/DefinitelyTyped
5
6/// <reference types="node" />
7
8import { RemoteInfo } from "dgram";
9
10declare function bonjour(opts?: bonjour.BonjourOptions): bonjour.Bonjour;
11export = bonjour;
12declare namespace bonjour {
13 /**
14 * Start a browser
15 *
16 * The browser listens for services by querying for PTR records of a given
17 * type, protocol and domain, e.g. _http._tcp.local.
18 *
19 * If no type is given, a wild card search is performed.
20 *
21 * An internal list of online services is kept which starts out empty. When
22 * ever a new service is discovered, it's added to the list and an "up" event
23 * is emitted with that service. When it's discovered that the service is no
24 * longer available, it is removed from the list and a "down" event is emitted
25 * with that service.
26 */
27 interface Browser extends NodeJS.EventEmitter {
28 services: RemoteService[];
29 start(): void;
30 update(): void;
31 stop(): void;
32 on(event: "up" | "down", listener: (service: RemoteService) => void): this;
33 once(event: "up" | "down", listener: (service: RemoteService) => void): this;
34 removeListener(event: "up" | "down", listener: (service: RemoteService) => void): this;
35 removeAllListeners(event?: "up" | "down"): this;
36 }
37 interface BrowserOptions {
38 type?: string | undefined;
39 subtypes?: string[] | undefined;
40 protocol?: string | undefined;
41 txt?: { [key: string]: string } | undefined;
42 }
43
44 interface ServiceOptions {
45 name: string;
46 host?: string | undefined;
47 port: number;
48 type: string;
49 subtypes?: string[] | undefined;
50 protocol?: "udp" | "tcp" | undefined;
51 txt?: { [key: string]: string } | undefined;
52 probe?: boolean | undefined;
53 }
54
55 interface BaseService {
56 name: string;
57 fqdn: string;
58 host: string;
59 port: number;
60 type: string;
61 protocol: string;
62 subtypes: string[];
63 txt: { [key: string]: string };
64 }
65 interface RemoteService extends BaseService {
66 referer: RemoteInfo;
67 rawTxt: Buffer;
68 addresses: string[];
69 }
70 interface Service extends BaseService, NodeJS.EventEmitter {
71 published: boolean;
72 addresses: string[];
73
74 stop(cb?: () => void): void;
75 start(): void;
76 }
77 interface BonjourOptions {
78 type?: "udp4" | "udp6" | undefined;
79 multicast?: boolean | undefined;
80 interface?: string | undefined;
81 port?: number | undefined;
82 ip?: string | undefined;
83 ttl?: number | undefined;
84 loopback?: boolean | undefined;
85 reuseAddr?: boolean | undefined;
86 }
87 interface Bonjour {
88 (opts?: BonjourOptions): Bonjour;
89 publish(options: ServiceOptions): Service;
90 unpublishAll(cb?: () => void): void;
91 find(options: BrowserOptions, onUp?: (service: RemoteService) => void): Browser;
92 findOne(options: BrowserOptions, cb?: (service: RemoteService) => void): Browser;
93 destroy(): void;
94 }
95}