1 | import { EventEmitter } from "events";
|
2 | import { AccessoriesResponse, CharacteristicsReadRequest, CharacteristicsReadResponse, CharacteristicsWriteRequest, CharacteristicsWriteResponse, CharacteristicValue, Nullable, ResourceRequest, VoidCallback } from "../types";
|
3 | import { AccessoryInfo, PairingInformation, PermissionTypes } from "./model/AccessoryInfo";
|
4 | import { HAPConnection, HAPUsername } from "./util/eventedhttp";
|
5 |
|
6 |
|
7 |
|
8 |
|
9 |
|
10 | export declare const enum TLVErrorCode {
|
11 | UNKNOWN = 1,
|
12 | INVALID_REQUEST = 2,
|
13 | AUTHENTICATION = 2,
|
14 | BACKOFF = 3,
|
15 | MAX_PEERS = 4,
|
16 | MAX_TRIES = 5,
|
17 | UNAVAILABLE = 6,
|
18 | BUSY = 7
|
19 | }
|
20 |
|
21 |
|
22 |
|
23 | export declare const enum HAPStatus {
|
24 | |
25 |
|
26 |
|
27 | SUCCESS = 0,
|
28 | |
29 |
|
30 |
|
31 | INSUFFICIENT_PRIVILEGES = -70401,
|
32 | |
33 |
|
34 |
|
35 | SERVICE_COMMUNICATION_FAILURE = -70402,
|
36 | |
37 |
|
38 |
|
39 | RESOURCE_BUSY = -70403,
|
40 | |
41 |
|
42 |
|
43 | READ_ONLY_CHARACTERISTIC = -70404,
|
44 | |
45 |
|
46 |
|
47 | WRITE_ONLY_CHARACTERISTIC = -70405,
|
48 | |
49 |
|
50 |
|
51 | NOTIFICATION_NOT_SUPPORTED = -70406,
|
52 | |
53 |
|
54 |
|
55 | OUT_OF_RESOURCE = -70407,
|
56 | |
57 |
|
58 |
|
59 | OPERATION_TIMED_OUT = -70408,
|
60 | |
61 |
|
62 |
|
63 | RESOURCE_DOES_NOT_EXIST = -70409,
|
64 | |
65 |
|
66 |
|
67 | INVALID_VALUE_IN_REQUEST = -70410,
|
68 | |
69 |
|
70 |
|
71 | INSUFFICIENT_AUTHORIZATION = -70411,
|
72 | |
73 |
|
74 |
|
75 | NOT_ALLOWED_IN_CURRENT_STATE = -70412
|
76 | }
|
77 |
|
78 |
|
79 |
|
80 |
|
81 |
|
82 | export declare function IsKnownHAPStatusError(status: HAPStatus): boolean;
|
83 |
|
84 |
|
85 |
|
86 |
|
87 |
|
88 |
|
89 |
|
90 |
|
91 |
|
92 |
|
93 | export declare const enum HAPHTTPCode {
|
94 | OK = 200,
|
95 | NO_CONTENT = 204,
|
96 | MULTI_STATUS = 207,
|
97 | BAD_REQUEST = 400,
|
98 | NOT_FOUND = 404,
|
99 | UNPROCESSABLE_ENTITY = 422,
|
100 | INTERNAL_SERVER_ERROR = 500,
|
101 | SERVICE_UNAVAILABLE = 503
|
102 | }
|
103 |
|
104 |
|
105 |
|
106 |
|
107 |
|
108 |
|
109 | export declare const enum HAPPairingHTTPCode {
|
110 | OK = 200,
|
111 | BAD_REQUEST = 400,
|
112 | METHOD_NOT_ALLOWED = 405,
|
113 | TOO_MANY_REQUESTS = 429,
|
114 | CONNECTION_AUTHORIZATION_REQUIRED = 470,
|
115 | INTERNAL_SERVER_ERROR = 500
|
116 | }
|
117 |
|
118 |
|
119 |
|
120 | export type IdentifyCallback = VoidCallback;
|
121 |
|
122 |
|
123 |
|
124 | export type HAPHttpError = {
|
125 | httpCode: HAPHTTPCode;
|
126 | status: HAPStatus;
|
127 | };
|
128 |
|
129 |
|
130 |
|
131 | export type PairingsCallback<T = void> = (error: TLVErrorCode | 0, data?: T) => void;
|
132 |
|
133 |
|
134 |
|
135 | export type AddPairingCallback = PairingsCallback;
|
136 |
|
137 |
|
138 |
|
139 | export type RemovePairingCallback = PairingsCallback;
|
140 |
|
141 |
|
142 |
|
143 | export type ListPairingsCallback = PairingsCallback<PairingInformation[]>;
|
144 |
|
145 |
|
146 |
|
147 | export type PairCallback = VoidCallback;
|
148 |
|
149 |
|
150 |
|
151 | export type AccessoriesCallback = (error: HAPHttpError | undefined, result?: AccessoriesResponse) => void;
|
152 |
|
153 |
|
154 |
|
155 | export type ReadCharacteristicsCallback = (error: HAPHttpError | undefined, response?: CharacteristicsReadResponse) => void;
|
156 |
|
157 |
|
158 |
|
159 | export type WriteCharacteristicsCallback = (error: HAPHttpError | undefined, response?: CharacteristicsWriteResponse) => void;
|
160 |
|
161 |
|
162 |
|
163 | export type ResourceRequestCallback = (error: HAPHttpError | undefined, resource?: Buffer) => void;
|
164 |
|
165 |
|
166 |
|
167 | export declare const enum HAPServerEventTypes {
|
168 | |
169 |
|
170 |
|
171 | LISTENING = "listening",
|
172 | |
173 |
|
174 |
|
175 |
|
176 | IDENTIFY = "identify",
|
177 | ADD_PAIRING = "add-pairing",
|
178 | REMOVE_PAIRING = "remove-pairing",
|
179 | LIST_PAIRINGS = "list-pairings",
|
180 | |
181 |
|
182 |
|
183 |
|
184 |
|
185 | PAIR = "pair",
|
186 | |
187 |
|
188 |
|
189 |
|
190 |
|
191 |
|
192 | ACCESSORIES = "accessories",
|
193 | |
194 |
|
195 |
|
196 |
|
197 |
|
198 |
|
199 | GET_CHARACTERISTICS = "get-characteristics",
|
200 | |
201 |
|
202 |
|
203 |
|
204 |
|
205 |
|
206 | SET_CHARACTERISTICS = "set-characteristics",
|
207 | REQUEST_RESOURCE = "request-resource",
|
208 | CONNECTION_CLOSED = "connection-closed"
|
209 | }
|
210 |
|
211 |
|
212 |
|
213 | export declare interface HAPServer {
|
214 | on(event: "listening", listener: (port: number, address: string) => void): this;
|
215 | on(event: "identify", listener: (callback: IdentifyCallback) => void): this;
|
216 | on(event: "add-pairing", listener: (connection: HAPConnection, username: HAPUsername, publicKey: Buffer, permission: PermissionTypes, callback: AddPairingCallback) => void): this;
|
217 | on(event: "remove-pairing", listener: (connection: HAPConnection, username: HAPUsername, callback: RemovePairingCallback) => void): this;
|
218 | on(event: "list-pairings", listener: (connection: HAPConnection, callback: ListPairingsCallback) => void): this;
|
219 | on(event: "pair", listener: (username: HAPUsername, clientLTPK: Buffer, callback: PairCallback) => void): this;
|
220 | on(event: "accessories", listener: (connection: HAPConnection, callback: AccessoriesCallback) => void): this;
|
221 | on(event: "get-characteristics", listener: (connection: HAPConnection, request: CharacteristicsReadRequest, callback: ReadCharacteristicsCallback) => void): this;
|
222 | on(event: "set-characteristics", listener: (connection: HAPConnection, request: CharacteristicsWriteRequest, callback: WriteCharacteristicsCallback) => void): this;
|
223 | on(event: "request-resource", listener: (resource: ResourceRequest, callback: ResourceRequestCallback) => void): this;
|
224 | on(event: "connection-closed", listener: (connection: HAPConnection) => void): this;
|
225 | emit(event: "listening", port: number, address: string): boolean;
|
226 | emit(event: "identify", callback: IdentifyCallback): boolean;
|
227 | emit(event: "add-pairing", connection: HAPConnection, username: HAPUsername, publicKey: Buffer, permission: PermissionTypes, callback: AddPairingCallback): boolean;
|
228 | emit(event: "remove-pairing", connection: HAPConnection, username: HAPUsername, callback: RemovePairingCallback): boolean;
|
229 | emit(event: "list-pairings", connection: HAPConnection, callback: ListPairingsCallback): boolean;
|
230 | emit(event: "pair", username: HAPUsername, clientLTPK: Buffer, callback: PairCallback): boolean;
|
231 | emit(event: "accessories", connection: HAPConnection, callback: AccessoriesCallback): boolean;
|
232 | emit(event: "get-characteristics", connection: HAPConnection, request: CharacteristicsReadRequest, callback: ReadCharacteristicsCallback): boolean;
|
233 | emit(event: "set-characteristics", connection: HAPConnection, request: CharacteristicsWriteRequest, callback: WriteCharacteristicsCallback): boolean;
|
234 | emit(event: "request-resource", resource: ResourceRequest, callback: ResourceRequestCallback): boolean;
|
235 | emit(event: "connection-closed", connection: HAPConnection): boolean;
|
236 | }
|
237 |
|
238 |
|
239 |
|
240 |
|
241 |
|
242 |
|
243 |
|
244 |
|
245 |
|
246 |
|
247 |
|
248 |
|
249 |
|
250 |
|
251 |
|
252 |
|
253 |
|
254 |
|
255 |
|
256 |
|
257 |
|
258 | export declare class HAPServer extends EventEmitter {
|
259 | private accessoryInfo;
|
260 | private httpServer;
|
261 | private unsuccessfulPairAttempts;
|
262 | allowInsecureRequest: boolean;
|
263 | constructor(accessoryInfo: AccessoryInfo);
|
264 | listen(port?: number, host?: string): void;
|
265 | stop(): void;
|
266 | destroy(): void;
|
267 | /**
|
268 | * Send an even notification for given characteristic and changed value to all connected clients.
|
269 | * If `originator` is specified, the given {@link HAPConnection} will be excluded from the broadcast.
|
270 | *
|
271 | * @param aid - The accessory id of the updated characteristic.
|
272 | * @param iid - The instance id of the updated characteristic.
|
273 | * @param value - The newly set value of the characteristic.
|
274 | * @param originator - If specified, the connection will not get an event message.
|
275 | * @param immediateDelivery - The HAP spec requires some characteristics to be delivery immediately.
|
276 | * Namely, for the {@link Characteristic.ButtonEvent} and the {@link Characteristic.ProgrammableSwitchEvent} characteristics.
|
277 | */
|
278 | sendEventNotifications(aid: number, iid: number, value: Nullable<CharacteristicValue>, originator?: HAPConnection, immediateDelivery?: boolean): void;
|
279 | private onListening;
|
280 | private handleRequestOnHAPConnection;
|
281 | private handleConnectionClosed;
|
282 | private getHandler;
|
283 | |
284 |
|
285 |
|
286 | private handleIdentifyRequest;
|
287 | private handlePairSetup;
|
288 | private handlePairSetupM1;
|
289 | private handlePairSetupM3;
|
290 | private handlePairSetupM5;
|
291 | private handlePairSetupM5_2;
|
292 | private handlePairSetupM5_3;
|
293 | private handlePairVerify;
|
294 | private handlePairVerifyM1;
|
295 | private handlePairVerifyM3;
|
296 | private handlePairings;
|
297 | private handleAccessories;
|
298 | private handleCharacteristics;
|
299 | private handlePrepareWrite;
|
300 | private handleResource;
|
301 | }
|
302 |
|
\ | No newline at end of file |