hap-nodejs 1.1.1-beta.4 → 1.1.1-beta.6
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/@types/bonjour-hap.d.ts +53 -50
- package/@types/simple-plist.d.ts +4 -0
- package/README.md +19 -16
- package/dist/accessories/AirConditioner_accessory.js +30 -28
- package/dist/accessories/AirConditioner_accessory.js.map +1 -1
- package/dist/accessories/AppleTVRemote_accessory.js +81 -69
- package/dist/accessories/AppleTVRemote_accessory.js.map +1 -1
- package/dist/accessories/Camera_accessory.js +136 -141
- package/dist/accessories/Camera_accessory.js.map +1 -1
- package/dist/accessories/Fan_accessory.js +22 -18
- package/dist/accessories/Fan_accessory.js.map +1 -1
- package/dist/accessories/GarageDoorOpener_accessory.js +35 -33
- package/dist/accessories/GarageDoorOpener_accessory.js.map +1 -1
- package/dist/accessories/Light-AdaptiveLighting_accessory.js +44 -42
- package/dist/accessories/Light-AdaptiveLighting_accessory.js.map +1 -1
- package/dist/accessories/Light_accessory.js +34 -32
- package/dist/accessories/Light_accessory.js.map +1 -1
- package/dist/accessories/Lock_accessory.js +26 -25
- package/dist/accessories/Lock_accessory.js.map +1 -1
- package/dist/accessories/MotionSensor_accessory.js +16 -13
- package/dist/accessories/MotionSensor_accessory.js.map +1 -1
- package/dist/accessories/Outlet_accessory.js +22 -20
- package/dist/accessories/Outlet_accessory.js.map +1 -1
- package/dist/accessories/SmartSpeaker_accessory.js +20 -18
- package/dist/accessories/SmartSpeaker_accessory.js.map +1 -1
- package/dist/accessories/Sprinkler_accessory.js +37 -34
- package/dist/accessories/Sprinkler_accessory.js.map +1 -1
- package/dist/accessories/TV_accessory.js +45 -43
- package/dist/accessories/TV_accessory.js.map +1 -1
- package/dist/accessories/TemperatureSensor_accessory.js +15 -12
- package/dist/accessories/TemperatureSensor_accessory.js.map +1 -1
- package/dist/accessories/Wi-FiRouter_accessory.d.ts +1 -1
- package/dist/accessories/Wi-FiRouter_accessory.d.ts.map +1 -1
- package/dist/accessories/Wi-FiRouter_accessory.js +12 -9
- package/dist/accessories/Wi-FiRouter_accessory.js.map +1 -1
- package/dist/accessories/Wi-FiSatellite_accessory.d.ts +1 -1
- package/dist/accessories/Wi-FiSatellite_accessory.d.ts.map +1 -1
- package/dist/accessories/Wi-FiSatellite_accessory.js +14 -11
- package/dist/accessories/Wi-FiSatellite_accessory.js.map +1 -1
- package/dist/accessories/gstreamer-audioProducer.d.ts +3 -3
- package/dist/accessories/gstreamer-audioProducer.d.ts.map +1 -1
- package/dist/accessories/gstreamer-audioProducer.js +38 -37
- package/dist/accessories/gstreamer-audioProducer.js.map +1 -1
- package/dist/accessories/types.d.ts +63 -63
- package/dist/accessories/types.d.ts.map +1 -1
- package/dist/accessories/types.js +87 -83
- package/dist/accessories/types.js.map +1 -1
- package/dist/index.d.ts +28 -26
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +34 -40
- package/dist/index.js.map +1 -1
- package/dist/internal-types.d.ts +1 -1
- package/dist/internal-types.d.ts.map +1 -1
- package/dist/internal-types.js +21 -19
- package/dist/internal-types.js.map +1 -1
- package/dist/lib/Accessory.d.ts +37 -38
- package/dist/lib/Accessory.d.ts.map +1 -1
- package/dist/lib/Accessory.js +296 -286
- package/dist/lib/Accessory.js.map +1 -1
- package/dist/lib/Advertiser.d.ts +7 -7
- package/dist/lib/Advertiser.d.ts.map +1 -1
- package/dist/lib/Advertiser.js +136 -128
- package/dist/lib/Advertiser.js.map +1 -1
- package/dist/lib/Bridge.d.ts +1 -1
- package/dist/lib/Bridge.d.ts.map +1 -1
- package/dist/lib/Bridge.js +6 -2
- package/dist/lib/Bridge.js.map +1 -1
- package/dist/lib/Characteristic.d.ts +41 -40
- package/dist/lib/Characteristic.d.ts.map +1 -1
- package/dist/lib/Characteristic.js +208 -204
- package/dist/lib/Characteristic.js.map +1 -1
- package/dist/lib/HAPServer.d.ts +30 -31
- package/dist/lib/HAPServer.d.ts.map +1 -1
- package/dist/lib/HAPServer.js +229 -220
- package/dist/lib/HAPServer.js.map +1 -1
- package/dist/lib/Service.d.ts +22 -22
- package/dist/lib/Service.d.ts.map +1 -1
- package/dist/lib/Service.js +67 -63
- package/dist/lib/Service.js.map +1 -1
- package/dist/lib/camera/RTPProxy.d.ts +1 -2
- package/dist/lib/camera/RTPProxy.d.ts.map +1 -1
- package/dist/lib/camera/RTPProxy.js +44 -28
- package/dist/lib/camera/RTPProxy.js.map +1 -1
- package/dist/lib/camera/RTPStreamManagement.d.ts +33 -34
- package/dist/lib/camera/RTPStreamManagement.d.ts.map +1 -1
- package/dist/lib/camera/RTPStreamManagement.js +149 -181
- package/dist/lib/camera/RTPStreamManagement.js.map +1 -1
- package/dist/lib/camera/RecordingManagement.d.ts +17 -19
- package/dist/lib/camera/RecordingManagement.d.ts.map +1 -1
- package/dist/lib/camera/RecordingManagement.js +151 -160
- package/dist/lib/camera/RecordingManagement.js.map +1 -1
- package/dist/lib/camera/index.d.ts +3 -3
- package/dist/lib/camera/index.d.ts.map +1 -1
- package/dist/lib/camera/index.js +6 -3
- package/dist/lib/camera/index.js.map +1 -1
- package/dist/lib/controller/AdaptiveLightingController.d.ts +33 -33
- package/dist/lib/controller/AdaptiveLightingController.d.ts.map +1 -1
- package/dist/lib/controller/AdaptiveLightingController.js +144 -152
- package/dist/lib/controller/AdaptiveLightingController.js.map +1 -1
- package/dist/lib/controller/CameraController.d.ts +20 -22
- package/dist/lib/controller/CameraController.d.ts.map +1 -1
- package/dist/lib/controller/CameraController.js +78 -74
- package/dist/lib/controller/CameraController.js.map +1 -1
- package/dist/lib/controller/Controller.d.ts +4 -4
- package/dist/lib/controller/Controller.d.ts.map +1 -1
- package/dist/lib/controller/Controller.js +8 -5
- package/dist/lib/controller/Controller.js.map +1 -1
- package/dist/lib/controller/DoorbellController.d.ts +4 -5
- package/dist/lib/controller/DoorbellController.d.ts.map +1 -1
- package/dist/lib/controller/DoorbellController.js +13 -9
- package/dist/lib/controller/DoorbellController.js.map +1 -1
- package/dist/lib/controller/RemoteController.d.ts +37 -39
- package/dist/lib/controller/RemoteController.d.ts.map +1 -1
- package/dist/lib/controller/RemoteController.js +197 -208
- package/dist/lib/controller/RemoteController.js.map +1 -1
- package/dist/lib/controller/index.d.ts +5 -5
- package/dist/lib/controller/index.d.ts.map +1 -1
- package/dist/lib/controller/index.js +8 -5
- package/dist/lib/controller/index.js.map +1 -1
- package/dist/lib/datastream/DataStreamManagement.d.ts +2 -2
- package/dist/lib/datastream/DataStreamManagement.d.ts.map +1 -1
- package/dist/lib/datastream/DataStreamManagement.js +39 -39
- package/dist/lib/datastream/DataStreamManagement.js.map +1 -1
- package/dist/lib/datastream/DataStreamParser.d.ts +0 -1
- package/dist/lib/datastream/DataStreamParser.d.ts.map +1 -1
- package/dist/lib/datastream/DataStreamParser.js +77 -57
- package/dist/lib/datastream/DataStreamParser.js.map +1 -1
- package/dist/lib/datastream/DataStreamServer.d.ts +22 -23
- package/dist/lib/datastream/DataStreamServer.d.ts.map +1 -1
- package/dist/lib/datastream/DataStreamServer.js +164 -154
- package/dist/lib/datastream/DataStreamServer.js.map +1 -1
- package/dist/lib/datastream/index.d.ts +3 -3
- package/dist/lib/datastream/index.d.ts.map +1 -1
- package/dist/lib/datastream/index.js +6 -3
- package/dist/lib/datastream/index.js.map +1 -1
- package/dist/lib/definitions/CharacteristicDefinitions.d.ts +11 -1
- package/dist/lib/definitions/CharacteristicDefinitions.d.ts.map +1 -1
- package/dist/lib/definitions/CharacteristicDefinitions.js +1218 -957
- package/dist/lib/definitions/CharacteristicDefinitions.js.map +1 -1
- package/dist/lib/definitions/ServiceDefinitions.d.ts +1 -1
- package/dist/lib/definitions/ServiceDefinitions.d.ts.map +1 -1
- package/dist/lib/definitions/ServiceDefinitions.js +695 -620
- package/dist/lib/definitions/ServiceDefinitions.js.map +1 -1
- package/dist/lib/definitions/generate-definitions.d.ts +3 -3
- package/dist/lib/definitions/generate-definitions.d.ts.map +1 -1
- package/dist/lib/definitions/generate-definitions.js +256 -244
- package/dist/lib/definitions/generate-definitions.js.map +1 -1
- package/dist/lib/definitions/generator-configuration.d.ts +1 -1
- package/dist/lib/definitions/generator-configuration.d.ts.map +1 -1
- package/dist/lib/definitions/generator-configuration.js +170 -160
- package/dist/lib/definitions/generator-configuration.js.map +1 -1
- package/dist/lib/definitions/index.d.ts +2 -2
- package/dist/lib/definitions/index.d.ts.map +1 -1
- package/dist/lib/definitions/index.js +5 -2
- package/dist/lib/definitions/index.js.map +1 -1
- package/dist/lib/gen/HomeKit.d.ts +7 -0
- package/dist/lib/gen/HomeKit.d.ts.map +1 -0
- package/dist/lib/gen/HomeKit.js +8 -0
- package/dist/lib/gen/HomeKit.js.map +1 -0
- package/dist/lib/model/AccessoryInfo.d.ts +3 -4
- package/dist/lib/model/AccessoryInfo.d.ts.map +1 -1
- package/dist/lib/model/AccessoryInfo.js +53 -50
- package/dist/lib/model/AccessoryInfo.js.map +1 -1
- package/dist/lib/model/ControllerStorage.d.ts +3 -3
- package/dist/lib/model/ControllerStorage.d.ts.map +1 -1
- package/dist/lib/model/ControllerStorage.js +23 -18
- package/dist/lib/model/ControllerStorage.js.map +1 -1
- package/dist/lib/model/HAPStorage.d.ts +2 -2
- package/dist/lib/model/HAPStorage.d.ts.map +1 -1
- package/dist/lib/model/HAPStorage.js +11 -4
- package/dist/lib/model/HAPStorage.js.map +1 -1
- package/dist/lib/model/IdentifierCache.d.ts +1 -1
- package/dist/lib/model/IdentifierCache.d.ts.map +1 -1
- package/dist/lib/model/IdentifierCache.js +27 -19
- package/dist/lib/model/IdentifierCache.js.map +1 -1
- package/dist/lib/tv/AccessControlManagement.d.ts +9 -9
- package/dist/lib/tv/AccessControlManagement.d.ts.map +1 -1
- package/dist/lib/tv/AccessControlManagement.js +29 -27
- package/dist/lib/tv/AccessControlManagement.js.map +1 -1
- package/dist/lib/util/checkName.d.ts +2 -2
- package/dist/lib/util/checkName.d.ts.map +1 -1
- package/dist/lib/util/checkName.js +9 -6
- package/dist/lib/util/checkName.js.map +1 -1
- package/dist/lib/util/clone.d.ts.map +1 -1
- package/dist/lib/util/clone.js +5 -1
- package/dist/lib/util/clone.js.map +1 -1
- package/dist/lib/util/color-utils.d.ts +1 -1
- package/dist/lib/util/color-utils.d.ts.map +1 -1
- package/dist/lib/util/color-utils.js +9 -4
- package/dist/lib/util/color-utils.js.map +1 -1
- package/dist/lib/util/eventedhttp.d.ts +22 -23
- package/dist/lib/util/eventedhttp.d.ts.map +1 -1
- package/dist/lib/util/eventedhttp.js +116 -109
- package/dist/lib/util/eventedhttp.js.map +1 -1
- package/dist/lib/util/hapCrypto.d.ts +2 -3
- package/dist/lib/util/hapCrypto.d.ts.map +1 -1
- package/dist/lib/util/hapCrypto.js +40 -31
- package/dist/lib/util/hapCrypto.js.map +1 -1
- package/dist/lib/util/hapStatusError.d.ts +1 -1
- package/dist/lib/util/hapStatusError.d.ts.map +1 -1
- package/dist/lib/util/hapStatusError.js +8 -4
- package/dist/lib/util/hapStatusError.js.map +1 -1
- package/dist/lib/util/net-utils.d.ts +1 -1
- package/dist/lib/util/net-utils.js +23 -17
- package/dist/lib/util/net-utils.js.map +1 -1
- package/dist/lib/util/once.d.ts.map +1 -1
- package/dist/lib/util/once.js +6 -2
- package/dist/lib/util/once.js.map +1 -1
- package/dist/lib/util/promise-utils.d.ts +1 -1
- package/dist/lib/util/promise-utils.d.ts.map +1 -1
- package/dist/lib/util/promise-utils.js +10 -3
- package/dist/lib/util/promise-utils.js.map +1 -1
- package/dist/lib/util/request-util.d.ts +2 -3
- package/dist/lib/util/request-util.d.ts.map +1 -1
- package/dist/lib/util/request-util.js +19 -11
- package/dist/lib/util/request-util.js.map +1 -1
- package/dist/lib/util/time.d.ts +0 -1
- package/dist/lib/util/time.d.ts.map +1 -1
- package/dist/lib/util/time.js +11 -6
- package/dist/lib/util/time.js.map +1 -1
- package/dist/lib/util/tlv.d.ts +0 -1
- package/dist/lib/util/tlv.d.ts.map +1 -1
- package/dist/lib/util/tlv.js +43 -28
- package/dist/lib/util/tlv.js.map +1 -1
- package/dist/lib/util/uuid.d.ts +0 -1
- package/dist/lib/util/uuid.d.ts.map +1 -1
- package/dist/lib/util/uuid.js +38 -26
- package/dist/lib/util/uuid.js.map +1 -1
- package/dist/types.d.ts +24 -24
- package/dist/types.d.ts.map +1 -1
- package/dist/types.js +5 -3
- package/dist/types.js.map +1 -1
- package/package.json +45 -50
- package/dist/lib/dbus/align.d.ts +0 -2
- package/dist/lib/dbus/align.d.ts.map +0 -1
- package/dist/lib/dbus/align.js +0 -12
- package/dist/lib/dbus/align.js.map +0 -1
- package/dist/lib/dbus/bus.d.ts +0 -38
- package/dist/lib/dbus/bus.d.ts.map +0 -1
- package/dist/lib/dbus/bus.js +0 -222
- package/dist/lib/dbus/bus.js.map +0 -1
- package/dist/lib/dbus/constants.d.ts +0 -43
- package/dist/lib/dbus/constants.d.ts.map +0 -1
- package/dist/lib/dbus/constants.js +0 -53
- package/dist/lib/dbus/constants.js.map +0 -1
- package/dist/lib/dbus/dbus-buffer.d.ts +0 -30
- package/dist/lib/dbus/dbus-buffer.d.ts.map +0 -1
- package/dist/lib/dbus/dbus-buffer.js +0 -175
- package/dist/lib/dbus/dbus-buffer.js.map +0 -1
- package/dist/lib/dbus/handshake.d.ts +0 -2
- package/dist/lib/dbus/handshake.d.ts.map +0 -1
- package/dist/lib/dbus/handshake.js +0 -130
- package/dist/lib/dbus/handshake.js.map +0 -1
- package/dist/lib/dbus/index.d.ts +0 -3
- package/dist/lib/dbus/index.d.ts.map +0 -1
- package/dist/lib/dbus/index.js +0 -123
- package/dist/lib/dbus/index.js.map +0 -1
- package/dist/lib/dbus/introspect.d.ts +0 -30
- package/dist/lib/dbus/introspect.d.ts.map +0 -1
- package/dist/lib/dbus/introspect.js +0 -208
- package/dist/lib/dbus/introspect.js.map +0 -1
- package/dist/lib/dbus/marshall.d.ts +0 -2
- package/dist/lib/dbus/marshall.d.ts.map +0 -1
- package/dist/lib/dbus/marshall.js +0 -97
- package/dist/lib/dbus/marshall.js.map +0 -1
- package/dist/lib/dbus/marshallers.d.ts +0 -10
- package/dist/lib/dbus/marshallers.d.ts.map +0 -1
- package/dist/lib/dbus/marshallers.js +0 -329
- package/dist/lib/dbus/marshallers.js.map +0 -1
- package/dist/lib/dbus/message.d.ts +0 -4
- package/dist/lib/dbus/message.d.ts.map +0 -1
- package/dist/lib/dbus/message.js +0 -116
- package/dist/lib/dbus/message.js.map +0 -1
- package/dist/lib/dbus/put.d.ts +0 -21
- package/dist/lib/dbus/put.d.ts.map +0 -1
- package/dist/lib/dbus/put.js +0 -120
- package/dist/lib/dbus/put.js.map +0 -1
- package/dist/lib/dbus/readline.d.ts +0 -2
- package/dist/lib/dbus/readline.d.ts.map +0 -1
- package/dist/lib/dbus/readline.js +0 -27
- package/dist/lib/dbus/readline.js.map +0 -1
- package/dist/lib/dbus/signature.d.ts +0 -2
- package/dist/lib/dbus/signature.d.ts.map +0 -1
- package/dist/lib/dbus/signature.js +0 -59
- package/dist/lib/dbus/signature.js.map +0 -1
- package/dist/lib/dbus/stdifaces.d.ts +0 -3
- package/dist/lib/dbus/stdifaces.d.ts.map +0 -1
- package/dist/lib/dbus/stdifaces.js +0 -206
- package/dist/lib/dbus/stdifaces.js.map +0 -1
|
@@ -1,27 +1,28 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
const
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.DataStreamConnection = exports.HDSConnectionError = exports.HDSConnectionErrorType = exports.DataStreamConnectionEvent = exports.DataStreamServer = exports.DataStreamServerEvent = exports.MessageType = exports.HDSProtocolError = exports.HDSProtocolSpecificErrorReason = exports.HDSStatus = exports.Topics = exports.Protocols = void 0;
|
|
4
|
+
const tslib_1 = require("tslib");
|
|
5
|
+
const assert_1 = tslib_1.__importDefault(require("assert"));
|
|
6
|
+
const crypto_1 = tslib_1.__importDefault(require("crypto"));
|
|
7
|
+
const debug_1 = tslib_1.__importDefault(require("debug"));
|
|
8
|
+
const events_1 = require("events");
|
|
9
|
+
const net_1 = tslib_1.__importDefault(require("net"));
|
|
10
|
+
const hapCrypto = tslib_1.__importStar(require("../util/hapCrypto"));
|
|
11
|
+
const DataStreamParser_1 = require("./DataStreamParser");
|
|
12
|
+
const debug = (0, debug_1.default)("HAP-NodeJS:DataStream:Server");
|
|
10
13
|
/**
|
|
11
14
|
* @group HomeKit Data Streams (HDS)
|
|
12
15
|
*/
|
|
13
|
-
|
|
14
|
-
export var Protocols;
|
|
16
|
+
var Protocols;
|
|
15
17
|
(function (Protocols) {
|
|
16
18
|
Protocols["CONTROL"] = "control";
|
|
17
19
|
Protocols["TARGET_CONTROL"] = "targetControl";
|
|
18
20
|
Protocols["DATA_SEND"] = "dataSend";
|
|
19
|
-
})(Protocols || (Protocols = {}));
|
|
21
|
+
})(Protocols || (exports.Protocols = Protocols = {}));
|
|
20
22
|
/**
|
|
21
23
|
* @group HomeKit Data Streams (HDS)
|
|
22
24
|
*/
|
|
23
|
-
|
|
24
|
-
export var Topics;
|
|
25
|
+
var Topics;
|
|
25
26
|
(function (Topics) {
|
|
26
27
|
// control
|
|
27
28
|
Topics["HELLO"] = "hello";
|
|
@@ -32,12 +33,13 @@ export var Topics;
|
|
|
32
33
|
Topics["DATA"] = "data";
|
|
33
34
|
Topics["ACK"] = "ack";
|
|
34
35
|
Topics["CLOSE"] = "close";
|
|
35
|
-
})(Topics || (Topics = {}));
|
|
36
|
+
})(Topics || (exports.Topics = Topics = {}));
|
|
36
37
|
/**
|
|
37
38
|
* @group HomeKit Data Streams (HDS)
|
|
38
39
|
*/
|
|
39
|
-
|
|
40
|
+
var HDSStatus;
|
|
40
41
|
(function (HDSStatus) {
|
|
42
|
+
// noinspection JSUnusedGlobalSymbols
|
|
41
43
|
HDSStatus[HDSStatus["SUCCESS"] = 0] = "SUCCESS";
|
|
42
44
|
HDSStatus[HDSStatus["OUT_OF_MEMORY"] = 1] = "OUT_OF_MEMORY";
|
|
43
45
|
HDSStatus[HDSStatus["TIMEOUT"] = 2] = "TIMEOUT";
|
|
@@ -45,13 +47,13 @@ export var HDSStatus;
|
|
|
45
47
|
HDSStatus[HDSStatus["PAYLOAD_ERROR"] = 4] = "PAYLOAD_ERROR";
|
|
46
48
|
HDSStatus[HDSStatus["MISSING_PROTOCOL"] = 5] = "MISSING_PROTOCOL";
|
|
47
49
|
HDSStatus[HDSStatus["PROTOCOL_SPECIFIC_ERROR"] = 6] = "PROTOCOL_SPECIFIC_ERROR";
|
|
48
|
-
})(HDSStatus || (HDSStatus = {}));
|
|
50
|
+
})(HDSStatus || (exports.HDSStatus = HDSStatus = {}));
|
|
49
51
|
/**
|
|
50
52
|
* @group HomeKit Data Streams (HDS)
|
|
51
53
|
*/
|
|
52
|
-
|
|
53
|
-
export var HDSProtocolSpecificErrorReason;
|
|
54
|
+
var HDSProtocolSpecificErrorReason;
|
|
54
55
|
(function (HDSProtocolSpecificErrorReason) {
|
|
56
|
+
// noinspection JSUnusedGlobalSymbols
|
|
55
57
|
HDSProtocolSpecificErrorReason[HDSProtocolSpecificErrorReason["NORMAL"] = 0] = "NORMAL";
|
|
56
58
|
HDSProtocolSpecificErrorReason[HDSProtocolSpecificErrorReason["NOT_ALLOWED"] = 1] = "NOT_ALLOWED";
|
|
57
59
|
HDSProtocolSpecificErrorReason[HDSProtocolSpecificErrorReason["BUSY"] = 2] = "BUSY";
|
|
@@ -62,26 +64,26 @@ export var HDSProtocolSpecificErrorReason;
|
|
|
62
64
|
HDSProtocolSpecificErrorReason[HDSProtocolSpecificErrorReason["BAD_DATA"] = 7] = "BAD_DATA";
|
|
63
65
|
HDSProtocolSpecificErrorReason[HDSProtocolSpecificErrorReason["PROTOCOL_ERROR"] = 8] = "PROTOCOL_ERROR";
|
|
64
66
|
HDSProtocolSpecificErrorReason[HDSProtocolSpecificErrorReason["INVALID_CONFIGURATION"] = 9] = "INVALID_CONFIGURATION";
|
|
65
|
-
})(HDSProtocolSpecificErrorReason || (HDSProtocolSpecificErrorReason = {}));
|
|
67
|
+
})(HDSProtocolSpecificErrorReason || (exports.HDSProtocolSpecificErrorReason = HDSProtocolSpecificErrorReason = {}));
|
|
66
68
|
/**
|
|
67
69
|
* An error indicating a protocol level HDS error.
|
|
68
70
|
* E.g. it may be used to encode a {@link HDSStatus.PROTOCOL_SPECIFIC_ERROR} in the {@link Protocols.DATA_SEND} protocol.
|
|
69
71
|
* @group HomeKit Data Streams (HDS)
|
|
70
72
|
*/
|
|
71
|
-
|
|
73
|
+
class HDSProtocolError extends Error {
|
|
72
74
|
reason;
|
|
73
75
|
/**
|
|
74
76
|
* Initializes a new `HDSProtocolError`
|
|
75
77
|
* @param reason - The {@link HDSProtocolSpecificErrorReason}.
|
|
76
|
-
*
|
|
78
|
+
* Values MUST NOT be {@link HDSProtocolSpecificErrorReason.NORMAL}.
|
|
77
79
|
*/
|
|
78
80
|
constructor(reason) {
|
|
79
|
-
super(
|
|
80
|
-
|
|
81
|
+
super("HDSProtocolError: " + reason);
|
|
82
|
+
(0, assert_1.default)(reason !== 0 /* HDSProtocolSpecificErrorReason.NORMAL */, "Cannot initialize a HDSProtocolError with NORMAL!");
|
|
81
83
|
this.reason = reason;
|
|
82
84
|
}
|
|
83
85
|
}
|
|
84
|
-
|
|
86
|
+
exports.HDSProtocolError = HDSProtocolError;
|
|
85
87
|
var ServerState;
|
|
86
88
|
(function (ServerState) {
|
|
87
89
|
ServerState[ServerState["UNINITIALIZED"] = 0] = "UNINITIALIZED";
|
|
@@ -89,7 +91,6 @@ var ServerState;
|
|
|
89
91
|
ServerState[ServerState["LISTENING"] = 2] = "LISTENING";
|
|
90
92
|
ServerState[ServerState["CLOSING"] = 3] = "CLOSING";
|
|
91
93
|
})(ServerState || (ServerState = {}));
|
|
92
|
-
// eslint-disable-next-line no-restricted-syntax
|
|
93
94
|
var ConnectionState;
|
|
94
95
|
(function (ConnectionState) {
|
|
95
96
|
ConnectionState[ConnectionState["UNIDENTIFIED"] = 0] = "UNIDENTIFIED";
|
|
@@ -101,18 +102,16 @@ var ConnectionState;
|
|
|
101
102
|
/**
|
|
102
103
|
* @group HomeKit Data Streams (HDS)
|
|
103
104
|
*/
|
|
104
|
-
|
|
105
|
-
export var MessageType;
|
|
105
|
+
var MessageType;
|
|
106
106
|
(function (MessageType) {
|
|
107
107
|
MessageType[MessageType["EVENT"] = 1] = "EVENT";
|
|
108
108
|
MessageType[MessageType["REQUEST"] = 2] = "REQUEST";
|
|
109
109
|
MessageType[MessageType["RESPONSE"] = 3] = "RESPONSE";
|
|
110
|
-
})(MessageType || (MessageType = {}));
|
|
110
|
+
})(MessageType || (exports.MessageType = MessageType = {}));
|
|
111
111
|
/**
|
|
112
112
|
* @group HomeKit Data Streams (HDS)
|
|
113
113
|
*/
|
|
114
|
-
|
|
115
|
-
export var DataStreamServerEvent;
|
|
114
|
+
var DataStreamServerEvent;
|
|
116
115
|
(function (DataStreamServerEvent) {
|
|
117
116
|
/**
|
|
118
117
|
* This event is emitted when a new client socket is received. At this point we have no idea to what
|
|
@@ -123,23 +122,23 @@ export var DataStreamServerEvent;
|
|
|
123
122
|
* This event is emitted when the socket of a connection gets closed.
|
|
124
123
|
*/
|
|
125
124
|
DataStreamServerEvent["CONNECTION_CLOSED"] = "connection-closed";
|
|
126
|
-
})(DataStreamServerEvent || (DataStreamServerEvent = {}));
|
|
125
|
+
})(DataStreamServerEvent || (exports.DataStreamServerEvent = DataStreamServerEvent = {}));
|
|
127
126
|
/**
|
|
128
127
|
* DataStreamServer which listens for incoming tcp connections and handles identification of new connections
|
|
129
128
|
* @group HomeKit Data Streams (HDS)
|
|
130
129
|
*/
|
|
131
|
-
// eslint-disable-next-line
|
|
132
|
-
|
|
133
|
-
static version =
|
|
130
|
+
// eslint-disable-next-line @typescript-eslint/no-unsafe-declaration-merging
|
|
131
|
+
class DataStreamServer extends events_1.EventEmitter {
|
|
132
|
+
static version = "1.0";
|
|
134
133
|
state = 0 /* ServerState.UNINITIALIZED */;
|
|
135
|
-
static accessoryToControllerInfo = Buffer.from(
|
|
136
|
-
static controllerToAccessoryInfo = Buffer.from(
|
|
134
|
+
static accessoryToControllerInfo = Buffer.from("HDS-Read-Encryption-Key");
|
|
135
|
+
static controllerToAccessoryInfo = Buffer.from("HDS-Write-Encryption-Key");
|
|
137
136
|
tcpServer;
|
|
138
137
|
tcpPort;
|
|
139
138
|
preparedSessions = [];
|
|
140
139
|
connections = [];
|
|
141
140
|
removeListenersOnceClosed = false;
|
|
142
|
-
internalEventEmitter = new
|
|
141
|
+
internalEventEmitter = new events_1.EventEmitter(); // used for message event and message request handlers
|
|
143
142
|
constructor() {
|
|
144
143
|
super();
|
|
145
144
|
}
|
|
@@ -153,7 +152,7 @@ export class DataStreamServer extends EventEmitter {
|
|
|
153
152
|
* @param handler - function to be called for every occurring event
|
|
154
153
|
*/
|
|
155
154
|
onEventMessage(protocol, event, handler) {
|
|
156
|
-
this.internalEventEmitter.on(
|
|
155
|
+
this.internalEventEmitter.on(protocol + "-e-" + event, handler);
|
|
157
156
|
return this;
|
|
158
157
|
}
|
|
159
158
|
/**
|
|
@@ -164,7 +163,7 @@ export class DataStreamServer extends EventEmitter {
|
|
|
164
163
|
* @param handler - registered event handler
|
|
165
164
|
*/
|
|
166
165
|
removeEventHandler(protocol, event, handler) {
|
|
167
|
-
this.internalEventEmitter.removeListener(
|
|
166
|
+
this.internalEventEmitter.removeListener(protocol + "-e-" + event, handler);
|
|
168
167
|
return this;
|
|
169
168
|
}
|
|
170
169
|
/**
|
|
@@ -177,7 +176,7 @@ export class DataStreamServer extends EventEmitter {
|
|
|
177
176
|
* @param handler - function to be called for every occurring request
|
|
178
177
|
*/
|
|
179
178
|
onRequestMessage(protocol, request, handler) {
|
|
180
|
-
this.internalEventEmitter.on(
|
|
179
|
+
this.internalEventEmitter.on(protocol + "-r-" + request, handler);
|
|
181
180
|
return this;
|
|
182
181
|
}
|
|
183
182
|
/**
|
|
@@ -188,20 +187,20 @@ export class DataStreamServer extends EventEmitter {
|
|
|
188
187
|
* @param handler - registered request handler
|
|
189
188
|
*/
|
|
190
189
|
removeRequestHandler(protocol, request, handler) {
|
|
191
|
-
this.internalEventEmitter.removeListener(
|
|
190
|
+
this.internalEventEmitter.removeListener(protocol + "-r-" + request, handler);
|
|
192
191
|
return this;
|
|
193
192
|
}
|
|
194
193
|
prepareSession(connection, controllerKeySalt, callback) {
|
|
195
|
-
debug(
|
|
196
|
-
const accessoryKeySalt = randomBytes(32);
|
|
194
|
+
debug("Preparing for incoming HDS connection from %s", connection.sessionID);
|
|
195
|
+
const accessoryKeySalt = crypto_1.default.randomBytes(32);
|
|
197
196
|
const salt = Buffer.concat([controllerKeySalt, accessoryKeySalt]);
|
|
198
|
-
const accessoryToControllerEncryptionKey = HKDF(
|
|
199
|
-
const controllerToAccessoryEncryptionKey = HKDF(
|
|
197
|
+
const accessoryToControllerEncryptionKey = hapCrypto.HKDF("sha512", salt, connection.encryption.sharedSecret, DataStreamServer.accessoryToControllerInfo, 32);
|
|
198
|
+
const controllerToAccessoryEncryptionKey = hapCrypto.HKDF("sha512", salt, connection.encryption.sharedSecret, DataStreamServer.controllerToAccessoryInfo, 32);
|
|
200
199
|
const preparedSession = {
|
|
201
|
-
connection,
|
|
202
|
-
accessoryToControllerEncryptionKey,
|
|
203
|
-
controllerToAccessoryEncryptionKey,
|
|
204
|
-
accessoryKeySalt,
|
|
200
|
+
connection: connection,
|
|
201
|
+
accessoryToControllerEncryptionKey: accessoryToControllerEncryptionKey,
|
|
202
|
+
controllerToAccessoryEncryptionKey: controllerToAccessoryEncryptionKey,
|
|
203
|
+
accessoryKeySalt: accessoryKeySalt,
|
|
205
204
|
connectTimeout: setTimeout(() => this.timeoutPreparedSession(preparedSession), 10000),
|
|
206
205
|
};
|
|
207
206
|
preparedSession.connectTimeout.unref();
|
|
@@ -216,7 +215,7 @@ export class DataStreamServer extends EventEmitter {
|
|
|
216
215
|
});
|
|
217
216
|
}
|
|
218
217
|
timeoutPreparedSession(preparedSession) {
|
|
219
|
-
debug(
|
|
218
|
+
debug("Prepared HDS session timed out out since no connection was opened for 10 seconds (%s)", preparedSession.connection.sessionID);
|
|
220
219
|
const index = this.preparedSessions.indexOf(preparedSession);
|
|
221
220
|
if (index >= 0) {
|
|
222
221
|
this.preparedSessions.splice(index, 1);
|
|
@@ -226,52 +225,51 @@ export class DataStreamServer extends EventEmitter {
|
|
|
226
225
|
checkTCPServerEstablished(preparedSession, callback) {
|
|
227
226
|
switch (this.state) {
|
|
228
227
|
case 0 /* ServerState.UNINITIALIZED */:
|
|
229
|
-
debug(
|
|
230
|
-
this.tcpServer = createServer();
|
|
231
|
-
this.tcpServer.once(
|
|
232
|
-
this.tcpServer.on(
|
|
233
|
-
this.tcpServer.on(
|
|
228
|
+
debug("Starting up TCP server.");
|
|
229
|
+
this.tcpServer = net_1.default.createServer();
|
|
230
|
+
this.tcpServer.once("listening", this.listening.bind(this, preparedSession, callback));
|
|
231
|
+
this.tcpServer.on("connection", this.onConnection.bind(this));
|
|
232
|
+
this.tcpServer.on("close", this.closed.bind(this));
|
|
234
233
|
this.tcpServer.listen();
|
|
235
234
|
this.state = 1 /* ServerState.BINDING */;
|
|
236
235
|
break;
|
|
237
236
|
case 1 /* ServerState.BINDING */:
|
|
238
|
-
debug(
|
|
239
|
-
this.tcpServer.once(
|
|
237
|
+
debug("TCP server already running. Waiting for it to bind.");
|
|
238
|
+
this.tcpServer.once("listening", this.listening.bind(this, preparedSession, callback));
|
|
240
239
|
break;
|
|
241
240
|
case 2 /* ServerState.LISTENING */:
|
|
242
|
-
debug(
|
|
241
|
+
debug("Instructing client to connect to already running TCP server");
|
|
243
242
|
preparedSession.port = this.tcpPort;
|
|
244
243
|
callback();
|
|
245
244
|
break;
|
|
246
245
|
case 3 /* ServerState.CLOSING */:
|
|
247
|
-
debug(
|
|
248
|
-
this.tcpServer.once(
|
|
246
|
+
debug("TCP socket is currently closing. Trying again when server is fully closed and opening a new one then.");
|
|
247
|
+
this.tcpServer.once("close", () => setTimeout(() => this.checkTCPServerEstablished(preparedSession, callback), 10));
|
|
249
248
|
break;
|
|
250
249
|
}
|
|
251
250
|
}
|
|
252
251
|
listening(preparedSession, callback) {
|
|
253
252
|
this.state = 2 /* ServerState.LISTENING */;
|
|
254
253
|
const address = this.tcpServer.address();
|
|
255
|
-
if (address && typeof address !==
|
|
254
|
+
if (address && typeof address !== "string") { // address is only typeof string when listening to a pipe or unix socket
|
|
256
255
|
this.tcpPort = address.port;
|
|
257
256
|
preparedSession.port = address.port;
|
|
258
|
-
debug(
|
|
257
|
+
debug("TCP server is now listening for new data stream connections on port %s", address.port);
|
|
259
258
|
callback();
|
|
260
259
|
}
|
|
261
260
|
}
|
|
262
261
|
onConnection(socket) {
|
|
263
|
-
debug(
|
|
264
|
-
|
|
265
|
-
|
|
262
|
+
debug("[%s] New DataStream connection was established", socket.remoteAddress);
|
|
263
|
+
// eslint-disable-next-line @typescript-eslint/no-use-before-define
|
|
264
|
+
const connection = new DataStreamConnection(socket);
|
|
266
265
|
connection.on("identification" /* DataStreamConnectionEvent.IDENTIFICATION */, this.handleSessionIdentification.bind(this, connection));
|
|
267
266
|
connection.on("handle-message-globally" /* DataStreamConnectionEvent.HANDLE_MESSAGE_GLOBALLY */, this.handleMessageGlobally.bind(this, connection));
|
|
268
267
|
connection.on("closed" /* DataStreamConnectionEvent.CLOSED */, this.connectionClosed.bind(this, connection));
|
|
269
|
-
/* eslint-enable ts/no-use-before-define */
|
|
270
268
|
this.connections.push(connection);
|
|
271
269
|
this.emit("connection-opened" /* DataStreamServerEvent.CONNECTION_OPENED */, connection);
|
|
272
270
|
}
|
|
273
271
|
handleSessionIdentification(connection, firstFrame, callback) {
|
|
274
|
-
let identifiedSession;
|
|
272
|
+
let identifiedSession = undefined;
|
|
275
273
|
for (let i = 0; i < this.preparedSessions.length; i++) {
|
|
276
274
|
const preparedSession = this.preparedSessions[i];
|
|
277
275
|
// if we successfully decrypt the first frame with this key we know to which session this connection belongs
|
|
@@ -282,7 +280,7 @@ export class DataStreamServer extends EventEmitter {
|
|
|
282
280
|
}
|
|
283
281
|
callback(identifiedSession);
|
|
284
282
|
if (identifiedSession) {
|
|
285
|
-
debug(
|
|
283
|
+
debug("[%s] Connection was successfully identified (linked with sessionId: %s)", connection.remoteAddress, identifiedSession.connection.sessionID);
|
|
286
284
|
const index = this.preparedSessions.indexOf(identifiedSession);
|
|
287
285
|
if (index >= 0) {
|
|
288
286
|
this.preparedSessions.splice(index, 1);
|
|
@@ -294,19 +292,19 @@ export class DataStreamServer extends EventEmitter {
|
|
|
294
292
|
// on the other hand the keepAlive should handle that also :thinking:
|
|
295
293
|
}
|
|
296
294
|
else { // we looped through all session and didn't find anything
|
|
297
|
-
debug(
|
|
295
|
+
debug("[%s] Could not identify connection. Terminating.", connection.remoteAddress);
|
|
298
296
|
connection.close(); // disconnecting since first message was not a valid hello
|
|
299
297
|
}
|
|
300
298
|
}
|
|
301
299
|
handleMessageGlobally(connection, message) {
|
|
302
|
-
|
|
303
|
-
let separator =
|
|
300
|
+
assert_1.default.notStrictEqual(message.type, 3 /* MessageType.RESPONSE */); // responses can't physically get here
|
|
301
|
+
let separator = "";
|
|
304
302
|
const args = [];
|
|
305
303
|
if (message.type === 1 /* MessageType.EVENT */) {
|
|
306
|
-
separator =
|
|
304
|
+
separator = "-e-";
|
|
307
305
|
}
|
|
308
306
|
else if (message.type === 2 /* MessageType.REQUEST */) {
|
|
309
|
-
separator =
|
|
307
|
+
separator = "-r-";
|
|
310
308
|
args.push(message.id);
|
|
311
309
|
}
|
|
312
310
|
args.push(message.message);
|
|
@@ -316,15 +314,15 @@ export class DataStreamServer extends EventEmitter {
|
|
|
316
314
|
}
|
|
317
315
|
catch (error) {
|
|
318
316
|
hadListeners = true;
|
|
319
|
-
debug(
|
|
317
|
+
debug("[%s] Error occurred while dispatching handler for HDS message: %o", connection.remoteAddress, message);
|
|
320
318
|
debug(error.stack);
|
|
321
319
|
}
|
|
322
320
|
if (!hadListeners) {
|
|
323
|
-
debug(
|
|
321
|
+
debug("[%s] WARNING no handler was found for message: %o", connection.remoteAddress, message);
|
|
324
322
|
}
|
|
325
323
|
}
|
|
326
324
|
connectionClosed(connection) {
|
|
327
|
-
debug(
|
|
325
|
+
debug("[%s] DataStream connection closed", connection.remoteAddress);
|
|
328
326
|
this.connections.splice(this.connections.indexOf(connection), 1);
|
|
329
327
|
this.emit("connection-closed" /* DataStreamServerEvent.CONNECTION_CLOSED */, connection);
|
|
330
328
|
this.checkCloseable();
|
|
@@ -334,7 +332,7 @@ export class DataStreamServer extends EventEmitter {
|
|
|
334
332
|
}
|
|
335
333
|
checkCloseable() {
|
|
336
334
|
if (this.connections.length === 0 && this.preparedSessions.length === 0 && this.state < 3 /* ServerState.CLOSING */) {
|
|
337
|
-
debug(
|
|
335
|
+
debug("Last connection disconnected. Closing the server now.");
|
|
338
336
|
this.state = 3 /* ServerState.CLOSING */;
|
|
339
337
|
this.tcpServer.close();
|
|
340
338
|
}
|
|
@@ -359,11 +357,11 @@ export class DataStreamServer extends EventEmitter {
|
|
|
359
357
|
this.state = 0 /* ServerState.UNINITIALIZED */;
|
|
360
358
|
}
|
|
361
359
|
}
|
|
360
|
+
exports.DataStreamServer = DataStreamServer;
|
|
362
361
|
/**
|
|
363
362
|
* @group HomeKit Data Streams (HDS)
|
|
364
363
|
*/
|
|
365
|
-
|
|
366
|
-
export var DataStreamConnectionEvent;
|
|
364
|
+
var DataStreamConnectionEvent;
|
|
367
365
|
(function (DataStreamConnectionEvent) {
|
|
368
366
|
/**
|
|
369
367
|
* This event is emitted when the first HDSFrame is received from a new connection.
|
|
@@ -380,35 +378,35 @@ export var DataStreamConnectionEvent;
|
|
|
380
378
|
* This event is emitted when the socket of the connection was closed.
|
|
381
379
|
*/
|
|
382
380
|
DataStreamConnectionEvent["CLOSED"] = "closed";
|
|
383
|
-
})(DataStreamConnectionEvent || (DataStreamConnectionEvent = {}));
|
|
381
|
+
})(DataStreamConnectionEvent || (exports.DataStreamConnectionEvent = DataStreamConnectionEvent = {}));
|
|
384
382
|
/**
|
|
385
383
|
* @group HomeKit Data Streams (HDS)
|
|
386
384
|
*/
|
|
387
|
-
|
|
388
|
-
export var HDSConnectionErrorType;
|
|
385
|
+
var HDSConnectionErrorType;
|
|
389
386
|
(function (HDSConnectionErrorType) {
|
|
390
387
|
HDSConnectionErrorType[HDSConnectionErrorType["ILLEGAL_STATE"] = 1] = "ILLEGAL_STATE";
|
|
391
388
|
HDSConnectionErrorType[HDSConnectionErrorType["CLOSED_SOCKET"] = 2] = "CLOSED_SOCKET";
|
|
392
389
|
HDSConnectionErrorType[HDSConnectionErrorType["MAX_PAYLOAD_LENGTH"] = 3] = "MAX_PAYLOAD_LENGTH";
|
|
393
|
-
})(HDSConnectionErrorType || (HDSConnectionErrorType = {}));
|
|
390
|
+
})(HDSConnectionErrorType || (exports.HDSConnectionErrorType = HDSConnectionErrorType = {}));
|
|
394
391
|
/**
|
|
395
392
|
* @group HomeKit Data Streams (HDS)
|
|
396
393
|
*/
|
|
397
|
-
|
|
394
|
+
class HDSConnectionError extends Error {
|
|
398
395
|
type;
|
|
399
396
|
constructor(message, type) {
|
|
400
397
|
super(message);
|
|
401
398
|
this.type = type;
|
|
402
399
|
}
|
|
403
400
|
}
|
|
401
|
+
exports.HDSConnectionError = HDSConnectionError;
|
|
404
402
|
/**
|
|
405
403
|
* DataStream connection which holds any necessary state information, encryption and decryption keys, manages
|
|
406
404
|
* protocol handlers and also handles sending and receiving of data stream frames.
|
|
407
405
|
*
|
|
408
406
|
* @group HomeKit Data Streams (HDS)
|
|
409
407
|
*/
|
|
410
|
-
// eslint-disable-next-line
|
|
411
|
-
|
|
408
|
+
// eslint-disable-next-line @typescript-eslint/no-unsafe-declaration-merging
|
|
409
|
+
class DataStreamConnection extends events_1.EventEmitter {
|
|
412
410
|
static MAX_PAYLOAD_LENGTH = 0b11111111111111111111;
|
|
413
411
|
socket;
|
|
414
412
|
connection; // reference to the hap connection. is present when state > UNIDENTIFIED
|
|
@@ -449,12 +447,12 @@ export class DataStreamConnection extends EventEmitter {
|
|
|
449
447
|
},
|
|
450
448
|
});
|
|
451
449
|
this.helloTimer = setTimeout(() => {
|
|
452
|
-
debug(
|
|
450
|
+
debug("[%s] Hello message did not arrive in time. Killing the connection", this.remoteAddress);
|
|
453
451
|
this.close();
|
|
454
452
|
}, 10000);
|
|
455
|
-
this.socket.on(
|
|
456
|
-
this.socket.on(
|
|
457
|
-
this.socket.on(
|
|
453
|
+
this.socket.on("data", this.onSocketData.bind(this));
|
|
454
|
+
this.socket.on("error", this.onSocketError.bind(this));
|
|
455
|
+
this.socket.on("close", this.onSocketClose.bind(this));
|
|
458
456
|
// this is to mitigate the event emitter "memory leak warning".
|
|
459
457
|
// e.g. with HSV there might be multiple cameras subscribing to the CLOSE event. one subscription for
|
|
460
458
|
// every active recording stream on a camera. The default limit of 10 might be easily reached.
|
|
@@ -462,9 +460,10 @@ export class DataStreamConnection extends EventEmitter {
|
|
|
462
460
|
// a warning is still be printed if running long enough.
|
|
463
461
|
this.setMaxListeners(100);
|
|
464
462
|
}
|
|
463
|
+
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
465
464
|
handleHello(id, message) {
|
|
466
465
|
// that hello is indeed the _first_ message received is verified in onSocketData(...)
|
|
467
|
-
debug(
|
|
466
|
+
debug("[%s] Received hello message from client: %o", this.remoteAddress, message);
|
|
468
467
|
clearTimeout(this.helloTimer);
|
|
469
468
|
this.helloTimer = undefined;
|
|
470
469
|
this.state = 2 /* ConnectionState.READY */;
|
|
@@ -503,7 +502,9 @@ export class DataStreamConnection extends EventEmitter {
|
|
|
503
502
|
* @param event - name of the event (also referred to as topic. See {@link Topics} for some known ones)
|
|
504
503
|
* @param message - message dictionary which gets sent along the event
|
|
505
504
|
*/
|
|
505
|
+
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
506
506
|
sendEvent(protocol, event, message = {}) {
|
|
507
|
+
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
507
508
|
const header = {};
|
|
508
509
|
header.protocol = protocol;
|
|
509
510
|
header.event = event;
|
|
@@ -518,8 +519,9 @@ export class DataStreamConnection extends EventEmitter {
|
|
|
518
519
|
* @param request - name of the request (also referred to as topic. See {@link Topics} for some known ones)
|
|
519
520
|
* @param message - message dictionary which gets sent along the request
|
|
520
521
|
* @param callback - handler which gets supplied with an error object if the response didn't
|
|
521
|
-
*
|
|
522
|
+
* arrive in time or the status and the message dictionary from the response
|
|
522
523
|
*/
|
|
524
|
+
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
523
525
|
sendRequest(protocol, request, message = {}, callback) {
|
|
524
526
|
let requestId;
|
|
525
527
|
do { // generate unused requestId
|
|
@@ -534,12 +536,13 @@ export class DataStreamConnection extends EventEmitter {
|
|
|
534
536
|
delete this.responseHandlers[requestId];
|
|
535
537
|
delete this.responseTimers[requestId];
|
|
536
538
|
// handler should be able to clean up their stuff
|
|
537
|
-
handler(new Error(
|
|
539
|
+
handler(new Error("timeout"), undefined, {});
|
|
538
540
|
}, 10000); // 10s timer
|
|
541
|
+
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
539
542
|
const header = {};
|
|
540
543
|
header.protocol = protocol;
|
|
541
544
|
header.request = request;
|
|
542
|
-
header.id = new Int64(requestId);
|
|
545
|
+
header.id = new DataStreamParser_1.Int64(requestId);
|
|
543
546
|
this.sendHDSFrame(header, message);
|
|
544
547
|
}
|
|
545
548
|
/**
|
|
@@ -551,12 +554,15 @@ export class DataStreamConnection extends EventEmitter {
|
|
|
551
554
|
* @param status - status indication if the request was successful. A status of zero indicates success.
|
|
552
555
|
* @param message - message dictionary which gets sent along the response
|
|
553
556
|
*/
|
|
554
|
-
sendResponse(protocol, response, id, status = HDSStatus.SUCCESS,
|
|
557
|
+
sendResponse(protocol, response, id, status = HDSStatus.SUCCESS,
|
|
558
|
+
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
559
|
+
message = {}) {
|
|
560
|
+
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
555
561
|
const header = {};
|
|
556
562
|
header.protocol = protocol;
|
|
557
563
|
header.response = response;
|
|
558
|
-
header.id = new Int64(id);
|
|
559
|
-
header.status = new Int64(status);
|
|
564
|
+
header.id = new DataStreamParser_1.Int64(id);
|
|
565
|
+
header.status = new DataStreamParser_1.Int64(status);
|
|
560
566
|
this.sendHDSFrame(header, message);
|
|
561
567
|
}
|
|
562
568
|
onSocketData(data) {
|
|
@@ -581,7 +587,7 @@ export class DataStreamConnection extends EventEmitter {
|
|
|
581
587
|
// below listener is removed in .close()
|
|
582
588
|
this.connection.setMaxListeners(this.connection.getMaxListeners() + 1);
|
|
583
589
|
this.connection.on("closed" /* HAPConnectionEvent.CLOSED */, this.hapConnectionClosedListener); // register close listener
|
|
584
|
-
debug(
|
|
590
|
+
debug("[%s] Registering CLOSED handler to HAP connection. Connection currently has %d close handlers!", this.remoteAddress, this.connection.listeners("closed" /* HAPConnectionEvent.CLOSED */).length);
|
|
585
591
|
}
|
|
586
592
|
});
|
|
587
593
|
if (this.state === 0 /* ConnectionState.UNIDENTIFIED */) {
|
|
@@ -591,7 +597,7 @@ export class DataStreamConnection extends EventEmitter {
|
|
|
591
597
|
}
|
|
592
598
|
for (; frameIndex < frames.length; frameIndex++) { // decrypt all remaining frames
|
|
593
599
|
if (!this.decryptHDSFrame(frames[frameIndex])) {
|
|
594
|
-
debug(
|
|
600
|
+
debug("[%s] HDS frame decryption or authentication failed. Connection will be terminated!", this.remoteAddress);
|
|
595
601
|
this.close();
|
|
596
602
|
return;
|
|
597
603
|
}
|
|
@@ -601,12 +607,12 @@ export class DataStreamConnection extends EventEmitter {
|
|
|
601
607
|
const firstMessage = messages[0];
|
|
602
608
|
if (firstMessage.protocol !== "control" /* Protocols.CONTROL */ || firstMessage.type !== 2 /* MessageType.REQUEST */ || firstMessage.topic !== "hello" /* Topics.HELLO */) {
|
|
603
609
|
// first message is not the expected hello request
|
|
604
|
-
debug(
|
|
610
|
+
debug("[%s] First message received was not the expected hello message. Instead got: %o", this.remoteAddress, firstMessage);
|
|
605
611
|
this.close();
|
|
606
612
|
return;
|
|
607
613
|
}
|
|
608
614
|
}
|
|
609
|
-
messages.forEach(
|
|
615
|
+
messages.forEach(message => {
|
|
610
616
|
if (message.type === 3 /* MessageType.RESPONSE */) {
|
|
611
617
|
// protocol and topic are currently not tested here; just assumed they are correct;
|
|
612
618
|
// probably they are as the requestId is unique per connection no matter what protocol is used
|
|
@@ -618,14 +624,14 @@ export class DataStreamConnection extends EventEmitter {
|
|
|
618
624
|
}
|
|
619
625
|
if (!responseHandler) {
|
|
620
626
|
// we got a response to a request we did not send; we ignore it for now, since nobody will be hurt
|
|
621
|
-
debug(
|
|
627
|
+
debug("WARNING we received a response to a request we have not sent: %o", message);
|
|
622
628
|
return;
|
|
623
629
|
}
|
|
624
630
|
try {
|
|
625
631
|
responseHandler(undefined, message.status, message.message);
|
|
626
632
|
}
|
|
627
633
|
catch (error) {
|
|
628
|
-
debug(
|
|
634
|
+
debug("[%s] Error occurred while dispatching response handler for HDS message: %o", this.remoteAddress, message);
|
|
629
635
|
debug(error.stack);
|
|
630
636
|
}
|
|
631
637
|
delete this.responseHandlers[message.id];
|
|
@@ -638,35 +644,35 @@ export class DataStreamConnection extends EventEmitter {
|
|
|
638
644
|
return;
|
|
639
645
|
}
|
|
640
646
|
if (message.type === 1 /* MessageType.EVENT */) {
|
|
641
|
-
|
|
642
|
-
|
|
647
|
+
let eventHandler;
|
|
648
|
+
if (!handler.eventHandler || !(eventHandler = handler.eventHandler[message.topic])) {
|
|
649
|
+
debug("[%s] WARNING no event handler was found for message: %o", this.remoteAddress, message);
|
|
643
650
|
return;
|
|
644
651
|
}
|
|
645
|
-
const eventHandler = handler.eventHandler[message.topic];
|
|
646
652
|
try {
|
|
647
653
|
eventHandler(message.message);
|
|
648
654
|
}
|
|
649
655
|
catch (error) {
|
|
650
|
-
debug(
|
|
656
|
+
debug("[%s] Error occurred while dispatching event handler for HDS message: %o", this.remoteAddress, message);
|
|
651
657
|
debug(error.stack);
|
|
652
658
|
}
|
|
653
659
|
}
|
|
654
660
|
else if (message.type === 2 /* MessageType.REQUEST */) {
|
|
655
|
-
|
|
656
|
-
|
|
661
|
+
let requestHandler;
|
|
662
|
+
if (!handler.requestHandler || !(requestHandler = handler.requestHandler[message.topic])) {
|
|
663
|
+
debug("[%s] WARNING no request handler was found for message: %o", this.remoteAddress, message);
|
|
657
664
|
return;
|
|
658
665
|
}
|
|
659
|
-
const requestHandler = handler.requestHandler[message.topic];
|
|
660
666
|
try {
|
|
661
667
|
requestHandler(message.id, message.message);
|
|
662
668
|
}
|
|
663
669
|
catch (error) {
|
|
664
|
-
debug(
|
|
670
|
+
debug("[%s] Error occurred while dispatching request handler for HDS message: %o", this.remoteAddress, message);
|
|
665
671
|
debug(error.stack);
|
|
666
672
|
}
|
|
667
673
|
}
|
|
668
674
|
else {
|
|
669
|
-
debug(
|
|
675
|
+
debug("[%s] Encountered unknown message type with id %d", this.remoteAddress, message.type);
|
|
670
676
|
}
|
|
671
677
|
}
|
|
672
678
|
});
|
|
@@ -681,13 +687,13 @@ export class DataStreamConnection extends EventEmitter {
|
|
|
681
687
|
for (let frameBegin = 0; frameBegin < totalBufferLength;) {
|
|
682
688
|
if (frameBegin + 4 > totalBufferLength) {
|
|
683
689
|
// we don't have enough data in the buffer for the next header
|
|
684
|
-
this.frameBuffer = data.
|
|
690
|
+
this.frameBuffer = data.slice(frameBegin);
|
|
685
691
|
break;
|
|
686
692
|
}
|
|
687
693
|
const payloadType = data.readUInt8(frameBegin); // type defining structure of payload; 8-bit; currently expected to be 1
|
|
688
694
|
const payloadLength = data.readUIntBE(frameBegin + 1, 3); // read 24-bit big-endian uint length field
|
|
689
695
|
if (payloadLength > DataStreamConnection.MAX_PAYLOAD_LENGTH) {
|
|
690
|
-
debug(
|
|
696
|
+
debug("[%s] Connection send payload with size bigger than the maximum allow for data stream", this.remoteAddress);
|
|
691
697
|
this.close();
|
|
692
698
|
return [];
|
|
693
699
|
}
|
|
@@ -695,38 +701,38 @@ export class DataStreamConnection extends EventEmitter {
|
|
|
695
701
|
// check if the data from this frame is already there (payload + 16-byte authTag)
|
|
696
702
|
if (payloadLength + 16 > remainingBufferLength) {
|
|
697
703
|
// Frame is fragmented, so we wait until we receive more
|
|
698
|
-
this.frameBuffer = data.
|
|
704
|
+
this.frameBuffer = data.slice(frameBegin);
|
|
699
705
|
break;
|
|
700
706
|
}
|
|
701
707
|
const payloadBegin = frameBegin + 4;
|
|
702
708
|
const authTagBegin = payloadBegin + payloadLength;
|
|
703
|
-
const header = data.
|
|
704
|
-
const cipheredPayload = data.
|
|
709
|
+
const header = data.slice(frameBegin, payloadBegin); // header is also authenticated using authTag
|
|
710
|
+
const cipheredPayload = data.slice(payloadBegin, authTagBegin);
|
|
705
711
|
const plaintextPayload = Buffer.alloc(payloadLength);
|
|
706
|
-
const authTag = data.
|
|
712
|
+
const authTag = data.slice(authTagBegin, authTagBegin + 16);
|
|
707
713
|
frameBegin = authTagBegin + 16; // move to next frame
|
|
708
714
|
if (payloadType === 1) {
|
|
709
715
|
const hdsFrame = {
|
|
710
|
-
header,
|
|
711
|
-
cipheredPayload,
|
|
712
|
-
authTag,
|
|
716
|
+
header: header,
|
|
717
|
+
cipheredPayload: cipheredPayload,
|
|
718
|
+
authTag: authTag,
|
|
713
719
|
};
|
|
714
720
|
frames.push(hdsFrame);
|
|
715
721
|
}
|
|
716
722
|
else {
|
|
717
|
-
debug(
|
|
723
|
+
debug("[%s] Encountered unknown payload type %d for payload: %s", this.remoteAddress, plaintextPayload.toString("hex"));
|
|
718
724
|
}
|
|
719
725
|
}
|
|
720
726
|
return frames;
|
|
721
727
|
}
|
|
722
728
|
/**
|
|
723
|
-
* @private
|
|
729
|
+
* @private file-private API
|
|
724
730
|
*/
|
|
725
731
|
decryptHDSFrame(frame, keyOverwrite) {
|
|
726
|
-
writeUInt64LE(this.controllerToAccessoryNonce, this.controllerToAccessoryNonceBuffer, 0); // update nonce buffer
|
|
732
|
+
hapCrypto.writeUInt64LE(this.controllerToAccessoryNonce, this.controllerToAccessoryNonceBuffer, 0); // update nonce buffer
|
|
727
733
|
const key = keyOverwrite || this.controllerToAccessoryEncryptionKey;
|
|
728
734
|
try {
|
|
729
|
-
frame.plaintextPayload = chacha20_poly1305_decryptAndVerify(key, this.controllerToAccessoryNonceBuffer, frame.header, frame.cipheredPayload, frame.authTag);
|
|
735
|
+
frame.plaintextPayload = hapCrypto.chacha20_poly1305_decryptAndVerify(key, this.controllerToAccessoryNonceBuffer, frame.header, frame.cipheredPayload, frame.authTag);
|
|
730
736
|
this.controllerToAccessoryNonce++; // we had a successful encryption, increment the nonce
|
|
731
737
|
return true;
|
|
732
738
|
}
|
|
@@ -737,40 +743,42 @@ export class DataStreamConnection extends EventEmitter {
|
|
|
737
743
|
}
|
|
738
744
|
decodePayloads(frames) {
|
|
739
745
|
const messages = [];
|
|
740
|
-
frames.forEach(
|
|
746
|
+
frames.forEach(frame => {
|
|
741
747
|
const payload = frame.plaintextPayload;
|
|
742
748
|
if (!payload) {
|
|
743
|
-
throw new HDSConnectionError(
|
|
749
|
+
throw new HDSConnectionError("Reached illegal state. Encountered HDSFrame with wasn't decrypted yet!", 1 /* HDSConnectionErrorType.ILLEGAL_STATE */);
|
|
744
750
|
}
|
|
745
751
|
const headerLength = payload.readUInt8(0);
|
|
746
752
|
const messageLength = payload.length - headerLength - 1;
|
|
747
753
|
const headerBegin = 1;
|
|
748
754
|
const messageBegin = headerBegin + headerLength;
|
|
749
|
-
const headerPayload = new DataStreamReader(payload.
|
|
750
|
-
const messagePayload = new DataStreamReader(payload.
|
|
755
|
+
const headerPayload = new DataStreamParser_1.DataStreamReader(payload.slice(headerBegin, headerBegin + headerLength));
|
|
756
|
+
const messagePayload = new DataStreamParser_1.DataStreamReader(payload.slice(messageBegin, messageBegin + messageLength));
|
|
757
|
+
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
751
758
|
let headerDictionary;
|
|
759
|
+
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
752
760
|
let messageDictionary;
|
|
753
761
|
try {
|
|
754
|
-
headerDictionary = DataStreamParser.decode(headerPayload);
|
|
762
|
+
headerDictionary = DataStreamParser_1.DataStreamParser.decode(headerPayload);
|
|
755
763
|
headerPayload.finished();
|
|
756
764
|
}
|
|
757
765
|
catch (error) {
|
|
758
|
-
debug(
|
|
766
|
+
debug("[%s] Failed to decode header payload: %s", this.remoteAddress, error.message);
|
|
759
767
|
return;
|
|
760
768
|
}
|
|
761
769
|
try {
|
|
762
|
-
messageDictionary = DataStreamParser.decode(messagePayload);
|
|
770
|
+
messageDictionary = DataStreamParser_1.DataStreamParser.decode(messagePayload);
|
|
763
771
|
messagePayload.finished();
|
|
764
772
|
}
|
|
765
773
|
catch (error) {
|
|
766
|
-
debug(
|
|
774
|
+
debug("[%s] Failed to decode message payload: %s (header: %o)", this.remoteAddress, error.message, headerDictionary);
|
|
767
775
|
return;
|
|
768
776
|
}
|
|
769
777
|
let type;
|
|
770
778
|
const protocol = headerDictionary.protocol;
|
|
771
779
|
let topic;
|
|
772
|
-
let id;
|
|
773
|
-
let status;
|
|
780
|
+
let id = undefined;
|
|
781
|
+
let status = undefined;
|
|
774
782
|
if (headerDictionary.event !== undefined) {
|
|
775
783
|
type = 1 /* MessageType.EVENT */;
|
|
776
784
|
topic = headerDictionary.event;
|
|
@@ -787,43 +795,44 @@ export class DataStreamConnection extends EventEmitter {
|
|
|
787
795
|
status = headerDictionary.status;
|
|
788
796
|
}
|
|
789
797
|
else {
|
|
790
|
-
debug(
|
|
798
|
+
debug("[%s] Encountered unknown payload header format: %o (message: %o)", this.remoteAddress, headerDictionary, messageDictionary);
|
|
791
799
|
return;
|
|
792
800
|
}
|
|
793
801
|
const message = {
|
|
794
|
-
type,
|
|
795
|
-
protocol,
|
|
796
|
-
topic,
|
|
797
|
-
id,
|
|
798
|
-
status,
|
|
802
|
+
type: type,
|
|
803
|
+
protocol: protocol,
|
|
804
|
+
topic: topic,
|
|
805
|
+
id: id,
|
|
806
|
+
status: status,
|
|
799
807
|
message: messageDictionary,
|
|
800
808
|
};
|
|
801
809
|
messages.push(message);
|
|
802
810
|
});
|
|
803
811
|
return messages;
|
|
804
812
|
}
|
|
813
|
+
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
805
814
|
sendHDSFrame(header, message) {
|
|
806
815
|
if (this.state >= 3 /* ConnectionState.CLOSING */) {
|
|
807
|
-
throw new HDSConnectionError(
|
|
816
|
+
throw new HDSConnectionError("Cannot send message on closing/closed socket!", 2 /* HDSConnectionErrorType.CLOSED_SOCKET */);
|
|
808
817
|
}
|
|
809
|
-
const headerWriter = new DataStreamWriter();
|
|
810
|
-
const messageWriter = new DataStreamWriter();
|
|
811
|
-
DataStreamParser.encode(header, headerWriter);
|
|
812
|
-
DataStreamParser.encode(message, messageWriter);
|
|
818
|
+
const headerWriter = new DataStreamParser_1.DataStreamWriter();
|
|
819
|
+
const messageWriter = new DataStreamParser_1.DataStreamWriter();
|
|
820
|
+
DataStreamParser_1.DataStreamParser.encode(header, headerWriter);
|
|
821
|
+
DataStreamParser_1.DataStreamParser.encode(message, messageWriter);
|
|
813
822
|
const payloadHeaderBuffer = Buffer.alloc(1);
|
|
814
823
|
payloadHeaderBuffer.writeUInt8(headerWriter.length(), 0);
|
|
815
824
|
const payloadBuffer = Buffer.concat([payloadHeaderBuffer, headerWriter.getData(), messageWriter.getData()]);
|
|
816
825
|
if (payloadBuffer.length > DataStreamConnection.MAX_PAYLOAD_LENGTH) {
|
|
817
|
-
throw new HDSConnectionError(
|
|
826
|
+
throw new HDSConnectionError("Tried sending payload with length larger than the maximum allowed for data stream", 3 /* HDSConnectionErrorType.MAX_PAYLOAD_LENGTH */);
|
|
818
827
|
}
|
|
819
828
|
const frameTypeBuffer = Buffer.alloc(1);
|
|
820
829
|
frameTypeBuffer.writeUInt8(1, 0);
|
|
821
830
|
let frameLengthBuffer = Buffer.alloc(4);
|
|
822
831
|
frameLengthBuffer.writeUInt32BE(payloadBuffer.length, 0);
|
|
823
|
-
frameLengthBuffer = frameLengthBuffer.
|
|
832
|
+
frameLengthBuffer = frameLengthBuffer.slice(1, 4); // a bit hacky but the only real way to write 24-bit int in node
|
|
824
833
|
const frameHeader = Buffer.concat([frameTypeBuffer, frameLengthBuffer]);
|
|
825
|
-
writeUInt64LE(this.accessoryToControllerNonce++, this.accessoryToControllerNonceBuffer);
|
|
826
|
-
const encrypted = chacha20_poly1305_encryptAndSeal(this.accessoryToControllerEncryptionKey, this.accessoryToControllerNonceBuffer, frameHeader, payloadBuffer);
|
|
834
|
+
hapCrypto.writeUInt64LE(this.accessoryToControllerNonce++, this.accessoryToControllerNonceBuffer);
|
|
835
|
+
const encrypted = hapCrypto.chacha20_poly1305_encryptAndSeal(this.accessoryToControllerEncryptionKey, this.accessoryToControllerNonceBuffer, frameHeader, payloadBuffer);
|
|
827
836
|
this.socket.write(Buffer.concat([frameHeader, encrypted.ciphertext, encrypted.authTag]));
|
|
828
837
|
/* Useful for debugging outgoing packages and detecting encoding errors
|
|
829
838
|
console.log("SENT DATA: " + payloadBuffer.toString("hex"));
|
|
@@ -835,7 +844,7 @@ export class DataStreamConnection extends EventEmitter {
|
|
|
835
844
|
};
|
|
836
845
|
const sentMessage = this.decodePayloads([frame])[0];
|
|
837
846
|
console.log("Sent message: " + JSON.stringify(sentMessage, null, 4));
|
|
838
|
-
|
|
847
|
+
//*/
|
|
839
848
|
}
|
|
840
849
|
close() {
|
|
841
850
|
if (this.state >= 3 /* ConnectionState.CLOSING */) {
|
|
@@ -849,11 +858,11 @@ export class DataStreamConnection extends EventEmitter {
|
|
|
849
858
|
}
|
|
850
859
|
onHAPSessionClosed() {
|
|
851
860
|
// If the hap connection is closed it is probably also a good idea to close the data stream connection
|
|
852
|
-
debug(
|
|
861
|
+
debug("[%s] HAP connection disconnected. Also closing DataStream connection now.", this.remoteAddress);
|
|
853
862
|
this.close();
|
|
854
863
|
}
|
|
855
864
|
onSocketError(error) {
|
|
856
|
-
debug(
|
|
865
|
+
debug("[%s] Encountered socket error: %s", this.remoteAddress, error.message);
|
|
857
866
|
// onSocketClose will be called next
|
|
858
867
|
}
|
|
859
868
|
onSocketClose() {
|
|
@@ -865,4 +874,5 @@ export class DataStreamConnection extends EventEmitter {
|
|
|
865
874
|
this.removeAllListeners();
|
|
866
875
|
}
|
|
867
876
|
}
|
|
877
|
+
exports.DataStreamConnection = DataStreamConnection;
|
|
868
878
|
//# sourceMappingURL=DataStreamServer.js.map
|