UNPKG

7.15 kBTypeScriptView Raw
1import { MDNSServerOptions, ServiceTxt } from "@homebridge/ciao";
2import { InterfaceName, IPAddress } from "@homebridge/ciao/lib/NetworkManager";
3import { EventEmitter } from "events";
4import { AccessoryInfo } from "./model/AccessoryInfo";
5/**
6 * This enum lists all bitmasks for all known status flags.
7 * When the bit for the given bitmask is set, it represents the state described by the name.
8 *
9 * @group Advertiser
10 */
11export declare const enum StatusFlag {
12 NOT_PAIRED = 1,
13 NOT_JOINED_WIFI = 2,
14 PROBLEM_DETECTED = 4
15}
16/**
17 * This enum lists all bitmasks for all known pairing feature flags.
18 * When the bit for the given bitmask is set, it represents the state described by the name.
19 *
20 * @group Advertiser
21 */
22export declare const enum PairingFeatureFlag {
23 SUPPORTS_HARDWARE_AUTHENTICATION = 1,
24 SUPPORTS_SOFTWARE_AUTHENTICATION = 2
25}
26/**
27 * @group Advertiser
28 */
29export declare const enum AdvertiserEvent {
30 /**
31 * Emitted if the underlying mDNS advertisers signals, that the service name
32 * was automatically changed due to some naming conflicts on the network.
33 */
34 UPDATED_NAME = "updated-name"
35}
36/**
37 * @group Advertiser
38 */
39export declare interface Advertiser {
40 on(event: "updated-name", listener: (name: string) => void): this;
41 emit(event: "updated-name", name: string): boolean;
42}
43/**
44 * @group Advertiser
45 */
46export interface ServiceNetworkOptions {
47 /**
48 * If defined it restricts the service to be advertised on the specified
49 * ip addresses or interface names.
50 *
51 * If an interface name is specified, ANY address on that given interface will be advertised
52 * (if an IP address of the given interface is also given in the array, it will be overridden).
53 * If an IP address is specified, the service will only be advertised for the given addresses.
54 *
55 * Interface names and addresses can be mixed in the array.
56 * If an ip address is given, the ip address must be valid at the time of service creation.
57 *
58 * If the service is set to advertise on a given interface, though the MDNSServer is
59 * configured to ignore this interface, the service won't be advertised on the interface.
60 */
61 restrictedAddresses?: (InterfaceName | IPAddress)[];
62 /**
63 * The service won't advertise ipv6 address records.
64 * This can be used to simulate binding on 0.0.0.0.
65 * May be combined with {@link restrictedAddresses}.
66 */
67 disabledIpv6?: boolean;
68}
69/**
70 * A generic Advertiser interface required for any MDNS Advertiser backend implementations.
71 *
72 * All implementations have to extend NodeJS' {@link EventEmitter} and emit the events defined in {@link AdvertiserEvent}.
73 *
74 * @group Advertiser
75 */
76export interface Advertiser {
77 initPort(port: number): void;
78 startAdvertising(): Promise<void>;
79 updateAdvertisement(silent?: boolean): void;
80 destroy(): void;
81}
82/**
83 * Advertiser uses mdns to broadcast the presence of an Accessory to the local network.
84 *
85 * Note that as of iOS 9, an accessory can only pair with a single client. Instead of pairing your
86 * accessories with multiple iOS devices in your home, Apple intends for you to use Home Sharing.
87 * To support this requirement, we provide the ability to be "discoverable" or not (via a "service flag" on the
88 * mdns payload).
89 *
90 * @group Advertiser
91 */
92export declare class CiaoAdvertiser extends EventEmitter implements Advertiser {
93 static protocolVersion: string;
94 static protocolVersionService: string;
95 private readonly accessoryInfo;
96 private readonly setupHash;
97 private readonly responder;
98 private readonly advertisedService;
99 constructor(accessoryInfo: AccessoryInfo, responderOptions?: MDNSServerOptions, serviceOptions?: ServiceNetworkOptions);
100 initPort(port: number): void;
101 startAdvertising(): Promise<void>;
102 updateAdvertisement(silent?: boolean): void;
103 destroy(): Promise<void>;
104 static createTxt(accessoryInfo: AccessoryInfo, setupHash: string): ServiceTxt;
105 static computeSetupHash(accessoryInfo: AccessoryInfo): string;
106 static ff(...flags: PairingFeatureFlag[]): number;
107 static sf(...flags: StatusFlag[]): number;
108}
109/**
110 * Advertiser base on the legacy "bonjour-hap" library.
111 *
112 * @group Advertiser
113 */
114export declare class BonjourHAPAdvertiser extends EventEmitter implements Advertiser {
115 private readonly accessoryInfo;
116 private readonly setupHash;
117 private readonly serviceOptions?;
118 private bonjour;
119 private advertisement?;
120 private port?;
121 private destroyed;
122 constructor(accessoryInfo: AccessoryInfo, serviceOptions?: ServiceNetworkOptions);
123 initPort(port: number): void;
124 startAdvertising(): Promise<void>;
125 updateAdvertisement(silent?: boolean): void;
126 destroy(): void;
127}
128/**
129 * @group Advertiser
130 */
131export declare class DBusInvokeError extends Error {
132 readonly errorName: string;
133 constructor(errorObject: {
134 name: string;
135 message: any;
136 });
137}
138/**
139 * Advertiser based on the Avahi D-Bus library.
140 * For (very crappy) docs on the interface, see the XML files at: https://github.com/lathiat/avahi/tree/master/avahi-daemon.
141 *
142 * Refer to https://github.com/lathiat/avahi/blob/fd482a74625b8db8547b8cfca3ee3d3c6c721423/avahi-common/defs.h#L120-L155 for a
143 * rough API usage guide of Avahi.
144 *
145 * @group Advertiser
146 */
147export declare class AvahiAdvertiser extends EventEmitter implements Advertiser {
148 private readonly accessoryInfo;
149 private readonly setupHash;
150 private port?;
151 private bus?;
152 private avahiServerInterface?;
153 private path?;
154 private readonly stateChangeHandler;
155 constructor(accessoryInfo: AccessoryInfo);
156 private createTxt;
157 initPort(port: number): void;
158 startAdvertising(): Promise<void>;
159 /**
160 * Event handler for the `StateChanged` event of the `org.freedesktop.Avahi.Server` DBus interface.
161 *
162 * This is called once the state of the running avahi-daemon changes its running state.
163 * @param state - The state the server changed into {@see AvahiServerState}.
164 */
165 private handleStateChangedEvent;
166 updateAdvertisement(silent?: boolean): Promise<void>;
167 destroy(): Promise<void>;
168 static isAvailable(): Promise<boolean>;
169 private static avahiInvoke;
170 private static avahiInterface;
171}
172/**
173 * Advertiser based on the systemd-resolved D-Bus library.
174 * For docs on the interface, see: https://www.freedesktop.org/software/systemd/man/org.freedesktop.resolve1.html
175 *
176 * @group Advertiser
177 */
178export declare class ResolvedAdvertiser extends EventEmitter implements Advertiser {
179 private readonly accessoryInfo;
180 private readonly setupHash;
181 private port?;
182 private bus?;
183 private path?;
184 constructor(accessoryInfo: AccessoryInfo);
185 private createTxt;
186 initPort(port: number): void;
187 startAdvertising(): Promise<void>;
188 updateAdvertisement(silent?: boolean): Promise<void>;
189 private stopAdvertising;
190 destroy(): Promise<void>;
191 static isAvailable(): Promise<boolean>;
192 private static resolvedInvoke;
193 private static managerInvoke;
194}
195//# sourceMappingURL=Advertiser.d.ts.map
\No newline at end of file