hap-nodejs 1.0.0-beta.2 → 1.0.0-beta.3
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 +4 -3
- package/@types/simple-plist.d.ts +2 -1
- package/README.md +2 -1
- package/dist/BridgedCore.js +7 -5
- package/dist/BridgedCore.js.map +1 -1
- package/dist/Core.js +14 -8
- package/dist/Core.js.map +1 -1
- package/dist/accessories/AirConditioner_accessory.d.ts +2 -0
- package/dist/accessories/AirConditioner_accessory.d.ts.map +1 -0
- package/dist/accessories/AirConditioner_accessory.js +128 -0
- package/dist/accessories/AirConditioner_accessory.js.map +1 -0
- package/dist/accessories/AppleTVRemote_accessory.d.ts +2 -0
- package/dist/accessories/AppleTVRemote_accessory.d.ts.map +1 -0
- package/dist/accessories/AppleTVRemote_accessory.js +159 -0
- package/dist/accessories/AppleTVRemote_accessory.js.map +1 -0
- package/dist/accessories/Camera_accessory.d.ts +2 -0
- package/dist/accessories/Camera_accessory.d.ts.map +1 -0
- package/dist/accessories/Camera_accessory.js +630 -0
- package/dist/accessories/Camera_accessory.js.map +1 -0
- package/dist/accessories/Fan_accessory.d.ts +2 -0
- package/dist/accessories/Fan_accessory.d.ts.map +1 -0
- package/dist/accessories/Fan_accessory.js +80 -0
- package/dist/accessories/Fan_accessory.js.map +1 -0
- package/dist/accessories/GarageDoorOpener_accessory.d.ts +2 -0
- package/dist/accessories/GarageDoorOpener_accessory.d.ts.map +1 -0
- package/dist/accessories/GarageDoorOpener_accessory.js +78 -0
- package/dist/accessories/GarageDoorOpener_accessory.js.map +1 -0
- package/dist/accessories/Light-AdaptiveLighting_accessory.d.ts +2 -0
- package/dist/accessories/Light-AdaptiveLighting_accessory.d.ts.map +1 -0
- package/dist/accessories/Light-AdaptiveLighting_accessory.js +96 -0
- package/dist/accessories/Light-AdaptiveLighting_accessory.js.map +1 -0
- package/dist/accessories/Light_accessory.d.ts +2 -0
- package/dist/accessories/Light_accessory.d.ts.map +1 -0
- package/dist/accessories/Light_accessory.js +148 -0
- package/dist/accessories/Light_accessory.js.map +1 -0
- package/dist/accessories/Lock_accessory.d.ts +2 -0
- package/dist/accessories/Lock_accessory.d.ts.map +1 -0
- package/dist/accessories/Lock_accessory.js +76 -0
- package/dist/accessories/Lock_accessory.js.map +1 -0
- package/dist/accessories/MotionSensor_accessory.d.ts +2 -0
- package/dist/accessories/MotionSensor_accessory.d.ts.map +1 -0
- package/dist/accessories/MotionSensor_accessory.js +45 -0
- package/dist/accessories/MotionSensor_accessory.js.map +1 -0
- package/dist/accessories/Outlet_accessory.d.ts +2 -0
- package/dist/accessories/Outlet_accessory.d.ts.map +1 -0
- package/dist/accessories/Outlet_accessory.js +79 -0
- package/dist/accessories/Outlet_accessory.js.map +1 -0
- package/dist/accessories/SmartSpeaker_accessory.d.ts +2 -0
- package/dist/accessories/SmartSpeaker_accessory.d.ts.map +1 -0
- package/dist/accessories/SmartSpeaker_accessory.js +44 -0
- package/dist/accessories/SmartSpeaker_accessory.js.map +1 -0
- package/dist/accessories/Sprinkler_accessory.d.ts +2 -0
- package/dist/accessories/Sprinkler_accessory.d.ts.map +1 -0
- package/dist/accessories/Sprinkler_accessory.js +128 -0
- package/dist/accessories/Sprinkler_accessory.js.map +1 -0
- package/dist/accessories/TV_accessory.d.ts +2 -0
- package/dist/accessories/TV_accessory.d.ts.map +1 -0
- package/dist/accessories/TV_accessory.js +101 -0
- package/dist/accessories/TV_accessory.js.map +1 -0
- package/dist/accessories/TemperatureSensor_accessory.d.ts +2 -0
- package/dist/accessories/TemperatureSensor_accessory.d.ts.map +1 -0
- package/dist/accessories/TemperatureSensor_accessory.js +44 -0
- package/dist/accessories/TemperatureSensor_accessory.js.map +1 -0
- package/dist/accessories/Wi-FiRouter_accessory.d.ts +3 -0
- package/dist/accessories/Wi-FiRouter_accessory.d.ts.map +1 -0
- package/dist/accessories/Wi-FiRouter_accessory.js +17 -0
- package/dist/accessories/Wi-FiRouter_accessory.js.map +1 -0
- package/dist/accessories/Wi-FiSatellite_accessory.d.ts +3 -0
- package/dist/accessories/Wi-FiSatellite_accessory.d.ts.map +1 -0
- package/dist/accessories/Wi-FiSatellite_accessory.js +19 -0
- package/dist/accessories/Wi-FiSatellite_accessory.js.map +1 -0
- package/dist/accessories/gstreamer-audioProducer.d.ts +25 -0
- package/dist/accessories/gstreamer-audioProducer.d.ts.map +1 -0
- package/dist/accessories/gstreamer-audioProducer.js +155 -0
- package/dist/accessories/gstreamer-audioProducer.js.map +1 -0
- package/dist/accessories/types.d.ts +78 -0
- package/dist/accessories/types.d.ts.map +1 -0
- package/dist/accessories/types.js +88 -0
- package/dist/accessories/types.js.map +1 -0
- package/dist/index.d.ts +54 -27
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +34 -11
- package/dist/index.js.map +1 -1
- package/dist/internal-types.d.ts +65 -124
- package/dist/internal-types.d.ts.map +1 -1
- package/dist/internal-types.js +66 -5
- package/dist/internal-types.js.map +1 -1
- package/dist/lib/Accessory.d.ts +147 -60
- package/dist/lib/Accessory.d.ts.map +1 -1
- package/dist/lib/Accessory.js +566 -475
- package/dist/lib/Accessory.js.map +1 -1
- package/dist/lib/AccessoryLoader.d.ts +20 -8
- package/dist/lib/AccessoryLoader.d.ts.map +1 -1
- package/dist/lib/AccessoryLoader.js +115 -93
- package/dist/lib/AccessoryLoader.js.map +1 -1
- package/dist/lib/Advertiser.d.ts +99 -5
- package/dist/lib/Advertiser.d.ts.map +1 -1
- package/dist/lib/Advertiser.js +564 -22
- package/dist/lib/Advertiser.js.map +1 -1
- package/dist/lib/Bridge.d.ts +3 -1
- package/dist/lib/Bridge.d.ts.map +1 -1
- package/dist/lib/Bridge.js +2 -0
- package/dist/lib/Bridge.js.map +1 -1
- package/dist/lib/Characteristic.d.ts +918 -59
- package/dist/lib/Characteristic.d.ts.map +1 -1
- package/dist/lib/Characteristic.js +308 -257
- package/dist/lib/Characteristic.js.map +1 -1
- package/dist/lib/HAPServer.d.ts +114 -43
- package/dist/lib/HAPServer.d.ts.map +1 -1
- package/dist/lib/HAPServer.js +269 -405
- package/dist/lib/HAPServer.js.map +1 -1
- package/dist/lib/Service.d.ts +339 -15
- package/dist/lib/Service.d.ts.map +1 -1
- package/dist/lib/Service.js +59 -50
- package/dist/lib/Service.js.map +1 -1
- package/dist/lib/camera/Camera.d.ts +15 -6
- package/dist/lib/camera/Camera.d.ts.map +1 -1
- package/dist/lib/camera/Camera.js +6 -3
- package/dist/lib/camera/Camera.js.map +1 -1
- package/dist/lib/camera/RTPProxy.d.ts +24 -19
- package/dist/lib/camera/RTPProxy.d.ts.map +1 -1
- package/dist/lib/camera/RTPProxy.js +230 -207
- package/dist/lib/camera/RTPProxy.js.map +1 -1
- package/dist/lib/camera/RTPStreamManagement.d.ts +202 -43
- package/dist/lib/camera/RTPStreamManagement.d.ts.map +1 -1
- package/dist/lib/camera/RTPStreamManagement.js +303 -189
- package/dist/lib/camera/RTPStreamManagement.js.map +1 -1
- package/dist/lib/camera/RecordingManagement.d.ts +326 -0
- package/dist/lib/camera/RecordingManagement.d.ts.map +1 -0
- package/dist/lib/camera/RecordingManagement.js +833 -0
- package/dist/lib/camera/RecordingManagement.js.map +1 -0
- package/dist/lib/camera/index.d.ts +4 -3
- package/dist/lib/camera/index.d.ts.map +1 -1
- package/dist/lib/camera/index.js +1 -0
- package/dist/lib/camera/index.js.map +1 -1
- package/dist/lib/controller/AdaptiveLightingController.d.ts +37 -11
- package/dist/lib/controller/AdaptiveLightingController.d.ts.map +1 -1
- package/dist/lib/controller/AdaptiveLightingController.js +101 -86
- package/dist/lib/controller/AdaptiveLightingController.js.map +1 -1
- package/dist/lib/controller/CameraController.d.ts +290 -12
- package/dist/lib/controller/CameraController.d.ts.map +1 -1
- package/dist/lib/controller/CameraController.js +403 -47
- package/dist/lib/controller/CameraController.js.map +1 -1
- package/dist/lib/controller/Controller.d.ts +31 -10
- package/dist/lib/controller/Controller.d.ts.map +1 -1
- package/dist/lib/controller/Controller.js +7 -0
- package/dist/lib/controller/Controller.js.map +1 -1
- package/dist/lib/controller/DoorbellController.d.ts +47 -1
- package/dist/lib/controller/DoorbellController.d.ts.map +1 -1
- package/dist/lib/controller/DoorbellController.js +65 -11
- package/dist/lib/controller/DoorbellController.js.map +1 -1
- package/dist/lib/controller/RemoteController.d.ts +111 -42
- package/dist/lib/controller/RemoteController.d.ts.map +1 -1
- package/dist/lib/controller/RemoteController.js +228 -203
- package/dist/lib/controller/RemoteController.js.map +1 -1
- package/dist/lib/controller/index.d.ts +4 -4
- package/dist/lib/datastream/DataStreamManagement.d.ts +25 -19
- package/dist/lib/datastream/DataStreamManagement.d.ts.map +1 -1
- package/dist/lib/datastream/DataStreamManagement.js +42 -35
- package/dist/lib/datastream/DataStreamManagement.js.map +1 -1
- package/dist/lib/datastream/DataStreamParser.d.ts +63 -24
- package/dist/lib/datastream/DataStreamParser.d.ts.map +1 -1
- package/dist/lib/datastream/DataStreamParser.js +132 -86
- package/dist/lib/datastream/DataStreamParser.js.map +1 -1
- package/dist/lib/datastream/DataStreamServer.d.ts +154 -50
- package/dist/lib/datastream/DataStreamServer.d.ts.map +1 -1
- package/dist/lib/datastream/DataStreamServer.js +242 -147
- package/dist/lib/datastream/DataStreamServer.js.map +1 -1
- package/dist/lib/datastream/index.d.ts +3 -3
- package/dist/lib/definitions/CharacteristicDefinitions.d.ts +181 -0
- package/dist/lib/definitions/CharacteristicDefinitions.d.ts.map +1 -1
- package/dist/lib/definitions/CharacteristicDefinitions.js +968 -499
- package/dist/lib/definitions/CharacteristicDefinitions.js.map +1 -1
- package/dist/lib/definitions/ServiceDefinitions.d.ts +58 -0
- package/dist/lib/definitions/ServiceDefinitions.d.ts.map +1 -1
- package/dist/lib/definitions/ServiceDefinitions.js +173 -6
- package/dist/lib/definitions/ServiceDefinitions.js.map +1 -1
- package/dist/lib/definitions/generate-definitions.d.ts +1 -0
- package/dist/lib/definitions/generate-definitions.d.ts.map +1 -1
- package/dist/lib/definitions/generate-definitions.js +29 -21
- package/dist/lib/definitions/generate-definitions.js.map +1 -1
- package/dist/lib/definitions/generator-configuration.d.ts.map +1 -1
- package/dist/lib/definitions/generator-configuration.js +62 -29
- package/dist/lib/definitions/generator-configuration.js.map +1 -1
- package/dist/lib/model/AccessoryInfo.d.ts +16 -13
- package/dist/lib/model/AccessoryInfo.d.ts.map +1 -1
- package/dist/lib/model/AccessoryInfo.js +88 -83
- package/dist/lib/model/AccessoryInfo.js.map +1 -1
- package/dist/lib/model/ControllerStorage.d.ts +3 -0
- package/dist/lib/model/ControllerStorage.d.ts.map +1 -1
- package/dist/lib/model/ControllerStorage.js +7 -4
- package/dist/lib/model/ControllerStorage.js.map +1 -1
- package/dist/lib/model/HAPStorage.d.ts +3 -0
- package/dist/lib/model/HAPStorage.d.ts.map +1 -1
- package/dist/lib/model/HAPStorage.js +4 -0
- package/dist/lib/model/HAPStorage.js.map +1 -1
- package/dist/lib/model/IdentifierCache.d.ts +12 -11
- package/dist/lib/model/IdentifierCache.d.ts.map +1 -1
- package/dist/lib/model/IdentifierCache.js +68 -65
- package/dist/lib/model/IdentifierCache.js.map +1 -1
- package/dist/lib/tv/AccessControlManagement.d.ts +12 -1
- package/dist/lib/tv/AccessControlManagement.d.ts.map +1 -1
- package/dist/lib/tv/AccessControlManagement.js +13 -5
- package/dist/lib/tv/AccessControlManagement.js.map +1 -1
- package/dist/lib/util/clone.d.ts +2 -1
- package/dist/lib/util/clone.d.ts.map +1 -1
- package/dist/lib/util/clone.js +2 -0
- package/dist/lib/util/clone.js.map +1 -1
- package/dist/lib/util/color-utils.d.ts +4 -1
- package/dist/lib/util/color-utils.d.ts.map +1 -1
- package/dist/lib/util/color-utils.js +5 -2
- package/dist/lib/util/color-utils.js.map +1 -1
- package/dist/lib/util/eventedhttp.d.ts +62 -22
- package/dist/lib/util/eventedhttp.d.ts.map +1 -1
- package/dist/lib/util/eventedhttp.js +236 -180
- package/dist/lib/util/eventedhttp.js.map +1 -1
- package/dist/lib/util/hapCrypto.d.ts +35 -7
- package/dist/lib/util/hapCrypto.d.ts.map +1 -1
- package/dist/lib/util/hapCrypto.js +86 -78
- package/dist/lib/util/hapCrypto.js.map +1 -1
- package/dist/lib/util/hapStatusError.d.ts +2 -0
- package/dist/lib/util/hapStatusError.d.ts.map +1 -1
- package/dist/lib/util/hapStatusError.js +5 -3
- package/dist/lib/util/hapStatusError.js.map +1 -1
- package/dist/lib/util/net-utils.d.ts +7 -0
- package/dist/lib/util/net-utils.d.ts.map +1 -1
- package/dist/lib/util/net-utils.js +11 -4
- package/dist/lib/util/net-utils.js.map +1 -1
- package/dist/lib/util/once.d.ts +6 -1
- package/dist/lib/util/once.d.ts.map +1 -1
- package/dist/lib/util/once.js +9 -3
- package/dist/lib/util/once.js.map +1 -1
- package/dist/lib/util/promise-utils.d.ts +15 -0
- package/dist/lib/util/promise-utils.d.ts.map +1 -0
- package/dist/lib/util/promise-utils.js +36 -0
- package/dist/lib/util/promise-utils.js.map +1 -0
- package/dist/lib/util/request-util.d.ts +16 -0
- package/dist/lib/util/request-util.d.ts.map +1 -1
- package/dist/lib/util/request-util.js +43 -27
- package/dist/lib/util/request-util.js.map +1 -1
- package/dist/lib/util/time.d.ts +7 -1
- package/dist/lib/util/time.d.ts.map +1 -1
- package/dist/lib/util/time.js +13 -7
- package/dist/lib/util/time.js.map +1 -1
- package/dist/lib/util/tlv.d.ts +95 -5
- package/dist/lib/util/tlv.d.ts.map +1 -1
- package/dist/lib/util/tlv.js +96 -24
- package/dist/lib/util/tlv.js.map +1 -1
- package/dist/lib/util/uuid.d.ts +2 -3
- package/dist/lib/util/uuid.d.ts.map +1 -1
- package/dist/lib/util/uuid.js +25 -19
- package/dist/lib/util/uuid.js.map +1 -1
- package/dist/types.d.ts +271 -18
- package/dist/types.d.ts.map +1 -1
- package/dist/types.js +8 -0
- package/dist/types.js.map +1 -1
- package/package.json +28 -27
- package/dist/lib/util/setupcode.d.ts +0 -5
- package/dist/lib/util/setupcode.d.ts.map +0 -1
- package/dist/lib/util/setupcode.js +0 -49
- package/dist/lib/util/setupcode.js.map +0 -1
- package/dist/lib/util/setupid.d.ts +0 -5
- package/dist/lib/util/setupid.d.ts.map +0 -1
- package/dist/lib/util/setupid.js +0 -52
- package/dist/lib/util/setupid.js.map +0 -1
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.DataStreamConnection = exports.DataStreamConnectionEvent = exports.DataStreamServer = exports.DataStreamServerEvent = exports.
|
|
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
4
|
var tslib_1 = require("tslib");
|
|
5
5
|
var assert_1 = tslib_1.__importDefault(require("assert"));
|
|
6
6
|
var crypto_1 = tslib_1.__importDefault(require("crypto"));
|
|
@@ -9,13 +9,19 @@ var events_1 = require("events");
|
|
|
9
9
|
var net_1 = tslib_1.__importDefault(require("net"));
|
|
10
10
|
var hapCrypto = tslib_1.__importStar(require("../util/hapCrypto"));
|
|
11
11
|
var DataStreamParser_1 = require("./DataStreamParser");
|
|
12
|
-
var debug = debug_1.default(
|
|
12
|
+
var debug = (0, debug_1.default)("HAP-NodeJS:DataStream:Server");
|
|
13
|
+
/**
|
|
14
|
+
* @group HomeKit Data Streams (HDS)
|
|
15
|
+
*/
|
|
13
16
|
var Protocols;
|
|
14
17
|
(function (Protocols) {
|
|
15
18
|
Protocols["CONTROL"] = "control";
|
|
16
19
|
Protocols["TARGET_CONTROL"] = "targetControl";
|
|
17
20
|
Protocols["DATA_SEND"] = "dataSend";
|
|
18
21
|
})(Protocols = exports.Protocols || (exports.Protocols = {}));
|
|
22
|
+
/**
|
|
23
|
+
* @group HomeKit Data Streams (HDS)
|
|
24
|
+
*/
|
|
19
25
|
var Topics;
|
|
20
26
|
(function (Topics) {
|
|
21
27
|
// control
|
|
@@ -28,6 +34,9 @@ var Topics;
|
|
|
28
34
|
Topics["ACK"] = "ack";
|
|
29
35
|
Topics["CLOSE"] = "close";
|
|
30
36
|
})(Topics = exports.Topics || (exports.Topics = {}));
|
|
37
|
+
/**
|
|
38
|
+
* @group HomeKit Data Streams (HDS)
|
|
39
|
+
*/
|
|
31
40
|
var HDSStatus;
|
|
32
41
|
(function (HDSStatus) {
|
|
33
42
|
// noinspection JSUnusedGlobalSymbols
|
|
@@ -39,17 +48,44 @@ var HDSStatus;
|
|
|
39
48
|
HDSStatus[HDSStatus["MISSING_PROTOCOL"] = 5] = "MISSING_PROTOCOL";
|
|
40
49
|
HDSStatus[HDSStatus["PROTOCOL_SPECIFIC_ERROR"] = 6] = "PROTOCOL_SPECIFIC_ERROR";
|
|
41
50
|
})(HDSStatus = exports.HDSStatus || (exports.HDSStatus = {}));
|
|
42
|
-
|
|
43
|
-
|
|
51
|
+
/**
|
|
52
|
+
* @group HomeKit Data Streams (HDS)
|
|
53
|
+
*/
|
|
54
|
+
var HDSProtocolSpecificErrorReason;
|
|
55
|
+
(function (HDSProtocolSpecificErrorReason) {
|
|
44
56
|
// noinspection JSUnusedGlobalSymbols
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
57
|
+
HDSProtocolSpecificErrorReason[HDSProtocolSpecificErrorReason["NORMAL"] = 0] = "NORMAL";
|
|
58
|
+
HDSProtocolSpecificErrorReason[HDSProtocolSpecificErrorReason["NOT_ALLOWED"] = 1] = "NOT_ALLOWED";
|
|
59
|
+
HDSProtocolSpecificErrorReason[HDSProtocolSpecificErrorReason["BUSY"] = 2] = "BUSY";
|
|
60
|
+
HDSProtocolSpecificErrorReason[HDSProtocolSpecificErrorReason["CANCELLED"] = 3] = "CANCELLED";
|
|
61
|
+
HDSProtocolSpecificErrorReason[HDSProtocolSpecificErrorReason["UNSUPPORTED"] = 4] = "UNSUPPORTED";
|
|
62
|
+
HDSProtocolSpecificErrorReason[HDSProtocolSpecificErrorReason["UNEXPECTED_FAILURE"] = 5] = "UNEXPECTED_FAILURE";
|
|
63
|
+
HDSProtocolSpecificErrorReason[HDSProtocolSpecificErrorReason["TIMEOUT"] = 6] = "TIMEOUT";
|
|
64
|
+
HDSProtocolSpecificErrorReason[HDSProtocolSpecificErrorReason["BAD_DATA"] = 7] = "BAD_DATA";
|
|
65
|
+
HDSProtocolSpecificErrorReason[HDSProtocolSpecificErrorReason["PROTOCOL_ERROR"] = 8] = "PROTOCOL_ERROR";
|
|
66
|
+
HDSProtocolSpecificErrorReason[HDSProtocolSpecificErrorReason["INVALID_CONFIGURATION"] = 9] = "INVALID_CONFIGURATION";
|
|
67
|
+
})(HDSProtocolSpecificErrorReason = exports.HDSProtocolSpecificErrorReason || (exports.HDSProtocolSpecificErrorReason = {}));
|
|
68
|
+
/**
|
|
69
|
+
* An error indicating a protocol level HDS error.
|
|
70
|
+
* E.g. it may be used to encode a {@link HDSStatus.PROTOCOL_SPECIFIC_ERROR} in the {@link Protocols.DATA_SEND} protocol.
|
|
71
|
+
* @group HomeKit Data Streams (HDS)
|
|
72
|
+
*/
|
|
73
|
+
var HDSProtocolError = /** @class */ (function (_super) {
|
|
74
|
+
tslib_1.__extends(HDSProtocolError, _super);
|
|
75
|
+
/**
|
|
76
|
+
* Initializes a new `HDSProtocolError`
|
|
77
|
+
* @param reason - The {@link HDSProtocolSpecificErrorReason}.
|
|
78
|
+
* Values MUST NOT be {@link HDSProtocolSpecificErrorReason.NORMAL}.
|
|
79
|
+
*/
|
|
80
|
+
function HDSProtocolError(reason) {
|
|
81
|
+
var _this = _super.call(this, "HDSProtocolError: " + reason) || this;
|
|
82
|
+
(0, assert_1.default)(reason !== 0 /* HDSProtocolSpecificErrorReason.NORMAL */, "Cannot initialize a HDSProtocolError with NORMAL!");
|
|
83
|
+
_this.reason = reason;
|
|
84
|
+
return _this;
|
|
85
|
+
}
|
|
86
|
+
return HDSProtocolError;
|
|
87
|
+
}(Error));
|
|
88
|
+
exports.HDSProtocolError = HDSProtocolError;
|
|
53
89
|
var ServerState;
|
|
54
90
|
(function (ServerState) {
|
|
55
91
|
ServerState[ServerState["UNINITIALIZED"] = 0] = "UNINITIALIZED";
|
|
@@ -65,12 +101,18 @@ var ConnectionState;
|
|
|
65
101
|
ConnectionState[ConnectionState["CLOSING"] = 3] = "CLOSING";
|
|
66
102
|
ConnectionState[ConnectionState["CLOSED"] = 4] = "CLOSED";
|
|
67
103
|
})(ConnectionState || (ConnectionState = {}));
|
|
104
|
+
/**
|
|
105
|
+
* @group HomeKit Data Streams (HDS)
|
|
106
|
+
*/
|
|
68
107
|
var MessageType;
|
|
69
108
|
(function (MessageType) {
|
|
70
109
|
MessageType[MessageType["EVENT"] = 1] = "EVENT";
|
|
71
110
|
MessageType[MessageType["REQUEST"] = 2] = "REQUEST";
|
|
72
111
|
MessageType[MessageType["RESPONSE"] = 3] = "RESPONSE";
|
|
73
|
-
})(MessageType || (MessageType = {}));
|
|
112
|
+
})(MessageType = exports.MessageType || (exports.MessageType = {}));
|
|
113
|
+
/**
|
|
114
|
+
* @group HomeKit Data Streams (HDS)
|
|
115
|
+
*/
|
|
74
116
|
var DataStreamServerEvent;
|
|
75
117
|
(function (DataStreamServerEvent) {
|
|
76
118
|
/**
|
|
@@ -85,12 +127,13 @@ var DataStreamServerEvent;
|
|
|
85
127
|
})(DataStreamServerEvent = exports.DataStreamServerEvent || (exports.DataStreamServerEvent = {}));
|
|
86
128
|
/**
|
|
87
129
|
* DataStreamServer which listens for incoming tcp connections and handles identification of new connections
|
|
130
|
+
* @group HomeKit Data Streams (HDS)
|
|
88
131
|
*/
|
|
89
132
|
var DataStreamServer = /** @class */ (function (_super) {
|
|
90
133
|
tslib_1.__extends(DataStreamServer, _super);
|
|
91
134
|
function DataStreamServer() {
|
|
92
135
|
var _this = _super.call(this) || this;
|
|
93
|
-
_this.state = 0 /* UNINITIALIZED */;
|
|
136
|
+
_this.state = 0 /* ServerState.UNINITIALIZED */;
|
|
94
137
|
_this.preparedSessions = [];
|
|
95
138
|
_this.connections = [];
|
|
96
139
|
_this.removeListenersOnceClosed = false;
|
|
@@ -102,20 +145,20 @@ var DataStreamServer = /** @class */ (function (_super) {
|
|
|
102
145
|
* The handler is only called for a connection if for the give protocol no ProtocolHandler
|
|
103
146
|
* was registered on the connection level.
|
|
104
147
|
*
|
|
105
|
-
* @param protocol
|
|
106
|
-
* @param event
|
|
107
|
-
* @param handler
|
|
148
|
+
* @param protocol - name of the protocol to register the handler for
|
|
149
|
+
* @param event - name of the event (also referred to as topic. See {@link Topics} for some known ones)
|
|
150
|
+
* @param handler - function to be called for every occurring event
|
|
108
151
|
*/
|
|
109
152
|
DataStreamServer.prototype.onEventMessage = function (protocol, event, handler) {
|
|
110
153
|
this.internalEventEmitter.on(protocol + "-e-" + event, handler);
|
|
111
154
|
return this;
|
|
112
155
|
};
|
|
113
156
|
/**
|
|
114
|
-
* Removes
|
|
157
|
+
* Removes a registered event handler.
|
|
115
158
|
*
|
|
116
|
-
* @param protocol
|
|
117
|
-
* @param event
|
|
118
|
-
* @param handler
|
|
159
|
+
* @param protocol - name of the protocol to unregister the handler for
|
|
160
|
+
* @param event - name of the event (also referred to as topic. See {@link Topics} for some known ones)
|
|
161
|
+
* @param handler - registered event handler
|
|
119
162
|
*/
|
|
120
163
|
DataStreamServer.prototype.removeEventHandler = function (protocol, event, handler) {
|
|
121
164
|
this.internalEventEmitter.removeListener(protocol + "-e-" + event, handler);
|
|
@@ -126,20 +169,20 @@ var DataStreamServer = /** @class */ (function (_super) {
|
|
|
126
169
|
* The handler is only called for a connection if for the give protocol no ProtocolHandler
|
|
127
170
|
* was registered on the connection level.
|
|
128
171
|
*
|
|
129
|
-
* @param protocol
|
|
130
|
-
* @param request
|
|
131
|
-
* @param handler
|
|
172
|
+
* @param protocol - name of the protocol to register the handler for
|
|
173
|
+
* @param request - name of the request (also referred to as topic. See {@link Topics} for some known ones)
|
|
174
|
+
* @param handler - function to be called for every occurring request
|
|
132
175
|
*/
|
|
133
176
|
DataStreamServer.prototype.onRequestMessage = function (protocol, request, handler) {
|
|
134
177
|
this.internalEventEmitter.on(protocol + "-r-" + request, handler);
|
|
135
178
|
return this;
|
|
136
179
|
};
|
|
137
180
|
/**
|
|
138
|
-
* Removes
|
|
181
|
+
* Removes a registered request handler.
|
|
139
182
|
*
|
|
140
|
-
* @param protocol
|
|
141
|
-
* @param request
|
|
142
|
-
* @param handler
|
|
183
|
+
* @param protocol - name of the protocol to unregister the handler for
|
|
184
|
+
* @param request - name of the request (also referred to as topic. See {@link Topics} for some known ones)
|
|
185
|
+
* @param handler - registered request handler
|
|
143
186
|
*/
|
|
144
187
|
DataStreamServer.prototype.removeRequestHandler = function (protocol, request, handler) {
|
|
145
188
|
this.internalEventEmitter.removeListener(protocol + "-r-" + request, handler);
|
|
@@ -181,32 +224,32 @@ var DataStreamServer = /** @class */ (function (_super) {
|
|
|
181
224
|
DataStreamServer.prototype.checkTCPServerEstablished = function (preparedSession, callback) {
|
|
182
225
|
var _this = this;
|
|
183
226
|
switch (this.state) {
|
|
184
|
-
case 0 /* UNINITIALIZED */:
|
|
227
|
+
case 0 /* ServerState.UNINITIALIZED */:
|
|
185
228
|
debug("Starting up TCP server.");
|
|
186
229
|
this.tcpServer = net_1.default.createServer();
|
|
187
|
-
this.tcpServer.once(
|
|
188
|
-
this.tcpServer.on(
|
|
189
|
-
this.tcpServer.on(
|
|
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));
|
|
190
233
|
this.tcpServer.listen();
|
|
191
|
-
this.state = 1 /* BINDING */;
|
|
234
|
+
this.state = 1 /* ServerState.BINDING */;
|
|
192
235
|
break;
|
|
193
|
-
case 1 /* BINDING */:
|
|
236
|
+
case 1 /* ServerState.BINDING */:
|
|
194
237
|
debug("TCP server already running. Waiting for it to bind.");
|
|
195
|
-
this.tcpServer.once(
|
|
238
|
+
this.tcpServer.once("listening", this.listening.bind(this, preparedSession, callback));
|
|
196
239
|
break;
|
|
197
|
-
case 2 /* LISTENING */:
|
|
240
|
+
case 2 /* ServerState.LISTENING */:
|
|
198
241
|
debug("Instructing client to connect to already running TCP server");
|
|
199
242
|
preparedSession.port = this.tcpPort;
|
|
200
243
|
callback();
|
|
201
244
|
break;
|
|
202
|
-
case 3 /* CLOSING */:
|
|
245
|
+
case 3 /* ServerState.CLOSING */:
|
|
203
246
|
debug("TCP socket is currently closing. Trying again when server is fully closed and opening a new one then.");
|
|
204
|
-
this.tcpServer.once(
|
|
247
|
+
this.tcpServer.once("close", function () { return setTimeout(function () { return _this.checkTCPServerEstablished(preparedSession, callback); }, 10); });
|
|
205
248
|
break;
|
|
206
249
|
}
|
|
207
250
|
};
|
|
208
251
|
DataStreamServer.prototype.listening = function (preparedSession, callback) {
|
|
209
|
-
this.state = 2 /* LISTENING */;
|
|
252
|
+
this.state = 2 /* ServerState.LISTENING */;
|
|
210
253
|
var address = this.tcpServer.address();
|
|
211
254
|
if (address && typeof address !== "string") { // address is only typeof string when listening to a pipe or unix socket
|
|
212
255
|
this.tcpPort = address.port;
|
|
@@ -217,12 +260,13 @@ var DataStreamServer = /** @class */ (function (_super) {
|
|
|
217
260
|
};
|
|
218
261
|
DataStreamServer.prototype.onConnection = function (socket) {
|
|
219
262
|
debug("[%s] New DataStream connection was established", socket.remoteAddress);
|
|
263
|
+
// eslint-disable-next-line @typescript-eslint/no-use-before-define
|
|
220
264
|
var connection = new DataStreamConnection(socket);
|
|
221
|
-
connection.on("identification" /* IDENTIFICATION */, this.handleSessionIdentification.bind(this, connection));
|
|
222
|
-
connection.on("handle-message-globally" /* HANDLE_MESSAGE_GLOBALLY */, this.handleMessageGlobally.bind(this, connection));
|
|
223
|
-
connection.on("closed" /* CLOSED */, this.connectionClosed.bind(this, connection));
|
|
265
|
+
connection.on("identification" /* DataStreamConnectionEvent.IDENTIFICATION */, this.handleSessionIdentification.bind(this, connection));
|
|
266
|
+
connection.on("handle-message-globally" /* DataStreamConnectionEvent.HANDLE_MESSAGE_GLOBALLY */, this.handleMessageGlobally.bind(this, connection));
|
|
267
|
+
connection.on("closed" /* DataStreamConnectionEvent.CLOSED */, this.connectionClosed.bind(this, connection));
|
|
224
268
|
this.connections.push(connection);
|
|
225
|
-
this.emit("connection-opened" /* CONNECTION_OPENED */, connection);
|
|
269
|
+
this.emit("connection-opened" /* DataStreamServerEvent.CONNECTION_OPENED */, connection);
|
|
226
270
|
};
|
|
227
271
|
DataStreamServer.prototype.handleSessionIdentification = function (connection, firstFrame, callback) {
|
|
228
272
|
var identifiedSession = undefined;
|
|
@@ -254,20 +298,20 @@ var DataStreamServer = /** @class */ (function (_super) {
|
|
|
254
298
|
};
|
|
255
299
|
DataStreamServer.prototype.handleMessageGlobally = function (connection, message) {
|
|
256
300
|
var _a;
|
|
257
|
-
assert_1.default.notStrictEqual(message.type, 3 /* RESPONSE */); // responses can't physically get here
|
|
301
|
+
assert_1.default.notStrictEqual(message.type, 3 /* MessageType.RESPONSE */); // responses can't physically get here
|
|
258
302
|
var separator = "";
|
|
259
303
|
var args = [];
|
|
260
|
-
if (message.type === 1 /* EVENT */) {
|
|
304
|
+
if (message.type === 1 /* MessageType.EVENT */) {
|
|
261
305
|
separator = "-e-";
|
|
262
306
|
}
|
|
263
|
-
else if (message.type === 2 /* REQUEST */) {
|
|
307
|
+
else if (message.type === 2 /* MessageType.REQUEST */) {
|
|
264
308
|
separator = "-r-";
|
|
265
309
|
args.push(message.id);
|
|
266
310
|
}
|
|
267
311
|
args.push(message.message);
|
|
268
312
|
var hadListeners;
|
|
269
313
|
try {
|
|
270
|
-
hadListeners = (_a = this.internalEventEmitter).emit.apply(_a, tslib_1.__spreadArray([message.protocol + separator + message.topic, connection], tslib_1.__read(args)));
|
|
314
|
+
hadListeners = (_a = this.internalEventEmitter).emit.apply(_a, tslib_1.__spreadArray([message.protocol + separator + message.topic, connection], tslib_1.__read(args), false));
|
|
271
315
|
}
|
|
272
316
|
catch (error) {
|
|
273
317
|
hadListeners = true;
|
|
@@ -281,16 +325,16 @@ var DataStreamServer = /** @class */ (function (_super) {
|
|
|
281
325
|
DataStreamServer.prototype.connectionClosed = function (connection) {
|
|
282
326
|
debug("[%s] DataStream connection closed", connection.remoteAddress);
|
|
283
327
|
this.connections.splice(this.connections.indexOf(connection), 1);
|
|
284
|
-
this.emit("connection-closed" /* CONNECTION_CLOSED */, connection);
|
|
328
|
+
this.emit("connection-closed" /* DataStreamServerEvent.CONNECTION_CLOSED */, connection);
|
|
285
329
|
this.checkCloseable();
|
|
286
|
-
if (this.state === 3 /* CLOSING */ && this.removeListenersOnceClosed && this.connections.length === 0) {
|
|
330
|
+
if (this.state === 3 /* ServerState.CLOSING */ && this.removeListenersOnceClosed && this.connections.length === 0) {
|
|
287
331
|
this.removeAllListeners(); // see this.destroy()
|
|
288
332
|
}
|
|
289
333
|
};
|
|
290
334
|
DataStreamServer.prototype.checkCloseable = function () {
|
|
291
|
-
if (this.connections.length === 0 && this.preparedSessions.length === 0 && this.state < 3 /* CLOSING */) {
|
|
335
|
+
if (this.connections.length === 0 && this.preparedSessions.length === 0 && this.state < 3 /* ServerState.CLOSING */) {
|
|
292
336
|
debug("Last connection disconnected. Closing the server now.");
|
|
293
|
-
this.state = 3 /* CLOSING */;
|
|
337
|
+
this.state = 3 /* ServerState.CLOSING */;
|
|
294
338
|
this.tcpServer.close();
|
|
295
339
|
}
|
|
296
340
|
};
|
|
@@ -299,7 +343,7 @@ var DataStreamServer = /** @class */ (function (_super) {
|
|
|
299
343
|
*/
|
|
300
344
|
DataStreamServer.prototype.destroy = function () {
|
|
301
345
|
var e_1, _a;
|
|
302
|
-
if (this.state > 0 /* UNINITIALIZED */ && this.state < 3 /* CLOSING */) {
|
|
346
|
+
if (this.state > 0 /* ServerState.UNINITIALIZED */ && this.state < 3 /* ServerState.CLOSING */) {
|
|
303
347
|
this.tcpServer.close();
|
|
304
348
|
try {
|
|
305
349
|
for (var _b = tslib_1.__values(this.connections), _c = _b.next(); !_c.done; _c = _b.next()) {
|
|
@@ -315,14 +359,14 @@ var DataStreamServer = /** @class */ (function (_super) {
|
|
|
315
359
|
finally { if (e_1) throw e_1.error; }
|
|
316
360
|
}
|
|
317
361
|
}
|
|
318
|
-
this.state = 3 /* CLOSING */;
|
|
362
|
+
this.state = 3 /* ServerState.CLOSING */;
|
|
319
363
|
this.removeListenersOnceClosed = true;
|
|
320
364
|
this.internalEventEmitter.removeAllListeners();
|
|
321
365
|
};
|
|
322
366
|
DataStreamServer.prototype.closed = function () {
|
|
323
367
|
this.tcpServer = undefined;
|
|
324
368
|
this.tcpPort = undefined;
|
|
325
|
-
this.state = 0 /* UNINITIALIZED */;
|
|
369
|
+
this.state = 0 /* ServerState.UNINITIALIZED */;
|
|
326
370
|
};
|
|
327
371
|
DataStreamServer.version = "1.0";
|
|
328
372
|
DataStreamServer.accessoryToControllerInfo = Buffer.from("HDS-Read-Encryption-Key");
|
|
@@ -330,6 +374,9 @@ var DataStreamServer = /** @class */ (function (_super) {
|
|
|
330
374
|
return DataStreamServer;
|
|
331
375
|
}(events_1.EventEmitter));
|
|
332
376
|
exports.DataStreamServer = DataStreamServer;
|
|
377
|
+
/**
|
|
378
|
+
* @group HomeKit Data Streams (HDS)
|
|
379
|
+
*/
|
|
333
380
|
var DataStreamConnectionEvent;
|
|
334
381
|
(function (DataStreamConnectionEvent) {
|
|
335
382
|
/**
|
|
@@ -340,7 +387,7 @@ var DataStreamConnectionEvent;
|
|
|
340
387
|
*/
|
|
341
388
|
DataStreamConnectionEvent["IDENTIFICATION"] = "identification";
|
|
342
389
|
/**
|
|
343
|
-
* This event is emitted when no handler could be found for the given protocol of
|
|
390
|
+
* This event is emitted when no handler could be found for the given protocol of an event or request message.
|
|
344
391
|
*/
|
|
345
392
|
DataStreamConnectionEvent["HANDLE_MESSAGE_GLOBALLY"] = "handle-message-globally";
|
|
346
393
|
/**
|
|
@@ -349,8 +396,32 @@ var DataStreamConnectionEvent;
|
|
|
349
396
|
DataStreamConnectionEvent["CLOSED"] = "closed";
|
|
350
397
|
})(DataStreamConnectionEvent = exports.DataStreamConnectionEvent || (exports.DataStreamConnectionEvent = {}));
|
|
351
398
|
/**
|
|
352
|
-
*
|
|
399
|
+
* @group HomeKit Data Streams (HDS)
|
|
400
|
+
*/
|
|
401
|
+
var HDSConnectionErrorType;
|
|
402
|
+
(function (HDSConnectionErrorType) {
|
|
403
|
+
HDSConnectionErrorType[HDSConnectionErrorType["ILLEGAL_STATE"] = 1] = "ILLEGAL_STATE";
|
|
404
|
+
HDSConnectionErrorType[HDSConnectionErrorType["CLOSED_SOCKET"] = 2] = "CLOSED_SOCKET";
|
|
405
|
+
HDSConnectionErrorType[HDSConnectionErrorType["MAX_PAYLOAD_LENGTH"] = 3] = "MAX_PAYLOAD_LENGTH";
|
|
406
|
+
})(HDSConnectionErrorType = exports.HDSConnectionErrorType || (exports.HDSConnectionErrorType = {}));
|
|
407
|
+
/**
|
|
408
|
+
* @group HomeKit Data Streams (HDS)
|
|
409
|
+
*/
|
|
410
|
+
var HDSConnectionError = /** @class */ (function (_super) {
|
|
411
|
+
tslib_1.__extends(HDSConnectionError, _super);
|
|
412
|
+
function HDSConnectionError(message, type) {
|
|
413
|
+
var _this = _super.call(this, message) || this;
|
|
414
|
+
_this.type = type;
|
|
415
|
+
return _this;
|
|
416
|
+
}
|
|
417
|
+
return HDSConnectionError;
|
|
418
|
+
}(Error));
|
|
419
|
+
exports.HDSConnectionError = HDSConnectionError;
|
|
420
|
+
/**
|
|
421
|
+
* DataStream connection which holds any necessary state information, encryption and decryption keys, manages
|
|
353
422
|
* protocol handlers and also handles sending and receiving of data stream frames.
|
|
423
|
+
*
|
|
424
|
+
* @group HomeKit Data Streams (HDS)
|
|
354
425
|
*/
|
|
355
426
|
var DataStreamConnection = /** @class */ (function (_super) {
|
|
356
427
|
tslib_1.__extends(DataStreamConnection, _super);
|
|
@@ -358,12 +429,12 @@ var DataStreamConnection = /** @class */ (function (_super) {
|
|
|
358
429
|
var _a;
|
|
359
430
|
var _this = _super.call(this) || this;
|
|
360
431
|
/*
|
|
361
|
-
|
|
362
|
-
|
|
363
|
-
|
|
364
|
-
|
|
365
|
-
|
|
366
|
-
_this.state = 0 /* UNIDENTIFIED */;
|
|
432
|
+
Since our DataStream server does only listen on one port and this port is supplied to every client
|
|
433
|
+
which wants to connect, we do not really know which client is who when we receive a tcp connection.
|
|
434
|
+
Thus, we find the correct PreparedDataStreamSession object by testing the encryption keys of all available
|
|
435
|
+
prepared sessions. Then we can reference this hds connection with the correct hap connection and mark it as identified.
|
|
436
|
+
*/
|
|
437
|
+
_this.state = 0 /* ConnectionState.UNIDENTIFIED */;
|
|
367
438
|
_this.protocolHandlers = {}; // used to store protocolHandlers identified by their protocol name
|
|
368
439
|
_this.responseHandlers = {}; // used to store responseHandlers indexed by their respective requestId
|
|
369
440
|
_this.responseTimers = {}; // used to store response timeouts indexed by their respective requestId
|
|
@@ -376,34 +447,41 @@ var DataStreamConnection = /** @class */ (function (_super) {
|
|
|
376
447
|
_this.controllerToAccessoryNonce = 0;
|
|
377
448
|
_this.controllerToAccessoryNonceBuffer = Buffer.alloc(8);
|
|
378
449
|
_this.hapConnectionClosedListener = _this.onHAPSessionClosed.bind(_this);
|
|
379
|
-
_this.addProtocolHandler("control" /* CONTROL */, {
|
|
450
|
+
_this.addProtocolHandler("control" /* Protocols.CONTROL */, {
|
|
380
451
|
requestHandler: (_a = {},
|
|
381
|
-
_a["hello" /* HELLO */] = _this.handleHello.bind(_this),
|
|
382
|
-
_a)
|
|
452
|
+
_a["hello" /* Topics.HELLO */] = _this.handleHello.bind(_this),
|
|
453
|
+
_a),
|
|
383
454
|
});
|
|
384
455
|
_this.helloTimer = setTimeout(function () {
|
|
385
456
|
debug("[%s] Hello message did not arrive in time. Killing the connection", _this.remoteAddress);
|
|
386
457
|
_this.close();
|
|
387
458
|
}, 10000);
|
|
388
|
-
_this.socket.on(
|
|
389
|
-
_this.socket.on(
|
|
390
|
-
_this.socket.on(
|
|
459
|
+
_this.socket.on("data", _this.onSocketData.bind(_this));
|
|
460
|
+
_this.socket.on("error", _this.onSocketError.bind(_this));
|
|
461
|
+
_this.socket.on("close", _this.onSocketClose.bind(_this));
|
|
462
|
+
// this is to mitigate the event emitter "memory leak warning".
|
|
463
|
+
// e.g. with HSV there might be multiple cameras subscribing to the CLOSE event. one subscription for
|
|
464
|
+
// every active recording stream on a camera. The default limit of 10 might be easily reached.
|
|
465
|
+
// Setting a high limit isn't the prefect solution, but will avoid false positives but ensures that
|
|
466
|
+
// a warning is still be printed if running long enough.
|
|
467
|
+
_this.setMaxListeners(100);
|
|
391
468
|
return _this;
|
|
392
469
|
}
|
|
393
|
-
|
|
470
|
+
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
471
|
+
DataStreamConnection.prototype.handleHello = function (id, message) {
|
|
394
472
|
// that hello is indeed the _first_ message received is verified in onSocketData(...)
|
|
395
|
-
debug("[%s] Received hello message from client", this.remoteAddress);
|
|
473
|
+
debug("[%s] Received hello message from client: %o", this.remoteAddress, message);
|
|
396
474
|
clearTimeout(this.helloTimer);
|
|
397
475
|
this.helloTimer = undefined;
|
|
398
|
-
this.state = 2 /* READY */;
|
|
399
|
-
this.sendResponse("control" /* CONTROL */, "hello" /* HELLO */, id);
|
|
476
|
+
this.state = 2 /* ConnectionState.READY */;
|
|
477
|
+
this.sendResponse("control" /* Protocols.CONTROL */, "hello" /* Topics.HELLO */, id);
|
|
400
478
|
};
|
|
401
479
|
/**
|
|
402
480
|
* Registers a new protocol handler to handle incoming messages.
|
|
403
481
|
* The same protocol cannot be registered multiple times.
|
|
404
482
|
*
|
|
405
|
-
* @param protocol
|
|
406
|
-
* @param protocolHandler
|
|
483
|
+
* @param protocol - name of the protocol to register the handler for
|
|
484
|
+
* @param protocolHandler - object to be registered as protocol handler
|
|
407
485
|
*/
|
|
408
486
|
DataStreamConnection.prototype.addProtocolHandler = function (protocol, protocolHandler) {
|
|
409
487
|
if (this.protocolHandlers[protocol] !== undefined) {
|
|
@@ -415,8 +493,8 @@ var DataStreamConnection = /** @class */ (function (_super) {
|
|
|
415
493
|
/**
|
|
416
494
|
* Removes a protocol handler if it is registered.
|
|
417
495
|
*
|
|
418
|
-
* @param protocol
|
|
419
|
-
* @param protocolHandler
|
|
496
|
+
* @param protocol - name of the protocol to unregister the handler for
|
|
497
|
+
* @param protocolHandler - object which will be unregistered
|
|
420
498
|
*/
|
|
421
499
|
DataStreamConnection.prototype.removeProtocolHandler = function (protocol, protocolHandler) {
|
|
422
500
|
var current = this.protocolHandlers[protocol];
|
|
@@ -427,26 +505,29 @@ var DataStreamConnection = /** @class */ (function (_super) {
|
|
|
427
505
|
/**
|
|
428
506
|
* Sends a new event message to the connected client.
|
|
429
507
|
*
|
|
430
|
-
* @param protocol
|
|
431
|
-
* @param event
|
|
432
|
-
* @param message
|
|
508
|
+
* @param protocol - name of the protocol
|
|
509
|
+
* @param event - name of the event (also referred to as topic. See {@link Topics} for some known ones)
|
|
510
|
+
* @param message - message dictionary which gets sent along the event
|
|
433
511
|
*/
|
|
512
|
+
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
434
513
|
DataStreamConnection.prototype.sendEvent = function (protocol, event, message) {
|
|
435
514
|
if (message === void 0) { message = {}; }
|
|
515
|
+
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
436
516
|
var header = {};
|
|
437
|
-
header
|
|
438
|
-
header
|
|
517
|
+
header.protocol = protocol;
|
|
518
|
+
header.event = event;
|
|
439
519
|
this.sendHDSFrame(header, message);
|
|
440
520
|
};
|
|
441
521
|
/**
|
|
442
522
|
* Sends a new request message to the connected client.
|
|
443
523
|
*
|
|
444
|
-
* @param protocol
|
|
445
|
-
* @param request
|
|
446
|
-
* @param message
|
|
447
|
-
* @param callback
|
|
448
|
-
*
|
|
524
|
+
* @param protocol - name of the protocol
|
|
525
|
+
* @param request - name of the request (also referred to as topic. See {@link Topics} for some known ones)
|
|
526
|
+
* @param message - message dictionary which gets sent along the request
|
|
527
|
+
* @param callback - handler which gets supplied with an error object if the response didn't
|
|
528
|
+
* arrive in time or the status and the message dictionary from the response
|
|
449
529
|
*/
|
|
530
|
+
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
450
531
|
DataStreamConnection.prototype.sendRequest = function (protocol, request, message, callback) {
|
|
451
532
|
var _this = this;
|
|
452
533
|
if (message === void 0) { message = {}; }
|
|
@@ -462,37 +543,41 @@ var DataStreamConnection = /** @class */ (function (_super) {
|
|
|
462
543
|
var handler = _this.responseHandlers[requestId];
|
|
463
544
|
delete _this.responseHandlers[requestId];
|
|
464
545
|
delete _this.responseTimers[requestId];
|
|
465
|
-
// handler should be able to
|
|
546
|
+
// handler should be able to clean up their stuff
|
|
466
547
|
handler(new Error("timeout"), undefined, {});
|
|
467
548
|
}, 10000); // 10s timer
|
|
549
|
+
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
468
550
|
var header = {};
|
|
469
|
-
header
|
|
470
|
-
header
|
|
471
|
-
header
|
|
551
|
+
header.protocol = protocol;
|
|
552
|
+
header.request = request;
|
|
553
|
+
header.id = new DataStreamParser_1.Int64(requestId);
|
|
472
554
|
this.sendHDSFrame(header, message);
|
|
473
555
|
};
|
|
474
556
|
/**
|
|
475
557
|
* Send a new response message to a received request message to the client.
|
|
476
558
|
*
|
|
477
|
-
* @param protocol
|
|
478
|
-
* @param response
|
|
479
|
-
* @param id
|
|
480
|
-
* @param status
|
|
481
|
-
* @param message
|
|
559
|
+
* @param protocol - name of the protocol
|
|
560
|
+
* @param response - name of the response (also referred to as topic. See {@link Topics} for some known ones)
|
|
561
|
+
* @param id - id from the request, to associate the response to the request
|
|
562
|
+
* @param status - status indication if the request was successful. A status of zero indicates success.
|
|
563
|
+
* @param message - message dictionary which gets sent along the response
|
|
482
564
|
*/
|
|
483
|
-
DataStreamConnection.prototype.sendResponse = function (protocol, response, id, status,
|
|
565
|
+
DataStreamConnection.prototype.sendResponse = function (protocol, response, id, status,
|
|
566
|
+
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
567
|
+
message) {
|
|
484
568
|
if (status === void 0) { status = HDSStatus.SUCCESS; }
|
|
485
569
|
if (message === void 0) { message = {}; }
|
|
570
|
+
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
486
571
|
var header = {};
|
|
487
|
-
header
|
|
488
|
-
header
|
|
489
|
-
header
|
|
490
|
-
header
|
|
572
|
+
header.protocol = protocol;
|
|
573
|
+
header.response = response;
|
|
574
|
+
header.id = new DataStreamParser_1.Int64(id);
|
|
575
|
+
header.status = new DataStreamParser_1.Int64(status);
|
|
491
576
|
this.sendHDSFrame(header, message);
|
|
492
577
|
};
|
|
493
578
|
DataStreamConnection.prototype.onSocketData = function (data) {
|
|
494
579
|
var _this = this;
|
|
495
|
-
if (this.state >= 3 /* CLOSING */) {
|
|
580
|
+
if (this.state >= 3 /* ConnectionState.CLOSING */) {
|
|
496
581
|
return;
|
|
497
582
|
}
|
|
498
583
|
var frameIndex = 0;
|
|
@@ -500,21 +585,22 @@ var DataStreamConnection = /** @class */ (function (_super) {
|
|
|
500
585
|
if (frames.length === 0) { // not enough data
|
|
501
586
|
return;
|
|
502
587
|
}
|
|
503
|
-
if (this.state === 0 /* UNIDENTIFIED */) {
|
|
588
|
+
if (this.state === 0 /* ConnectionState.UNIDENTIFIED */) {
|
|
504
589
|
// at the beginning we are only interested in trying to decrypt the first frame in order to test decryption keys
|
|
505
590
|
var firstFrame = frames[frameIndex++];
|
|
506
|
-
this.emit("identification" /* IDENTIFICATION */, firstFrame, function (identifiedSession) {
|
|
591
|
+
this.emit("identification" /* DataStreamConnectionEvent.IDENTIFICATION */, firstFrame, function (identifiedSession) {
|
|
507
592
|
if (identifiedSession) {
|
|
508
593
|
// horray, we found our connection
|
|
509
594
|
_this.connection = identifiedSession.connection;
|
|
510
595
|
_this.accessoryToControllerEncryptionKey = identifiedSession.accessoryToControllerEncryptionKey;
|
|
511
596
|
_this.controllerToAccessoryEncryptionKey = identifiedSession.controllerToAccessoryEncryptionKey;
|
|
512
|
-
_this.state = 1 /* EXPECTING_HELLO */;
|
|
597
|
+
_this.state = 1 /* ConnectionState.EXPECTING_HELLO */;
|
|
513
598
|
// below listener is removed in .close()
|
|
514
|
-
_this.connection.on("closed" /* CLOSED */, _this.hapConnectionClosedListener); // register close listener
|
|
599
|
+
_this.connection.on("closed" /* HAPConnectionEvent.CLOSED */, _this.hapConnectionClosedListener); // register close listener
|
|
600
|
+
debug("[%s] Registering CLOSED handler to HAP connection. Connection currently has %d close handlers!", _this.remoteAddress, _this.connection.listeners("closed" /* HAPConnectionEvent.CLOSED */).length);
|
|
515
601
|
}
|
|
516
602
|
});
|
|
517
|
-
if (this.state === 0 /* UNIDENTIFIED */) {
|
|
603
|
+
if (this.state === 0 /* ConnectionState.UNIDENTIFIED */) {
|
|
518
604
|
// did not find a prepared connection, server already closed this connection; nothing to do here
|
|
519
605
|
return;
|
|
520
606
|
}
|
|
@@ -527,9 +613,9 @@ var DataStreamConnection = /** @class */ (function (_super) {
|
|
|
527
613
|
}
|
|
528
614
|
}
|
|
529
615
|
var messages = this.decodePayloads(frames); // decode contents of payload
|
|
530
|
-
if (this.state === 1 /* EXPECTING_HELLO */) {
|
|
616
|
+
if (this.state === 1 /* ConnectionState.EXPECTING_HELLO */) {
|
|
531
617
|
var firstMessage = messages[0];
|
|
532
|
-
if (firstMessage.protocol !== "control" /* CONTROL */ || firstMessage.type !== 2 /* REQUEST */ || firstMessage.topic !== "hello" /* HELLO */) {
|
|
618
|
+
if (firstMessage.protocol !== "control" /* Protocols.CONTROL */ || firstMessage.type !== 2 /* MessageType.REQUEST */ || firstMessage.topic !== "hello" /* Topics.HELLO */) {
|
|
533
619
|
// first message is not the expected hello request
|
|
534
620
|
debug("[%s] First message received was not the expected hello message. Instead got: %o", this.remoteAddress, firstMessage);
|
|
535
621
|
this.close();
|
|
@@ -537,8 +623,8 @@ var DataStreamConnection = /** @class */ (function (_super) {
|
|
|
537
623
|
}
|
|
538
624
|
}
|
|
539
625
|
messages.forEach(function (message) {
|
|
540
|
-
if (message.type === 3 /* RESPONSE */) {
|
|
541
|
-
// protocol and topic are currently not tested here; just assumed
|
|
626
|
+
if (message.type === 3 /* MessageType.RESPONSE */) {
|
|
627
|
+
// protocol and topic are currently not tested here; just assumed they are correct;
|
|
542
628
|
// probably they are as the requestId is unique per connection no matter what protocol is used
|
|
543
629
|
var responseHandler = _this.responseHandlers[message.id];
|
|
544
630
|
var responseTimer = _this.responseTimers[message.id];
|
|
@@ -564,10 +650,10 @@ var DataStreamConnection = /** @class */ (function (_super) {
|
|
|
564
650
|
var handler = _this.protocolHandlers[message.protocol];
|
|
565
651
|
if (handler === undefined) {
|
|
566
652
|
// send message to the server to check if there are some global handlers for it
|
|
567
|
-
_this.emit("handle-message-globally" /* HANDLE_MESSAGE_GLOBALLY */, message);
|
|
653
|
+
_this.emit("handle-message-globally" /* DataStreamConnectionEvent.HANDLE_MESSAGE_GLOBALLY */, message);
|
|
568
654
|
return;
|
|
569
655
|
}
|
|
570
|
-
if (message.type === 1 /* EVENT */) {
|
|
656
|
+
if (message.type === 1 /* MessageType.EVENT */) {
|
|
571
657
|
var eventHandler = void 0;
|
|
572
658
|
if (!handler.eventHandler || !(eventHandler = handler.eventHandler[message.topic])) {
|
|
573
659
|
debug("[%s] WARNING no event handler was found for message: %o", _this.remoteAddress, message);
|
|
@@ -581,7 +667,7 @@ var DataStreamConnection = /** @class */ (function (_super) {
|
|
|
581
667
|
debug(error.stack);
|
|
582
668
|
}
|
|
583
669
|
}
|
|
584
|
-
else if (message.type === 2 /* REQUEST */) {
|
|
670
|
+
else if (message.type === 2 /* MessageType.REQUEST */) {
|
|
585
671
|
var requestHandler = void 0;
|
|
586
672
|
if (!handler.requestHandler || !(requestHandler = handler.requestHandler[message.topic])) {
|
|
587
673
|
debug("[%s] WARNING no request handler was found for message: %o", _this.remoteAddress, message);
|
|
@@ -644,11 +730,14 @@ var DataStreamConnection = /** @class */ (function (_super) {
|
|
|
644
730
|
frames.push(hdsFrame);
|
|
645
731
|
}
|
|
646
732
|
else {
|
|
647
|
-
debug("[%s] Encountered unknown payload type %d for payload: %s", this.remoteAddress, plaintextPayload.toString(
|
|
733
|
+
debug("[%s] Encountered unknown payload type %d for payload: %s", this.remoteAddress, plaintextPayload.toString("hex"));
|
|
648
734
|
}
|
|
649
735
|
}
|
|
650
736
|
return frames;
|
|
651
737
|
};
|
|
738
|
+
/**
|
|
739
|
+
* @private file-private API
|
|
740
|
+
*/
|
|
652
741
|
DataStreamConnection.prototype.decryptHDSFrame = function (frame, keyOverwrite) {
|
|
653
742
|
hapCrypto.writeUInt64LE(this.controllerToAccessoryNonce, this.controllerToAccessoryNonceBuffer, 0); // update nonce buffer
|
|
654
743
|
var key = keyOverwrite || this.controllerToAccessoryEncryptionKey;
|
|
@@ -668,7 +757,7 @@ var DataStreamConnection = /** @class */ (function (_super) {
|
|
|
668
757
|
frames.forEach(function (frame) {
|
|
669
758
|
var payload = frame.plaintextPayload;
|
|
670
759
|
if (!payload) {
|
|
671
|
-
throw new
|
|
760
|
+
throw new HDSConnectionError("Reached illegal state. Encountered HDSFrame with wasn't decrypted yet!", 1 /* HDSConnectionErrorType.ILLEGAL_STATE */);
|
|
672
761
|
}
|
|
673
762
|
var headerLength = payload.readUInt8(0);
|
|
674
763
|
var messageLength = payload.length - headerLength - 1;
|
|
@@ -676,7 +765,9 @@ var DataStreamConnection = /** @class */ (function (_super) {
|
|
|
676
765
|
var messageBegin = headerBegin + headerLength;
|
|
677
766
|
var headerPayload = new DataStreamParser_1.DataStreamReader(payload.slice(headerBegin, headerBegin + headerLength));
|
|
678
767
|
var messagePayload = new DataStreamParser_1.DataStreamReader(payload.slice(messageBegin, messageBegin + messageLength));
|
|
768
|
+
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
679
769
|
var headerDictionary;
|
|
770
|
+
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
680
771
|
var messageDictionary;
|
|
681
772
|
try {
|
|
682
773
|
headerDictionary = DataStreamParser_1.DataStreamParser.decode(headerPayload);
|
|
@@ -695,24 +786,24 @@ var DataStreamConnection = /** @class */ (function (_super) {
|
|
|
695
786
|
return;
|
|
696
787
|
}
|
|
697
788
|
var type;
|
|
698
|
-
var protocol = headerDictionary
|
|
789
|
+
var protocol = headerDictionary.protocol;
|
|
699
790
|
var topic;
|
|
700
791
|
var id = undefined;
|
|
701
792
|
var status = undefined;
|
|
702
|
-
if (headerDictionary
|
|
703
|
-
type = 1 /* EVENT */;
|
|
704
|
-
topic = headerDictionary
|
|
793
|
+
if (headerDictionary.event !== undefined) {
|
|
794
|
+
type = 1 /* MessageType.EVENT */;
|
|
795
|
+
topic = headerDictionary.event;
|
|
705
796
|
}
|
|
706
|
-
else if (headerDictionary
|
|
707
|
-
type = 2 /* REQUEST */;
|
|
708
|
-
topic = headerDictionary
|
|
709
|
-
id = headerDictionary
|
|
797
|
+
else if (headerDictionary.request !== undefined) {
|
|
798
|
+
type = 2 /* MessageType.REQUEST */;
|
|
799
|
+
topic = headerDictionary.request;
|
|
800
|
+
id = headerDictionary.id;
|
|
710
801
|
}
|
|
711
|
-
else if (headerDictionary
|
|
712
|
-
type = 3 /* RESPONSE */;
|
|
713
|
-
topic = headerDictionary
|
|
714
|
-
id = headerDictionary
|
|
715
|
-
status = headerDictionary
|
|
802
|
+
else if (headerDictionary.response !== undefined) {
|
|
803
|
+
type = 3 /* MessageType.RESPONSE */;
|
|
804
|
+
topic = headerDictionary.response;
|
|
805
|
+
id = headerDictionary.id;
|
|
806
|
+
status = headerDictionary.status;
|
|
716
807
|
}
|
|
717
808
|
else {
|
|
718
809
|
debug("[%s] Encountered unknown payload header format: %o (message: %o)", _this.remoteAddress, headerDictionary, messageDictionary);
|
|
@@ -730,9 +821,10 @@ var DataStreamConnection = /** @class */ (function (_super) {
|
|
|
730
821
|
});
|
|
731
822
|
return messages;
|
|
732
823
|
};
|
|
824
|
+
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
733
825
|
DataStreamConnection.prototype.sendHDSFrame = function (header, message) {
|
|
734
|
-
if (this.state >= 3 /* CLOSING */) {
|
|
735
|
-
throw
|
|
826
|
+
if (this.state >= 3 /* ConnectionState.CLOSING */) {
|
|
827
|
+
throw new HDSConnectionError("Cannot send message on closing/closed socket!", 2 /* HDSConnectionErrorType.CLOSED_SOCKET */);
|
|
736
828
|
}
|
|
737
829
|
var headerWriter = new DataStreamParser_1.DataStreamWriter();
|
|
738
830
|
var messageWriter = new DataStreamParser_1.DataStreamWriter();
|
|
@@ -742,7 +834,7 @@ var DataStreamConnection = /** @class */ (function (_super) {
|
|
|
742
834
|
payloadHeaderBuffer.writeUInt8(headerWriter.length(), 0);
|
|
743
835
|
var payloadBuffer = Buffer.concat([payloadHeaderBuffer, headerWriter.getData(), messageWriter.getData()]);
|
|
744
836
|
if (payloadBuffer.length > DataStreamConnection.MAX_PAYLOAD_LENGTH) {
|
|
745
|
-
throw new
|
|
837
|
+
throw new HDSConnectionError("Tried sending payload with length larger than the maximum allowed for data stream", 3 /* HDSConnectionErrorType.MAX_PAYLOAD_LENGTH */);
|
|
746
838
|
}
|
|
747
839
|
var frameTypeBuffer = Buffer.alloc(1);
|
|
748
840
|
frameTypeBuffer.writeUInt8(1, 0);
|
|
@@ -754,26 +846,27 @@ var DataStreamConnection = /** @class */ (function (_super) {
|
|
|
754
846
|
var encrypted = hapCrypto.chacha20_poly1305_encryptAndSeal(this.accessoryToControllerEncryptionKey, this.accessoryToControllerNonceBuffer, frameHeader, payloadBuffer);
|
|
755
847
|
this.socket.write(Buffer.concat([frameHeader, encrypted.ciphertext, encrypted.authTag]));
|
|
756
848
|
/* Useful for debugging outgoing packages and detecting encoding errors
|
|
757
|
-
|
|
758
|
-
|
|
759
|
-
|
|
760
|
-
|
|
761
|
-
|
|
762
|
-
|
|
763
|
-
|
|
764
|
-
|
|
765
|
-
|
|
766
|
-
|
|
849
|
+
console.log("SENT DATA: " + payloadBuffer.toString("hex"));
|
|
850
|
+
const frame: HDSFrame = {
|
|
851
|
+
header: frameHeader,
|
|
852
|
+
plaintextPayload: payloadBuffer,
|
|
853
|
+
cipheredPayload: cipheredPayload,
|
|
854
|
+
authTag: authTag,
|
|
855
|
+
};
|
|
856
|
+
const sentMessage = this.decodePayloads([frame])[0];
|
|
857
|
+
console.log("Sent message: " + JSON.stringify(sentMessage, null, 4));
|
|
858
|
+
//*/
|
|
767
859
|
};
|
|
768
860
|
DataStreamConnection.prototype.close = function () {
|
|
769
|
-
|
|
770
|
-
if (this.state >= 3 /* CLOSING */) {
|
|
861
|
+
if (this.state >= 3 /* ConnectionState.CLOSING */) {
|
|
771
862
|
return; // connection is already closing/closed
|
|
772
863
|
}
|
|
773
|
-
|
|
774
|
-
this.state = 3 /* CLOSING */;
|
|
864
|
+
this.state = 3 /* ConnectionState.CLOSING */;
|
|
775
865
|
this.socket.end();
|
|
776
866
|
};
|
|
867
|
+
DataStreamConnection.prototype.isConsideredClosed = function () {
|
|
868
|
+
return this.state >= 3 /* ConnectionState.CLOSING */;
|
|
869
|
+
};
|
|
777
870
|
DataStreamConnection.prototype.onHAPSessionClosed = function () {
|
|
778
871
|
// If the hap connection is closed it is probably also a good idea to close the data stream connection
|
|
779
872
|
debug("[%s] HAP connection disconnected. Also closing DataStream connection now.", this.remoteAddress);
|
|
@@ -784,9 +877,11 @@ var DataStreamConnection = /** @class */ (function (_super) {
|
|
|
784
877
|
// onSocketClose will be called next
|
|
785
878
|
};
|
|
786
879
|
DataStreamConnection.prototype.onSocketClose = function () {
|
|
880
|
+
var _a;
|
|
787
881
|
// this instance is now considered completely dead
|
|
788
|
-
this.state = 4 /* CLOSED */;
|
|
789
|
-
this.emit("closed" /* CLOSED */);
|
|
882
|
+
this.state = 4 /* ConnectionState.CLOSED */;
|
|
883
|
+
this.emit("closed" /* DataStreamConnectionEvent.CLOSED */);
|
|
884
|
+
(_a = this.connection) === null || _a === void 0 ? void 0 : _a.removeListener("closed" /* HAPConnectionEvent.CLOSED */, this.hapConnectionClosedListener);
|
|
790
885
|
this.removeAllListeners();
|
|
791
886
|
};
|
|
792
887
|
DataStreamConnection.MAX_PAYLOAD_LENGTH = 1048575;
|