hap-nodejs 0.11.0-beta.11 → 0.11.0-beta.13
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +1 -0
- package/dist/accessories/Light_accessory.js +1 -1
- package/dist/accessories/Light_accessory.js.map +1 -1
- package/dist/internal-types.d.ts +47 -3
- package/dist/internal-types.d.ts.map +1 -1
- package/dist/internal-types.js +52 -1
- package/dist/internal-types.js.map +1 -1
- package/dist/lib/Accessory.d.ts +27 -12
- package/dist/lib/Accessory.d.ts.map +1 -1
- package/dist/lib/Accessory.js +159 -191
- package/dist/lib/Accessory.js.map +1 -1
- package/dist/lib/Characteristic.d.ts +2 -1
- package/dist/lib/Characteristic.d.ts.map +1 -1
- package/dist/lib/Characteristic.js +5 -2
- package/dist/lib/Characteristic.js.map +1 -1
- package/dist/lib/HAPServer.d.ts +43 -4
- package/dist/lib/HAPServer.d.ts.map +1 -1
- package/dist/lib/HAPServer.js +78 -101
- package/dist/lib/HAPServer.js.map +1 -1
- package/dist/lib/Service.d.ts +2 -1
- package/dist/lib/Service.d.ts.map +1 -1
- package/dist/lib/Service.js +4 -0
- package/dist/lib/Service.js.map +1 -1
- package/dist/lib/camera/RTPStreamManagement.d.ts +2 -2
- package/dist/lib/camera/RTPStreamManagement.d.ts.map +1 -1
- package/dist/lib/camera/RTPStreamManagement.js +14 -11
- package/dist/lib/camera/RTPStreamManagement.js.map +1 -1
- package/dist/lib/controller/AdaptiveLightingController.d.ts.map +1 -1
- package/dist/lib/controller/AdaptiveLightingController.js +9 -7
- package/dist/lib/controller/AdaptiveLightingController.js.map +1 -1
- package/dist/lib/controller/CameraController.d.ts.map +1 -1
- package/dist/lib/controller/CameraController.js +1 -0
- package/dist/lib/controller/CameraController.js.map +1 -1
- package/dist/lib/controller/RemoteController.js +2 -2
- package/dist/lib/controller/RemoteController.js.map +1 -1
- package/dist/lib/util/HAPHTTPError.d.ts +16 -0
- package/dist/lib/util/HAPHTTPError.d.ts.map +1 -0
- package/dist/lib/util/HAPHTTPError.js +26 -0
- package/dist/lib/util/HAPHTTPError.js.map +1 -0
- package/dist/lib/util/color-utils.d.ts +1 -1
- package/dist/lib/util/color-utils.js +1 -1
- package/dist/lib/util/eventedhttp.d.ts +18 -4
- package/dist/lib/util/eventedhttp.d.ts.map +1 -1
- package/dist/lib/util/eventedhttp.js +83 -88
- package/dist/lib/util/eventedhttp.js.map +1 -1
- package/dist/lib/util/hapCrypto.d.ts +3 -2
- package/dist/lib/util/hapCrypto.d.ts.map +1 -1
- package/dist/lib/util/hapCrypto.js.map +1 -1
- package/dist/lib/util/promise-utils.d.ts +4 -0
- package/dist/lib/util/promise-utils.d.ts.map +1 -1
- package/dist/lib/util/promise-utils.js +24 -1
- package/dist/lib/util/promise-utils.js.map +1 -1
- package/dist/lib/util/time.js +1 -1
- package/dist/lib/util/tlv.d.ts +63 -4
- package/dist/lib/util/tlv.d.ts.map +1 -1
- package/dist/lib/util/tlv.js +61 -16
- package/dist/lib/util/tlv.js.map +1 -1
- package/dist/lib/util/tlvError.d.ts +14 -0
- package/dist/lib/util/tlvError.d.ts.map +1 -0
- package/dist/lib/util/tlvError.js +24 -0
- package/dist/lib/util/tlvError.js.map +1 -0
- package/dist/types.d.ts +4 -0
- package/dist/types.d.ts.map +1 -1
- package/package.json +6 -4
package/dist/lib/HAPServer.d.ts
CHANGED
|
@@ -18,18 +18,57 @@ export declare const enum TLVErrorCode {
|
|
|
18
18
|
BUSY = 7
|
|
19
19
|
}
|
|
20
20
|
export declare const enum HAPStatus {
|
|
21
|
+
/**
|
|
22
|
+
* Success of the request.
|
|
23
|
+
*/
|
|
21
24
|
SUCCESS = 0,
|
|
25
|
+
/**
|
|
26
|
+
* The request was rejected due to insufficient privileges.
|
|
27
|
+
*/
|
|
22
28
|
INSUFFICIENT_PRIVILEGES = -70401,
|
|
29
|
+
/**
|
|
30
|
+
* Operation failed due to some communication failure with the characteristic.
|
|
31
|
+
*/
|
|
23
32
|
SERVICE_COMMUNICATION_FAILURE = -70402,
|
|
33
|
+
/**
|
|
34
|
+
* The resource is busy. Try again.
|
|
35
|
+
*/
|
|
24
36
|
RESOURCE_BUSY = -70403,
|
|
37
|
+
/**
|
|
38
|
+
* Cannot write a read-only characteristic ({@see Perms.PAIRED_WRITE} not defined).
|
|
39
|
+
*/
|
|
25
40
|
READ_ONLY_CHARACTERISTIC = -70404,
|
|
41
|
+
/**
|
|
42
|
+
* Cannot read from a write-only characteristic ({@link Perms.PAIRED_READ} not defined).
|
|
43
|
+
*/
|
|
26
44
|
WRITE_ONLY_CHARACTERISTIC = -70405,
|
|
45
|
+
/**
|
|
46
|
+
* Event notifications are not supported for the requested characteristic ({@link Perms.NOTIFY} not defined).
|
|
47
|
+
*/
|
|
27
48
|
NOTIFICATION_NOT_SUPPORTED = -70406,
|
|
49
|
+
/**
|
|
50
|
+
* The device is out of resources to process the request.
|
|
51
|
+
*/
|
|
28
52
|
OUT_OF_RESOURCE = -70407,
|
|
53
|
+
/**
|
|
54
|
+
* The operation timed out.
|
|
55
|
+
*/
|
|
29
56
|
OPERATION_TIMED_OUT = -70408,
|
|
57
|
+
/**
|
|
58
|
+
* The given resource does not exist.
|
|
59
|
+
*/
|
|
30
60
|
RESOURCE_DOES_NOT_EXIST = -70409,
|
|
61
|
+
/**
|
|
62
|
+
* Received an invalid value in the given request for the given characteristic.
|
|
63
|
+
*/
|
|
31
64
|
INVALID_VALUE_IN_REQUEST = -70410,
|
|
65
|
+
/**
|
|
66
|
+
* Insufficient authorization.
|
|
67
|
+
*/
|
|
32
68
|
INSUFFICIENT_AUTHORIZATION = -70411,
|
|
69
|
+
/**
|
|
70
|
+
* Operation not allowed in the current state.
|
|
71
|
+
*/
|
|
33
72
|
NOT_ALLOWED_IN_CURRENT_STATE = -70412
|
|
34
73
|
}
|
|
35
74
|
/**
|
|
@@ -184,15 +223,15 @@ export declare class HAPServer extends EventEmitter {
|
|
|
184
223
|
stop(): void;
|
|
185
224
|
destroy(): void;
|
|
186
225
|
/**
|
|
187
|
-
* Send
|
|
226
|
+
* Send an even notification for given characteristic and changed value to all connected clients.
|
|
188
227
|
* If {@param originator} is specified, the given {@link HAPConnection} will be excluded from the broadcast.
|
|
189
228
|
*
|
|
190
229
|
* @param aid - The accessory id of the updated characteristic.
|
|
191
230
|
* @param iid - The instance id of the updated characteristic.
|
|
192
231
|
* @param value - The newly set value of the characteristic.
|
|
193
|
-
* @param originator - If specified, the connection will not get
|
|
232
|
+
* @param originator - If specified, the connection will not get an event message.
|
|
194
233
|
* @param immediateDelivery - The HAP spec requires some characteristics to be delivery immediately.
|
|
195
|
-
* Namely for the {@link ButtonEvent} and the {@link ProgrammableSwitchEvent} characteristics.
|
|
234
|
+
* Namely, for the {@link ButtonEvent} and the {@link ProgrammableSwitchEvent} characteristics.
|
|
196
235
|
*/
|
|
197
236
|
sendEventNotifications(aid: number, iid: number, value: Nullable<CharacteristicValue>, originator?: HAPConnection, immediateDelivery?: boolean): void;
|
|
198
237
|
private onListening;
|
|
@@ -211,7 +250,7 @@ export declare class HAPServer extends EventEmitter {
|
|
|
211
250
|
private handlePairSetupM5_3;
|
|
212
251
|
private handlePairVerify;
|
|
213
252
|
private handlePairVerifyM1;
|
|
214
|
-
private
|
|
253
|
+
private handlePairVerifyM3;
|
|
215
254
|
private handlePairings;
|
|
216
255
|
private handleAccessories;
|
|
217
256
|
private handleCharacteristics;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"HAPServer.d.ts","sourceRoot":"","sources":["../../src/lib/HAPServer.ts"],"names":[],"mappings":";AAEA,OAAO,EAAE,YAAY,EAAE,MAAM,QAAQ,CAAC;AAKtC,OAAO,EACL,mBAAmB,EAEnB,0BAA0B,EAC1B,2BAA2B,EAC3B,2BAA2B,EAC3B,4BAA4B,
|
|
1
|
+
{"version":3,"file":"HAPServer.d.ts","sourceRoot":"","sources":["../../src/lib/HAPServer.ts"],"names":[],"mappings":";AAEA,OAAO,EAAE,YAAY,EAA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;;;;;OAUG;IACI,sBAAsB,CAAC,GAAG,EAAE,MAAM,EAAE,GAAG,EAAE,MAAM,EAAE,KAAK,EAAE,QAAQ,CAAC,mBAAmB,CAAC,EAAE,UAAU,CAAC,EAAE,aAAa,EAAE,iBAAiB,CAAC,EAAE,OAAO,GAAG,IAAI;IAQ5J,OAAO,CAAC,WAAW;IAKnB,OAAO,CAAC,4BAA4B;IA2BpC,OAAO,CAAC,sBAAsB;IAI9B,OAAO,CAAC,UAAU;IAuBlB;;OAEG;IACH,OAAO,CAAC,qBAAqB;IAqB7B,OAAO,CAAC,eAAe;IA8BvB,OAAO,CAAC,iBAAiB;IAsBzB,OAAO,CAAC,iBAAiB;IAyBzB,OAAO,CAAC,iBAAiB;IAiCzB,OAAO,CAAC,mBAAmB;IA0B3B,OAAO,CAAC,mBAAmB;IAsC3B,OAAO,CAAC,gBAAgB;IAgBxB,OAAO,CAAC,kBAAkB;IAgC1B,OAAO,CAAC,kBAAkB;IA6D1B,OAAO,CAAC,cAAc;IA+EtB,OAAO,CAAC,iBAAiB;IAkBzB,OAAO,CAAC,qBAAqB;IA2H7B,OAAO,CAAC,kBAAkB;IA2C1B,OAAO,CAAC,cAAc;CAgCvB"}
|
package/dist/lib/HAPServer.js
CHANGED
|
@@ -14,51 +14,6 @@ var hapCrypto = (0, tslib_1.__importStar)(require("./util/hapCrypto"));
|
|
|
14
14
|
var once_1 = require("./util/once");
|
|
15
15
|
var tlv = (0, tslib_1.__importStar)(require("./util/tlv"));
|
|
16
16
|
var debug = (0, debug_1.default)("HAP-NodeJS:HAPServer");
|
|
17
|
-
var TLVValues;
|
|
18
|
-
(function (TLVValues) {
|
|
19
|
-
// noinspection JSUnusedGlobalSymbols
|
|
20
|
-
TLVValues[TLVValues["REQUEST_TYPE"] = 0] = "REQUEST_TYPE";
|
|
21
|
-
TLVValues[TLVValues["METHOD"] = 0] = "METHOD";
|
|
22
|
-
TLVValues[TLVValues["USERNAME"] = 1] = "USERNAME";
|
|
23
|
-
TLVValues[TLVValues["IDENTIFIER"] = 1] = "IDENTIFIER";
|
|
24
|
-
TLVValues[TLVValues["SALT"] = 2] = "SALT";
|
|
25
|
-
TLVValues[TLVValues["PUBLIC_KEY"] = 3] = "PUBLIC_KEY";
|
|
26
|
-
TLVValues[TLVValues["PASSWORD_PROOF"] = 4] = "PASSWORD_PROOF";
|
|
27
|
-
TLVValues[TLVValues["ENCRYPTED_DATA"] = 5] = "ENCRYPTED_DATA";
|
|
28
|
-
TLVValues[TLVValues["SEQUENCE_NUM"] = 6] = "SEQUENCE_NUM";
|
|
29
|
-
TLVValues[TLVValues["STATE"] = 6] = "STATE";
|
|
30
|
-
TLVValues[TLVValues["ERROR_CODE"] = 7] = "ERROR_CODE";
|
|
31
|
-
TLVValues[TLVValues["RETRY_DELAY"] = 8] = "RETRY_DELAY";
|
|
32
|
-
TLVValues[TLVValues["CERTIFICATE"] = 9] = "CERTIFICATE";
|
|
33
|
-
TLVValues[TLVValues["PROOF"] = 10] = "PROOF";
|
|
34
|
-
TLVValues[TLVValues["SIGNATURE"] = 10] = "SIGNATURE";
|
|
35
|
-
TLVValues[TLVValues["PERMISSIONS"] = 11] = "PERMISSIONS";
|
|
36
|
-
TLVValues[TLVValues["FRAGMENT_DATA"] = 12] = "FRAGMENT_DATA";
|
|
37
|
-
TLVValues[TLVValues["FRAGMENT_LAST"] = 13] = "FRAGMENT_LAST";
|
|
38
|
-
TLVValues[TLVValues["SEPARATOR"] = 255] = "SEPARATOR"; // Zero-length TLV that separates different TLVs in a list.
|
|
39
|
-
})(TLVValues || (TLVValues = {}));
|
|
40
|
-
var PairMethods;
|
|
41
|
-
(function (PairMethods) {
|
|
42
|
-
// noinspection JSUnusedGlobalSymbols
|
|
43
|
-
PairMethods[PairMethods["PAIR_SETUP"] = 0] = "PAIR_SETUP";
|
|
44
|
-
PairMethods[PairMethods["PAIR_SETUP_WITH_AUTH"] = 1] = "PAIR_SETUP_WITH_AUTH";
|
|
45
|
-
PairMethods[PairMethods["PAIR_VERIFY"] = 2] = "PAIR_VERIFY";
|
|
46
|
-
PairMethods[PairMethods["ADD_PAIRING"] = 3] = "ADD_PAIRING";
|
|
47
|
-
PairMethods[PairMethods["REMOVE_PAIRING"] = 4] = "REMOVE_PAIRING";
|
|
48
|
-
PairMethods[PairMethods["LIST_PAIRINGS"] = 5] = "LIST_PAIRINGS";
|
|
49
|
-
})(PairMethods || (PairMethods = {}));
|
|
50
|
-
/**
|
|
51
|
-
* Pairing states (pair-setup or pair-verify). Encoded in {@link TLVValues.SEQUENCE_NUM}.
|
|
52
|
-
*/
|
|
53
|
-
var PairingStates;
|
|
54
|
-
(function (PairingStates) {
|
|
55
|
-
PairingStates[PairingStates["M1"] = 1] = "M1";
|
|
56
|
-
PairingStates[PairingStates["M2"] = 2] = "M2";
|
|
57
|
-
PairingStates[PairingStates["M3"] = 3] = "M3";
|
|
58
|
-
PairingStates[PairingStates["M4"] = 4] = "M4";
|
|
59
|
-
PairingStates[PairingStates["M5"] = 5] = "M5";
|
|
60
|
-
PairingStates[PairingStates["M6"] = 6] = "M6";
|
|
61
|
-
})(PairingStates || (PairingStates = {}));
|
|
62
17
|
/**
|
|
63
18
|
* TLV error codes for the {@link TLVValues.ERROR_CODE} field.
|
|
64
19
|
*/
|
|
@@ -77,18 +32,57 @@ var TLVErrorCode;
|
|
|
77
32
|
var HAPStatus;
|
|
78
33
|
(function (HAPStatus) {
|
|
79
34
|
// noinspection JSUnusedGlobalSymbols
|
|
35
|
+
/**
|
|
36
|
+
* Success of the request.
|
|
37
|
+
*/
|
|
80
38
|
HAPStatus[HAPStatus["SUCCESS"] = 0] = "SUCCESS";
|
|
39
|
+
/**
|
|
40
|
+
* The request was rejected due to insufficient privileges.
|
|
41
|
+
*/
|
|
81
42
|
HAPStatus[HAPStatus["INSUFFICIENT_PRIVILEGES"] = -70401] = "INSUFFICIENT_PRIVILEGES";
|
|
43
|
+
/**
|
|
44
|
+
* Operation failed due to some communication failure with the characteristic.
|
|
45
|
+
*/
|
|
82
46
|
HAPStatus[HAPStatus["SERVICE_COMMUNICATION_FAILURE"] = -70402] = "SERVICE_COMMUNICATION_FAILURE";
|
|
47
|
+
/**
|
|
48
|
+
* The resource is busy. Try again.
|
|
49
|
+
*/
|
|
83
50
|
HAPStatus[HAPStatus["RESOURCE_BUSY"] = -70403] = "RESOURCE_BUSY";
|
|
51
|
+
/**
|
|
52
|
+
* Cannot write a read-only characteristic ({@see Perms.PAIRED_WRITE} not defined).
|
|
53
|
+
*/
|
|
84
54
|
HAPStatus[HAPStatus["READ_ONLY_CHARACTERISTIC"] = -70404] = "READ_ONLY_CHARACTERISTIC";
|
|
55
|
+
/**
|
|
56
|
+
* Cannot read from a write-only characteristic ({@link Perms.PAIRED_READ} not defined).
|
|
57
|
+
*/
|
|
85
58
|
HAPStatus[HAPStatus["WRITE_ONLY_CHARACTERISTIC"] = -70405] = "WRITE_ONLY_CHARACTERISTIC";
|
|
59
|
+
/**
|
|
60
|
+
* Event notifications are not supported for the requested characteristic ({@link Perms.NOTIFY} not defined).
|
|
61
|
+
*/
|
|
86
62
|
HAPStatus[HAPStatus["NOTIFICATION_NOT_SUPPORTED"] = -70406] = "NOTIFICATION_NOT_SUPPORTED";
|
|
63
|
+
/**
|
|
64
|
+
* The device is out of resources to process the request.
|
|
65
|
+
*/
|
|
87
66
|
HAPStatus[HAPStatus["OUT_OF_RESOURCE"] = -70407] = "OUT_OF_RESOURCE";
|
|
67
|
+
/**
|
|
68
|
+
* The operation timed out.
|
|
69
|
+
*/
|
|
88
70
|
HAPStatus[HAPStatus["OPERATION_TIMED_OUT"] = -70408] = "OPERATION_TIMED_OUT";
|
|
71
|
+
/**
|
|
72
|
+
* The given resource does not exist.
|
|
73
|
+
*/
|
|
89
74
|
HAPStatus[HAPStatus["RESOURCE_DOES_NOT_EXIST"] = -70409] = "RESOURCE_DOES_NOT_EXIST";
|
|
75
|
+
/**
|
|
76
|
+
* Received an invalid value in the given request for the given characteristic.
|
|
77
|
+
*/
|
|
90
78
|
HAPStatus[HAPStatus["INVALID_VALUE_IN_REQUEST"] = -70410] = "INVALID_VALUE_IN_REQUEST";
|
|
79
|
+
/**
|
|
80
|
+
* Insufficient authorization.
|
|
81
|
+
*/
|
|
91
82
|
HAPStatus[HAPStatus["INSUFFICIENT_AUTHORIZATION"] = -70411] = "INSUFFICIENT_AUTHORIZATION";
|
|
83
|
+
/**
|
|
84
|
+
* Operation not allowed in the current state.
|
|
85
|
+
*/
|
|
92
86
|
HAPStatus[HAPStatus["NOT_ALLOWED_IN_CURRENT_STATE"] = -70412] = "NOT_ALLOWED_IN_CURRENT_STATE";
|
|
93
87
|
// when adding new status codes, remember to update bounds in IsKnownHAPStatusError below
|
|
94
88
|
})(HAPStatus = exports.HAPStatus || (exports.HAPStatus = {}));
|
|
@@ -231,7 +225,7 @@ var HAPServer = /** @class */ (function (_super) {
|
|
|
231
225
|
HAPServer.prototype.listen = function (port, host) {
|
|
232
226
|
if (port === void 0) { port = 0; }
|
|
233
227
|
if (host === "::") {
|
|
234
|
-
// this will
|
|
228
|
+
// this will work around "EAFNOSUPPORT: address family not supported" errors
|
|
235
229
|
// on systems where IPv6 is not supported/enabled, we just use the node default then by supplying undefined
|
|
236
230
|
host = undefined;
|
|
237
231
|
}
|
|
@@ -245,15 +239,15 @@ var HAPServer = /** @class */ (function (_super) {
|
|
|
245
239
|
this.removeAllListeners();
|
|
246
240
|
};
|
|
247
241
|
/**
|
|
248
|
-
* Send
|
|
242
|
+
* Send an even notification for given characteristic and changed value to all connected clients.
|
|
249
243
|
* If {@param originator} is specified, the given {@link HAPConnection} will be excluded from the broadcast.
|
|
250
244
|
*
|
|
251
245
|
* @param aid - The accessory id of the updated characteristic.
|
|
252
246
|
* @param iid - The instance id of the updated characteristic.
|
|
253
247
|
* @param value - The newly set value of the characteristic.
|
|
254
|
-
* @param originator - If specified, the connection will not get
|
|
248
|
+
* @param originator - If specified, the connection will not get an event message.
|
|
255
249
|
* @param immediateDelivery - The HAP spec requires some characteristics to be delivery immediately.
|
|
256
|
-
* Namely for the {@link ButtonEvent} and the {@link ProgrammableSwitchEvent} characteristics.
|
|
250
|
+
* Namely, for the {@link ButtonEvent} and the {@link ProgrammableSwitchEvent} characteristics.
|
|
257
251
|
*/
|
|
258
252
|
HAPServer.prototype.sendEventNotifications = function (aid, iid, value, originator, immediateDelivery) {
|
|
259
253
|
try {
|
|
@@ -274,10 +268,10 @@ var HAPServer = /** @class */ (function (_super) {
|
|
|
274
268
|
request.on("data", function (data) { return buffers.push(data); });
|
|
275
269
|
request.on("end", function () {
|
|
276
270
|
var url = new url_1.URL(request.url, "http://hap-nodejs.local"); // parse the url (query strings etc)
|
|
277
|
-
var handler = _this.getHandler(url);
|
|
271
|
+
var handler = _this.getHandler(url);
|
|
278
272
|
if (!handler) {
|
|
279
273
|
debug("[%s] WARNING: Handler for %s not implemented", _this.accessoryInfo.username, request.url);
|
|
280
|
-
response.writeHead(404 /* NOT_FOUND */, { "Content-Type": "application/hap+json" });
|
|
274
|
+
response.writeHead(404 /* NOT_FOUND */, { "Content-Type": "application/hap+json" /* HAP_JSON */ });
|
|
281
275
|
response.end(JSON.stringify({ status: -70409 /* RESOURCE_DOES_NOT_EXIST */ }));
|
|
282
276
|
}
|
|
283
277
|
else {
|
|
@@ -287,7 +281,7 @@ var HAPServer = /** @class */ (function (_super) {
|
|
|
287
281
|
}
|
|
288
282
|
catch (error) {
|
|
289
283
|
debug("[%s] Error executing route handler: %s", _this.accessoryInfo.username, error.stack);
|
|
290
|
-
response.writeHead(500 /* INTERNAL_SERVER_ERROR */, { "Content-Type": "application/hap+json" });
|
|
284
|
+
response.writeHead(500 /* INTERNAL_SERVER_ERROR */, { "Content-Type": "application/hap+json" /* HAP_JSON */ });
|
|
291
285
|
response.end(JSON.stringify({ status: -70403 /* RESOURCE_BUSY */ })); // resource busy try again, does somehow fit?
|
|
292
286
|
}
|
|
293
287
|
}
|
|
@@ -324,8 +318,8 @@ var HAPServer = /** @class */ (function (_super) {
|
|
|
324
318
|
HAPServer.prototype.handleIdentifyRequest = function (connection, url, request, data, response) {
|
|
325
319
|
var _this = this;
|
|
326
320
|
// POST body is empty
|
|
327
|
-
if (
|
|
328
|
-
response.writeHead(400 /* BAD_REQUEST */, { "Content-Type": "application/hap+json" });
|
|
321
|
+
if (this.accessoryInfo.paired() && !this.allowInsecureRequest) {
|
|
322
|
+
response.writeHead(400 /* BAD_REQUEST */, { "Content-Type": "application/hap+json" /* HAP_JSON */ });
|
|
329
323
|
response.end(JSON.stringify({ status: -70401 /* INSUFFICIENT_PRIVILEGES */ }));
|
|
330
324
|
return;
|
|
331
325
|
}
|
|
@@ -337,7 +331,7 @@ var HAPServer = /** @class */ (function (_super) {
|
|
|
337
331
|
}
|
|
338
332
|
else {
|
|
339
333
|
debug("[%s] Identification error: %s", _this.accessoryInfo.username, err.message);
|
|
340
|
-
response.writeHead(500 /* INTERNAL_SERVER_ERROR */, { "Content-Type": "application/hap+json" });
|
|
334
|
+
response.writeHead(500 /* INTERNAL_SERVER_ERROR */, { "Content-Type": "application/hap+json" /* HAP_JSON */ });
|
|
341
335
|
response.end(JSON.stringify({ status: -70403 /* RESOURCE_BUSY */ }));
|
|
342
336
|
}
|
|
343
337
|
}));
|
|
@@ -504,7 +498,7 @@ var HAPServer = /** @class */ (function (_super) {
|
|
|
504
498
|
this.handlePairVerifyM1(connection, request, response, tlvData);
|
|
505
499
|
}
|
|
506
500
|
else if (sequence === 3 /* M3 */ && connection._pairVerifyState === 2 /* M2 */) {
|
|
507
|
-
this.
|
|
501
|
+
this.handlePairVerifyM3(connection, request, response, tlvData);
|
|
508
502
|
}
|
|
509
503
|
else {
|
|
510
504
|
// Invalid state/sequence number
|
|
@@ -536,7 +530,7 @@ var HAPServer = /** @class */ (function (_super) {
|
|
|
536
530
|
response.end(tlv.encode(6 /* SEQUENCE_NUM */, 2 /* M2 */, 5 /* ENCRYPTED_DATA */, Buffer.concat([encrypted.ciphertext, encrypted.authTag]), 3 /* PUBLIC_KEY */, publicKey));
|
|
537
531
|
connection._pairVerifyState = 2 /* M2 */;
|
|
538
532
|
};
|
|
539
|
-
HAPServer.prototype.
|
|
533
|
+
HAPServer.prototype.handlePairVerifyM3 = function (connection, request, response, objects) {
|
|
540
534
|
debug("[%s] Pair verify step 2/2", this.accessoryInfo.username);
|
|
541
535
|
var encryptedData = objects[5 /* ENCRYPTED_DATA */];
|
|
542
536
|
var messageData = Buffer.alloc(encryptedData.length - 16);
|
|
@@ -562,7 +556,7 @@ var HAPServer = /** @class */ (function (_super) {
|
|
|
562
556
|
var material = Buffer.concat([enc.clientPublicKey, clientUsername, enc.publicKey]);
|
|
563
557
|
// since we're paired, we should have the public key stored for this client
|
|
564
558
|
var clientPublicKey = this.accessoryInfo.getClientPublicKey(clientUsername.toString());
|
|
565
|
-
// if we're not actually paired, then there's nothing to verify - this client thinks it's paired with us but we
|
|
559
|
+
// if we're not actually paired, then there's nothing to verify - this client thinks it's paired with us, but we
|
|
566
560
|
// disagree. Respond with invalid request (seems to match HomeKit Accessory Simulator behavior)
|
|
567
561
|
if (!clientPublicKey) {
|
|
568
562
|
debug("[%s] Client %s attempting to verify, but we are not paired; rejecting client", this.accessoryInfo.username, clientUsername);
|
|
@@ -597,7 +591,7 @@ var HAPServer = /** @class */ (function (_super) {
|
|
|
597
591
|
var _this = this;
|
|
598
592
|
// Only accept /pairing request if there is a secure session
|
|
599
593
|
if (!this.allowInsecureRequest && !connection.isAuthenticated()) {
|
|
600
|
-
response.writeHead(470 /* CONNECTION_AUTHORIZATION_REQUIRED */, { "Content-Type": "application/hap+json" });
|
|
594
|
+
response.writeHead(470 /* CONNECTION_AUTHORIZATION_REQUIRED */, { "Content-Type": "application/hap+json" /* HAP_JSON */ });
|
|
601
595
|
response.end(JSON.stringify({ status: -70401 /* INSUFFICIENT_PRIVILEGES */ }));
|
|
602
596
|
return;
|
|
603
597
|
}
|
|
@@ -654,7 +648,7 @@ var HAPServer = /** @class */ (function (_super) {
|
|
|
654
648
|
tlvList.push(1 /* IDENTIFIER */, value.username, 3 /* PUBLIC_KEY */, value.publicKey, 11 /* PERMISSIONS */, value.permission);
|
|
655
649
|
});
|
|
656
650
|
var list = tlv.encode.apply(tlv, (0, tslib_1.__spreadArray)([6 /* STATE */, 2 /* M2 */], (0, tslib_1.__read)(tlvList), false));
|
|
657
|
-
response.writeHead(200 /* OK */, { "Content-Type": "application/pairing+tlv8" });
|
|
651
|
+
response.writeHead(200 /* OK */, { "Content-Type": "application/pairing+tlv8" /* PAIRING_TLV8 */ });
|
|
658
652
|
response.end(list);
|
|
659
653
|
debug("[%s] Pairings: successfully executed LIST_PAIRINGS", _this.accessoryInfo.username);
|
|
660
654
|
}));
|
|
@@ -662,18 +656,18 @@ var HAPServer = /** @class */ (function (_super) {
|
|
|
662
656
|
};
|
|
663
657
|
HAPServer.prototype.handleAccessories = function (connection, url, request, data, response) {
|
|
664
658
|
if (!this.allowInsecureRequest && !connection.isAuthenticated()) {
|
|
665
|
-
response.writeHead(470 /* CONNECTION_AUTHORIZATION_REQUIRED */, { "Content-Type": "application/hap+json" });
|
|
659
|
+
response.writeHead(470 /* CONNECTION_AUTHORIZATION_REQUIRED */, { "Content-Type": "application/hap+json" /* HAP_JSON */ });
|
|
666
660
|
response.end(JSON.stringify({ status: -70401 /* INSUFFICIENT_PRIVILEGES */ }));
|
|
667
661
|
return;
|
|
668
662
|
}
|
|
669
663
|
// call out to listeners to retrieve the latest accessories JSON
|
|
670
664
|
this.emit("accessories" /* ACCESSORIES */, connection, (0, once_1.once)(function (error, result) {
|
|
671
665
|
if (error) {
|
|
672
|
-
response.writeHead(error.httpCode, { "Content-Type": "application/hap+json" });
|
|
666
|
+
response.writeHead(error.httpCode, { "Content-Type": "application/hap+json" /* HAP_JSON */ });
|
|
673
667
|
response.end(JSON.stringify({ status: error.status }));
|
|
674
668
|
}
|
|
675
669
|
else {
|
|
676
|
-
response.writeHead(200 /* OK */, { "Content-Type": "application/hap+json" });
|
|
670
|
+
response.writeHead(200 /* OK */, { "Content-Type": "application/hap+json" /* HAP_JSON */ });
|
|
677
671
|
response.end(JSON.stringify(result));
|
|
678
672
|
}
|
|
679
673
|
}));
|
|
@@ -681,7 +675,7 @@ var HAPServer = /** @class */ (function (_super) {
|
|
|
681
675
|
HAPServer.prototype.handleCharacteristics = function (connection, url, request, data, response) {
|
|
682
676
|
var e_1, _a;
|
|
683
677
|
if (!this.allowInsecureRequest && !connection.isAuthenticated()) {
|
|
684
|
-
response.writeHead(470 /* CONNECTION_AUTHORIZATION_REQUIRED */, { "Content-Type": "application/hap+json" });
|
|
678
|
+
response.writeHead(470 /* CONNECTION_AUTHORIZATION_REQUIRED */, { "Content-Type": "application/hap+json" /* HAP_JSON */ });
|
|
685
679
|
response.end(JSON.stringify({ status: -70401 /* INSUFFICIENT_PRIVILEGES */ }));
|
|
686
680
|
return;
|
|
687
681
|
}
|
|
@@ -689,7 +683,7 @@ var HAPServer = /** @class */ (function (_super) {
|
|
|
689
683
|
var searchParams = url.searchParams;
|
|
690
684
|
var idParam = searchParams.get("id");
|
|
691
685
|
if (!idParam) {
|
|
692
|
-
response.writeHead(400 /* BAD_REQUEST */, { "Content-Type": "application/hap+json" });
|
|
686
|
+
response.writeHead(400 /* BAD_REQUEST */, { "Content-Type": "application/hap+json" /* HAP_JSON */ });
|
|
693
687
|
response.end(JSON.stringify({ status: -70410 /* INVALID_VALUE_IN_REQUEST */ }));
|
|
694
688
|
return;
|
|
695
689
|
}
|
|
@@ -700,7 +694,7 @@ var HAPServer = /** @class */ (function (_super) {
|
|
|
700
694
|
var split = entry.split("."); // ["1","9"]
|
|
701
695
|
ids.push({
|
|
702
696
|
aid: parseInt(split[0], 10),
|
|
703
|
-
iid: parseInt(split[1], 10), // (characteristic) instance
|
|
697
|
+
iid: parseInt(split[1], 10), // (characteristic) instance id
|
|
704
698
|
});
|
|
705
699
|
}
|
|
706
700
|
}
|
|
@@ -721,11 +715,10 @@ var HAPServer = /** @class */ (function (_super) {
|
|
|
721
715
|
this.emit("get-characteristics" /* GET_CHARACTERISTICS */, connection, readRequest, (0, once_1.once)(function (error, readResponse) {
|
|
722
716
|
var e_2, _a, e_3, _b;
|
|
723
717
|
if (error) {
|
|
724
|
-
response.writeHead(error.httpCode, { "Content-Type": "application/hap+json" });
|
|
718
|
+
response.writeHead(error.httpCode, { "Content-Type": "application/hap+json" /* HAP_JSON */ });
|
|
725
719
|
response.end(JSON.stringify({ status: error.status }));
|
|
726
720
|
return;
|
|
727
721
|
}
|
|
728
|
-
// typescript can't type that this exists if error doesnt
|
|
729
722
|
var characteristics = readResponse.characteristics;
|
|
730
723
|
var errorOccurred = false; // determine if we send a 207 Multi-Status
|
|
731
724
|
try {
|
|
@@ -762,32 +755,31 @@ var HAPServer = /** @class */ (function (_super) {
|
|
|
762
755
|
}
|
|
763
756
|
}
|
|
764
757
|
// 207 "multi-status" is returned when an error occurs reading a characteristic. otherwise 200 is returned
|
|
765
|
-
response.writeHead(errorOccurred ? 207 /* MULTI_STATUS */ : 200 /* OK */, { "Content-Type": "application/hap+json" });
|
|
758
|
+
response.writeHead(errorOccurred ? 207 /* MULTI_STATUS */ : 200 /* OK */, { "Content-Type": "application/hap+json" /* HAP_JSON */ });
|
|
766
759
|
response.end(JSON.stringify({ characteristics: characteristics }));
|
|
767
760
|
}));
|
|
768
761
|
}
|
|
769
762
|
else if (request.method === "PUT") {
|
|
770
763
|
if (!connection.isAuthenticated()) {
|
|
771
764
|
if (!request.headers || (request.headers && request.headers.authorization !== this.accessoryInfo.pincode)) {
|
|
772
|
-
response.writeHead(470 /* CONNECTION_AUTHORIZATION_REQUIRED */, { "Content-Type": "application/hap+json" });
|
|
765
|
+
response.writeHead(470 /* CONNECTION_AUTHORIZATION_REQUIRED */, { "Content-Type": "application/hap+json" /* HAP_JSON */ });
|
|
773
766
|
response.end(JSON.stringify({ status: -70401 /* INSUFFICIENT_PRIVILEGES */ }));
|
|
774
767
|
return;
|
|
775
768
|
}
|
|
776
769
|
}
|
|
777
770
|
if (data.length === 0) {
|
|
778
|
-
response.writeHead(400
|
|
771
|
+
response.writeHead(400 /* BAD_REQUEST */, { "Content-Type": "application/hap+json" /* HAP_JSON */ });
|
|
779
772
|
response.end(JSON.stringify({ status: -70410 /* INVALID_VALUE_IN_REQUEST */ }));
|
|
780
773
|
return;
|
|
781
774
|
}
|
|
782
775
|
var writeRequest = JSON.parse(data.toString("utf8"));
|
|
783
776
|
this.emit("set-characteristics" /* SET_CHARACTERISTICS */, connection, writeRequest, (0, once_1.once)(function (error, writeResponse) {
|
|
784
|
-
var e_4, _a
|
|
777
|
+
var e_4, _a;
|
|
785
778
|
if (error) {
|
|
786
|
-
response.writeHead(error.httpCode, { "Content-Type": "application/hap+json" });
|
|
779
|
+
response.writeHead(error.httpCode, { "Content-Type": "application/hap+json" /* HAP_JSON */ });
|
|
787
780
|
response.end(JSON.stringify({ status: error.status }));
|
|
788
781
|
return;
|
|
789
782
|
}
|
|
790
|
-
// typescript can't type that this exists if error doesnt
|
|
791
783
|
var characteristics = writeResponse.characteristics;
|
|
792
784
|
var multiStatus = false;
|
|
793
785
|
try {
|
|
@@ -808,23 +800,8 @@ var HAPServer = /** @class */ (function (_super) {
|
|
|
808
800
|
finally { if (e_4) throw e_4.error; }
|
|
809
801
|
}
|
|
810
802
|
if (multiStatus) {
|
|
811
|
-
try {
|
|
812
|
-
for (var characteristics_4 = (0, tslib_1.__values)(characteristics), characteristics_4_1 = characteristics_4.next(); !characteristics_4_1.done; characteristics_4_1 = characteristics_4.next()) { // on a 207 Multi-Status EVERY characteristic MUST include a status property
|
|
813
|
-
var data_4 = characteristics_4_1.value;
|
|
814
|
-
if (data_4.status === undefined) {
|
|
815
|
-
data_4.status = 0 /* SUCCESS */;
|
|
816
|
-
}
|
|
817
|
-
}
|
|
818
|
-
}
|
|
819
|
-
catch (e_5_1) { e_5 = { error: e_5_1 }; }
|
|
820
|
-
finally {
|
|
821
|
-
try {
|
|
822
|
-
if (characteristics_4_1 && !characteristics_4_1.done && (_b = characteristics_4.return)) _b.call(characteristics_4);
|
|
823
|
-
}
|
|
824
|
-
finally { if (e_5) throw e_5.error; }
|
|
825
|
-
}
|
|
826
803
|
// 207 is "multi-status" since HomeKit may be setting multiple things and any one can fail independently
|
|
827
|
-
response.writeHead(207 /* MULTI_STATUS */, { "Content-Type": "application/hap+json" });
|
|
804
|
+
response.writeHead(207 /* MULTI_STATUS */, { "Content-Type": "application/hap+json" /* HAP_JSON */ });
|
|
828
805
|
response.end(JSON.stringify({ characteristics: characteristics }));
|
|
829
806
|
}
|
|
830
807
|
else {
|
|
@@ -835,20 +812,20 @@ var HAPServer = /** @class */ (function (_super) {
|
|
|
835
812
|
}));
|
|
836
813
|
}
|
|
837
814
|
else {
|
|
838
|
-
response.writeHead(400 /* BAD_REQUEST */, { "Content-Type": "application/hap+json" }); // method not allowed
|
|
815
|
+
response.writeHead(400 /* BAD_REQUEST */, { "Content-Type": "application/hap+json" /* HAP_JSON */ }); // method not allowed
|
|
839
816
|
response.end(JSON.stringify({ status: -70410 /* INVALID_VALUE_IN_REQUEST */ }));
|
|
840
817
|
}
|
|
841
818
|
};
|
|
842
819
|
HAPServer.prototype.handlePrepareWrite = function (connection, url, request, data, response) {
|
|
843
820
|
var _this = this;
|
|
844
821
|
if (!this.allowInsecureRequest && !connection.isAuthenticated()) {
|
|
845
|
-
response.writeHead(470 /* CONNECTION_AUTHORIZATION_REQUIRED */, { "Content-Type": "application/hap+json" });
|
|
822
|
+
response.writeHead(470 /* CONNECTION_AUTHORIZATION_REQUIRED */, { "Content-Type": "application/hap+json" /* HAP_JSON */ });
|
|
846
823
|
response.end(JSON.stringify({ status: -70401 /* INSUFFICIENT_PRIVILEGES */ }));
|
|
847
824
|
return;
|
|
848
825
|
}
|
|
849
826
|
if (request.method === "PUT") {
|
|
850
827
|
if (data.length === 0) {
|
|
851
|
-
response.writeHead(400 /* BAD_REQUEST */, { "Content-Type": "application/hap+json" });
|
|
828
|
+
response.writeHead(400 /* BAD_REQUEST */, { "Content-Type": "application/hap+json" /* HAP_JSON */ });
|
|
852
829
|
response.end(JSON.stringify({ status: -70410 /* INVALID_VALUE_IN_REQUEST */ }));
|
|
853
830
|
return;
|
|
854
831
|
}
|
|
@@ -864,31 +841,31 @@ var HAPServer = /** @class */ (function (_super) {
|
|
|
864
841
|
connection.timedWritePid = undefined;
|
|
865
842
|
connection.timedWriteTimeout = undefined;
|
|
866
843
|
}, prepareRequest_1.ttl);
|
|
867
|
-
response.writeHead(200 /* OK */, { "Content-Type": "application/hap+json" });
|
|
844
|
+
response.writeHead(200 /* OK */, { "Content-Type": "application/hap+json" /* HAP_JSON */ });
|
|
868
845
|
response.end(JSON.stringify({ status: 0 /* SUCCESS */ }));
|
|
869
846
|
return;
|
|
870
847
|
}
|
|
871
848
|
else {
|
|
872
|
-
response.writeHead(400 /* BAD_REQUEST */, { "Content-Type": "application/hap+json" });
|
|
849
|
+
response.writeHead(400 /* BAD_REQUEST */, { "Content-Type": "application/hap+json" /* HAP_JSON */ });
|
|
873
850
|
response.end(JSON.stringify({ status: -70410 /* INVALID_VALUE_IN_REQUEST */ }));
|
|
874
851
|
}
|
|
875
852
|
}
|
|
876
853
|
else {
|
|
877
|
-
response.writeHead(400 /* BAD_REQUEST */, { "Content-Type": "application/hap+json" });
|
|
854
|
+
response.writeHead(400 /* BAD_REQUEST */, { "Content-Type": "application/hap+json" /* HAP_JSON */ });
|
|
878
855
|
response.end(JSON.stringify({ status: -70410 /* INVALID_VALUE_IN_REQUEST */ }));
|
|
879
856
|
}
|
|
880
857
|
};
|
|
881
858
|
HAPServer.prototype.handleResource = function (connection, url, request, data, response) {
|
|
882
859
|
if (!connection.isAuthenticated()) {
|
|
883
860
|
if (!(this.allowInsecureRequest && request.headers && request.headers.authorization === this.accessoryInfo.pincode)) {
|
|
884
|
-
response.writeHead(470 /* CONNECTION_AUTHORIZATION_REQUIRED */, { "Content-Type": "application/hap+json" });
|
|
861
|
+
response.writeHead(470 /* CONNECTION_AUTHORIZATION_REQUIRED */, { "Content-Type": "application/hap+json" /* HAP_JSON */ });
|
|
885
862
|
response.end(JSON.stringify({ status: -70401 /* INSUFFICIENT_PRIVILEGES */ }));
|
|
886
863
|
return;
|
|
887
864
|
}
|
|
888
865
|
}
|
|
889
866
|
if (request.method === "POST") {
|
|
890
867
|
if (data.length === 0) {
|
|
891
|
-
response.writeHead(400 /* BAD_REQUEST */, { "Content-Type": "application/hap+json" });
|
|
868
|
+
response.writeHead(400 /* BAD_REQUEST */, { "Content-Type": "application/hap+json" /* HAP_JSON */ });
|
|
892
869
|
response.end(JSON.stringify({ status: -70410 /* INVALID_VALUE_IN_REQUEST */ }));
|
|
893
870
|
return;
|
|
894
871
|
}
|
|
@@ -896,17 +873,17 @@ var HAPServer = /** @class */ (function (_super) {
|
|
|
896
873
|
// call out to listeners to retrieve the resource, snapshot only right now
|
|
897
874
|
this.emit("request-resource" /* REQUEST_RESOURCE */, resourceRequest, (0, once_1.once)(function (error, resource) {
|
|
898
875
|
if (error) {
|
|
899
|
-
response.writeHead(error.httpCode, { "Content-Type": "application/hap+json" });
|
|
876
|
+
response.writeHead(error.httpCode, { "Content-Type": "application/hap+json" /* HAP_JSON */ });
|
|
900
877
|
response.end(JSON.stringify({ status: error.status }));
|
|
901
878
|
}
|
|
902
879
|
else {
|
|
903
|
-
response.writeHead(200 /* OK */, { "Content-Type": "image/jpeg" });
|
|
880
|
+
response.writeHead(200 /* OK */, { "Content-Type": "image/jpeg" /* IMAGE_JPEG */ });
|
|
904
881
|
response.end(resource);
|
|
905
882
|
}
|
|
906
883
|
}));
|
|
907
884
|
}
|
|
908
885
|
else {
|
|
909
|
-
response.writeHead(400 /* BAD_REQUEST */, { "Content-Type": "application/hap+json" }); // method not allowed
|
|
886
|
+
response.writeHead(400 /* BAD_REQUEST */, { "Content-Type": "application/hap+json" /* HAP_JSON */ }); // method not allowed
|
|
910
887
|
response.end(JSON.stringify({ status: -70410 /* INVALID_VALUE_IN_REQUEST */ }));
|
|
911
888
|
}
|
|
912
889
|
};
|