hap-nodejs 0.11.0-beta.9 → 0.11.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +1 -0
- package/dist/BridgedCore.js +4 -4
- package/dist/BridgedCore.js.map +1 -1
- package/dist/Core.js +2 -2
- package/dist/Core.js.map +1 -1
- package/dist/accessories/AirConditioner_accessory.js +18 -18
- package/dist/accessories/AirConditioner_accessory.js.map +1 -1
- package/dist/accessories/AppleTVRemote_accessory.js +6 -6
- package/dist/accessories/AppleTVRemote_accessory.js.map +1 -1
- package/dist/accessories/Camera_accessory.js +96 -87
- package/dist/accessories/Camera_accessory.js.map +1 -1
- package/dist/accessories/Fan_accessory.js +6 -6
- package/dist/accessories/Fan_accessory.js.map +1 -1
- package/dist/accessories/GarageDoorOpener_accessory.js +4 -4
- package/dist/accessories/GarageDoorOpener_accessory.js.map +1 -1
- package/dist/accessories/Light-AdaptiveLighting_accessory.js +2 -2
- package/dist/accessories/Light-AdaptiveLighting_accessory.js.map +1 -1
- package/dist/accessories/Light_accessory.js +11 -11
- package/dist/accessories/Light_accessory.js.map +1 -1
- package/dist/accessories/Lock_accessory.js +4 -4
- package/dist/accessories/Lock_accessory.js.map +1 -1
- package/dist/accessories/MotionSensor_accessory.js +3 -3
- package/dist/accessories/MotionSensor_accessory.js.map +1 -1
- package/dist/accessories/Outlet_accessory.js +4 -4
- package/dist/accessories/Outlet_accessory.js.map +1 -1
- package/dist/accessories/SmartSpeaker_accessory.js +5 -5
- package/dist/accessories/SmartSpeaker_accessory.js.map +1 -1
- package/dist/accessories/Sprinkler_accessory.js +7 -7
- package/dist/accessories/Sprinkler_accessory.js.map +1 -1
- package/dist/accessories/TV_accessory.js +9 -9
- package/dist/accessories/TV_accessory.js.map +1 -1
- package/dist/accessories/TemperatureSensor_accessory.js +2 -2
- package/dist/accessories/TemperatureSensor_accessory.js.map +1 -1
- package/dist/accessories/Wi-FiRouter_accessory.js +2 -2
- package/dist/accessories/Wi-FiRouter_accessory.js.map +1 -1
- package/dist/accessories/Wi-FiSatellite_accessory.js +2 -2
- package/dist/accessories/Wi-FiSatellite_accessory.js.map +1 -1
- package/dist/accessories/gstreamer-audioProducer.d.ts +2 -2
- package/dist/accessories/gstreamer-audioProducer.d.ts.map +1 -1
- package/dist/accessories/gstreamer-audioProducer.js +20 -20
- package/dist/accessories/gstreamer-audioProducer.js.map +1 -1
- package/dist/index.d.ts +30 -6
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +39 -25
- package/dist/index.js.map +1 -1
- package/dist/internal-types.d.ts +65 -126
- 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 +97 -21
- package/dist/lib/Accessory.d.ts.map +1 -1
- package/dist/lib/Accessory.js +315 -327
- package/dist/lib/Accessory.js.map +1 -1
- package/dist/lib/AccessoryLoader.d.ts +12 -0
- package/dist/lib/AccessoryLoader.d.ts.map +1 -1
- package/dist/lib/AccessoryLoader.js +18 -6
- package/dist/lib/AccessoryLoader.js.map +1 -1
- package/dist/lib/Advertiser.d.ts +32 -0
- package/dist/lib/Advertiser.d.ts.map +1 -1
- package/dist/lib/Advertiser.js +136 -58
- package/dist/lib/Advertiser.js.map +1 -1
- package/dist/lib/Bridge.d.ts +2 -0
- package/dist/lib/Bridge.d.ts.map +1 -1
- package/dist/lib/Bridge.js +3 -1
- package/dist/lib/Bridge.js.map +1 -1
- package/dist/lib/Characteristic.d.ts +872 -40
- package/dist/lib/Characteristic.d.ts.map +1 -1
- package/dist/lib/Characteristic.js +172 -141
- package/dist/lib/Characteristic.js.map +1 -1
- package/dist/lib/HAPServer.d.ts +113 -20
- package/dist/lib/HAPServer.d.ts.map +1 -1
- package/dist/lib/HAPServer.js +226 -231
- package/dist/lib/HAPServer.js.map +1 -1
- package/dist/lib/Service.d.ts +329 -13
- package/dist/lib/Service.d.ts.map +1 -1
- package/dist/lib/Service.js +45 -40
- package/dist/lib/Service.js.map +1 -1
- package/dist/lib/camera/Camera.d.ts +13 -4
- package/dist/lib/camera/Camera.d.ts.map +1 -1
- package/dist/lib/camera/Camera.js +3 -0
- package/dist/lib/camera/Camera.js.map +1 -1
- package/dist/lib/camera/RTPProxy.d.ts +5 -0
- package/dist/lib/camera/RTPProxy.d.ts.map +1 -1
- package/dist/lib/camera/RTPProxy.js +2 -1
- package/dist/lib/camera/RTPProxy.js.map +1 -1
- package/dist/lib/camera/RTPStreamManagement.d.ts +156 -33
- package/dist/lib/camera/RTPStreamManagement.d.ts.map +1 -1
- package/dist/lib/camera/RTPStreamManagement.js +204 -164
- package/dist/lib/camera/RTPStreamManagement.js.map +1 -1
- package/dist/lib/camera/RecordingManagement.d.ts +61 -11
- package/dist/lib/camera/RecordingManagement.d.ts.map +1 -1
- package/dist/lib/camera/RecordingManagement.js +171 -138
- package/dist/lib/camera/RecordingManagement.js.map +1 -1
- package/dist/lib/camera/index.js +4 -4
- package/dist/lib/camera/index.js.map +1 -1
- package/dist/lib/controller/AdaptiveLightingController.d.ts +28 -2
- package/dist/lib/controller/AdaptiveLightingController.d.ts.map +1 -1
- package/dist/lib/controller/AdaptiveLightingController.js +77 -68
- package/dist/lib/controller/AdaptiveLightingController.js.map +1 -1
- package/dist/lib/controller/CameraController.d.ts +44 -13
- package/dist/lib/controller/CameraController.d.ts.map +1 -1
- package/dist/lib/controller/CameraController.js +43 -34
- package/dist/lib/controller/CameraController.js.map +1 -1
- package/dist/lib/controller/Controller.d.ts +28 -7
- 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 +5 -1
- package/dist/lib/controller/DoorbellController.d.ts.map +1 -1
- package/dist/lib/controller/DoorbellController.js +5 -3
- package/dist/lib/controller/DoorbellController.js.map +1 -1
- package/dist/lib/controller/RemoteController.d.ts +108 -39
- package/dist/lib/controller/RemoteController.d.ts.map +1 -1
- package/dist/lib/controller/RemoteController.js +190 -175
- package/dist/lib/controller/RemoteController.js.map +1 -1
- package/dist/lib/controller/index.js +5 -5
- package/dist/lib/controller/index.js.map +1 -1
- 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 +36 -30
- package/dist/lib/datastream/DataStreamManagement.js.map +1 -1
- package/dist/lib/datastream/DataStreamParser.d.ts +39 -0
- package/dist/lib/datastream/DataStreamParser.d.ts.map +1 -1
- package/dist/lib/datastream/DataStreamParser.js +125 -88
- package/dist/lib/datastream/DataStreamParser.js.map +1 -1
- package/dist/lib/datastream/DataStreamServer.d.ts +121 -46
- package/dist/lib/datastream/DataStreamServer.d.ts.map +1 -1
- package/dist/lib/datastream/DataStreamServer.js +134 -100
- package/dist/lib/datastream/DataStreamServer.js.map +1 -1
- package/dist/lib/datastream/index.js +3 -3
- package/dist/lib/datastream/index.js.map +1 -1
- package/dist/lib/definitions/CharacteristicDefinitions.js +799 -799
- package/dist/lib/definitions/CharacteristicDefinitions.js.map +1 -1
- package/dist/lib/definitions/ServiceDefinitions.js +77 -77
- package/dist/lib/definitions/ServiceDefinitions.js.map +1 -1
- package/dist/lib/definitions/generate-definitions.js +60 -59
- package/dist/lib/definitions/generate-definitions.js.map +1 -1
- package/dist/lib/definitions/generator-configuration.js +15 -15
- package/dist/lib/definitions/generator-configuration.js.map +1 -1
- package/dist/lib/definitions/index.js +2 -2
- package/dist/lib/definitions/index.js.map +1 -1
- package/dist/lib/model/AccessoryInfo.d.ts +10 -4
- package/dist/lib/model/AccessoryInfo.d.ts.map +1 -1
- package/dist/lib/model/AccessoryInfo.js +21 -17
- 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 +8 -5
- 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 -1
- package/dist/lib/model/HAPStorage.js.map +1 -1
- package/dist/lib/model/IdentifierCache.d.ts +1 -0
- package/dist/lib/model/IdentifierCache.d.ts.map +1 -1
- package/dist/lib/model/IdentifierCache.js +3 -2
- package/dist/lib/model/IdentifierCache.js.map +1 -1
- package/dist/lib/tv/AccessControlManagement.d.ts +11 -0
- package/dist/lib/tv/AccessControlManagement.d.ts.map +1 -1
- package/dist/lib/tv/AccessControlManagement.js +15 -7
- 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 +5 -4
- 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 +52 -9
- package/dist/lib/util/eventedhttp.d.ts.map +1 -1
- package/dist/lib/util/eventedhttp.js +141 -135
- package/dist/lib/util/eventedhttp.js.map +1 -1
- package/dist/lib/util/hapCrypto.d.ts +30 -2
- package/dist/lib/util/hapCrypto.d.ts.map +1 -1
- package/dist/lib/util/hapCrypto.js +28 -4
- 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 +4 -2
- 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 +5 -0
- package/dist/lib/util/once.d.ts.map +1 -1
- package/dist/lib/util/once.js +6 -1
- package/dist/lib/util/once.js.map +1 -1
- package/dist/lib/util/promise-utils.d.ts +13 -0
- package/dist/lib/util/promise-utils.d.ts.map +1 -1
- package/dist/lib/util/promise-utils.js +27 -1
- package/dist/lib/util/promise-utils.js.map +1 -1
- 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 +42 -27
- package/dist/lib/util/request-util.js.map +1 -1
- package/dist/lib/util/time.d.ts +6 -0
- package/dist/lib/util/time.d.ts.map +1 -1
- package/dist/lib/util/time.js +8 -2
- 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 +90 -21
- 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 +1 -1
- package/dist/lib/util/uuid.js.map +1 -1
- package/dist/types.d.ts +267 -19
- package/dist/types.d.ts.map +1 -1
- package/dist/types.js +8 -0
- package/dist/types.js.map +1 -1
- package/package.json +10 -7
|
@@ -1,21 +1,27 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.DataStreamConnection = exports.HDSConnectionError = exports.HDSConnectionErrorType = exports.DataStreamConnectionEvent = exports.DataStreamServer = exports.DataStreamServerEvent = exports.HDSProtocolError = exports.HDSProtocolSpecificErrorReason = exports.HDSStatus = exports.Topics = exports.Protocols = void 0;
|
|
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
|
-
var assert_1 =
|
|
6
|
-
var crypto_1 =
|
|
7
|
-
var debug_1 =
|
|
5
|
+
var assert_1 = tslib_1.__importDefault(require("assert"));
|
|
6
|
+
var crypto_1 = tslib_1.__importDefault(require("crypto"));
|
|
7
|
+
var debug_1 = tslib_1.__importDefault(require("debug"));
|
|
8
8
|
var events_1 = require("events");
|
|
9
|
-
var net_1 =
|
|
10
|
-
var hapCrypto =
|
|
9
|
+
var net_1 = tslib_1.__importDefault(require("net"));
|
|
10
|
+
var hapCrypto = tslib_1.__importStar(require("../util/hapCrypto"));
|
|
11
11
|
var DataStreamParser_1 = require("./DataStreamParser");
|
|
12
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,6 +48,9 @@ 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 = {}));
|
|
51
|
+
/**
|
|
52
|
+
* @group HomeKit Data Streams (HDS)
|
|
53
|
+
*/
|
|
42
54
|
var HDSProtocolSpecificErrorReason;
|
|
43
55
|
(function (HDSProtocolSpecificErrorReason) {
|
|
44
56
|
// noinspection JSUnusedGlobalSymbols
|
|
@@ -56,9 +68,10 @@ var HDSProtocolSpecificErrorReason;
|
|
|
56
68
|
/**
|
|
57
69
|
* An error indicating a protocol level HDS error.
|
|
58
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)
|
|
59
72
|
*/
|
|
60
73
|
var HDSProtocolError = /** @class */ (function (_super) {
|
|
61
|
-
|
|
74
|
+
tslib_1.__extends(HDSProtocolError, _super);
|
|
62
75
|
/**
|
|
63
76
|
* Initializes a new `HDSProtocolError`
|
|
64
77
|
* @param reason - The {@link HDSProtocolSpecificErrorReason}.
|
|
@@ -66,7 +79,7 @@ var HDSProtocolError = /** @class */ (function (_super) {
|
|
|
66
79
|
*/
|
|
67
80
|
function HDSProtocolError(reason) {
|
|
68
81
|
var _this = _super.call(this, "HDSProtocolError: " + reason) || this;
|
|
69
|
-
(0, assert_1.default)(reason !== 0 /* NORMAL */, "Cannot initialize a HDSProtocolError with NORMAL!");
|
|
82
|
+
(0, assert_1.default)(reason !== 0 /* HDSProtocolSpecificErrorReason.NORMAL */, "Cannot initialize a HDSProtocolError with NORMAL!");
|
|
70
83
|
_this.reason = reason;
|
|
71
84
|
return _this;
|
|
72
85
|
}
|
|
@@ -88,12 +101,18 @@ var ConnectionState;
|
|
|
88
101
|
ConnectionState[ConnectionState["CLOSING"] = 3] = "CLOSING";
|
|
89
102
|
ConnectionState[ConnectionState["CLOSED"] = 4] = "CLOSED";
|
|
90
103
|
})(ConnectionState || (ConnectionState = {}));
|
|
104
|
+
/**
|
|
105
|
+
* @group HomeKit Data Streams (HDS)
|
|
106
|
+
*/
|
|
91
107
|
var MessageType;
|
|
92
108
|
(function (MessageType) {
|
|
93
109
|
MessageType[MessageType["EVENT"] = 1] = "EVENT";
|
|
94
110
|
MessageType[MessageType["REQUEST"] = 2] = "REQUEST";
|
|
95
111
|
MessageType[MessageType["RESPONSE"] = 3] = "RESPONSE";
|
|
96
|
-
})(MessageType || (MessageType = {}));
|
|
112
|
+
})(MessageType = exports.MessageType || (exports.MessageType = {}));
|
|
113
|
+
/**
|
|
114
|
+
* @group HomeKit Data Streams (HDS)
|
|
115
|
+
*/
|
|
97
116
|
var DataStreamServerEvent;
|
|
98
117
|
(function (DataStreamServerEvent) {
|
|
99
118
|
/**
|
|
@@ -108,12 +127,13 @@ var DataStreamServerEvent;
|
|
|
108
127
|
})(DataStreamServerEvent = exports.DataStreamServerEvent || (exports.DataStreamServerEvent = {}));
|
|
109
128
|
/**
|
|
110
129
|
* DataStreamServer which listens for incoming tcp connections and handles identification of new connections
|
|
130
|
+
* @group HomeKit Data Streams (HDS)
|
|
111
131
|
*/
|
|
112
132
|
var DataStreamServer = /** @class */ (function (_super) {
|
|
113
|
-
|
|
133
|
+
tslib_1.__extends(DataStreamServer, _super);
|
|
114
134
|
function DataStreamServer() {
|
|
115
135
|
var _this = _super.call(this) || this;
|
|
116
|
-
_this.state = 0 /* UNINITIALIZED */;
|
|
136
|
+
_this.state = 0 /* ServerState.UNINITIALIZED */;
|
|
117
137
|
_this.preparedSessions = [];
|
|
118
138
|
_this.connections = [];
|
|
119
139
|
_this.removeListenersOnceClosed = false;
|
|
@@ -125,20 +145,20 @@ var DataStreamServer = /** @class */ (function (_super) {
|
|
|
125
145
|
* The handler is only called for a connection if for the give protocol no ProtocolHandler
|
|
126
146
|
* was registered on the connection level.
|
|
127
147
|
*
|
|
128
|
-
* @param protocol
|
|
129
|
-
* @param event
|
|
130
|
-
* @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
|
|
131
151
|
*/
|
|
132
152
|
DataStreamServer.prototype.onEventMessage = function (protocol, event, handler) {
|
|
133
153
|
this.internalEventEmitter.on(protocol + "-e-" + event, handler);
|
|
134
154
|
return this;
|
|
135
155
|
};
|
|
136
156
|
/**
|
|
137
|
-
* Removes
|
|
157
|
+
* Removes a registered event handler.
|
|
138
158
|
*
|
|
139
|
-
* @param protocol
|
|
140
|
-
* @param event
|
|
141
|
-
* @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
|
|
142
162
|
*/
|
|
143
163
|
DataStreamServer.prototype.removeEventHandler = function (protocol, event, handler) {
|
|
144
164
|
this.internalEventEmitter.removeListener(protocol + "-e-" + event, handler);
|
|
@@ -149,20 +169,20 @@ var DataStreamServer = /** @class */ (function (_super) {
|
|
|
149
169
|
* The handler is only called for a connection if for the give protocol no ProtocolHandler
|
|
150
170
|
* was registered on the connection level.
|
|
151
171
|
*
|
|
152
|
-
* @param protocol
|
|
153
|
-
* @param request
|
|
154
|
-
* @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
|
|
155
175
|
*/
|
|
156
176
|
DataStreamServer.prototype.onRequestMessage = function (protocol, request, handler) {
|
|
157
177
|
this.internalEventEmitter.on(protocol + "-r-" + request, handler);
|
|
158
178
|
return this;
|
|
159
179
|
};
|
|
160
180
|
/**
|
|
161
|
-
* Removes
|
|
181
|
+
* Removes a registered request handler.
|
|
162
182
|
*
|
|
163
|
-
* @param protocol
|
|
164
|
-
* @param request
|
|
165
|
-
* @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
|
|
166
186
|
*/
|
|
167
187
|
DataStreamServer.prototype.removeRequestHandler = function (protocol, request, handler) {
|
|
168
188
|
this.internalEventEmitter.removeListener(protocol + "-r-" + request, handler);
|
|
@@ -204,32 +224,32 @@ var DataStreamServer = /** @class */ (function (_super) {
|
|
|
204
224
|
DataStreamServer.prototype.checkTCPServerEstablished = function (preparedSession, callback) {
|
|
205
225
|
var _this = this;
|
|
206
226
|
switch (this.state) {
|
|
207
|
-
case 0 /* UNINITIALIZED */:
|
|
227
|
+
case 0 /* ServerState.UNINITIALIZED */:
|
|
208
228
|
debug("Starting up TCP server.");
|
|
209
229
|
this.tcpServer = net_1.default.createServer();
|
|
210
230
|
this.tcpServer.once("listening", this.listening.bind(this, preparedSession, callback));
|
|
211
231
|
this.tcpServer.on("connection", this.onConnection.bind(this));
|
|
212
232
|
this.tcpServer.on("close", this.closed.bind(this));
|
|
213
233
|
this.tcpServer.listen();
|
|
214
|
-
this.state = 1 /* BINDING */;
|
|
234
|
+
this.state = 1 /* ServerState.BINDING */;
|
|
215
235
|
break;
|
|
216
|
-
case 1 /* BINDING */:
|
|
236
|
+
case 1 /* ServerState.BINDING */:
|
|
217
237
|
debug("TCP server already running. Waiting for it to bind.");
|
|
218
238
|
this.tcpServer.once("listening", this.listening.bind(this, preparedSession, callback));
|
|
219
239
|
break;
|
|
220
|
-
case 2 /* LISTENING */:
|
|
240
|
+
case 2 /* ServerState.LISTENING */:
|
|
221
241
|
debug("Instructing client to connect to already running TCP server");
|
|
222
242
|
preparedSession.port = this.tcpPort;
|
|
223
243
|
callback();
|
|
224
244
|
break;
|
|
225
|
-
case 3 /* CLOSING */:
|
|
245
|
+
case 3 /* ServerState.CLOSING */:
|
|
226
246
|
debug("TCP socket is currently closing. Trying again when server is fully closed and opening a new one then.");
|
|
227
247
|
this.tcpServer.once("close", function () { return setTimeout(function () { return _this.checkTCPServerEstablished(preparedSession, callback); }, 10); });
|
|
228
248
|
break;
|
|
229
249
|
}
|
|
230
250
|
};
|
|
231
251
|
DataStreamServer.prototype.listening = function (preparedSession, callback) {
|
|
232
|
-
this.state = 2 /* LISTENING */;
|
|
252
|
+
this.state = 2 /* ServerState.LISTENING */;
|
|
233
253
|
var address = this.tcpServer.address();
|
|
234
254
|
if (address && typeof address !== "string") { // address is only typeof string when listening to a pipe or unix socket
|
|
235
255
|
this.tcpPort = address.port;
|
|
@@ -242,11 +262,11 @@ var DataStreamServer = /** @class */ (function (_super) {
|
|
|
242
262
|
debug("[%s] New DataStream connection was established", socket.remoteAddress);
|
|
243
263
|
// eslint-disable-next-line @typescript-eslint/no-use-before-define
|
|
244
264
|
var connection = new DataStreamConnection(socket);
|
|
245
|
-
connection.on("identification" /* IDENTIFICATION */, this.handleSessionIdentification.bind(this, connection));
|
|
246
|
-
connection.on("handle-message-globally" /* HANDLE_MESSAGE_GLOBALLY */, this.handleMessageGlobally.bind(this, connection));
|
|
247
|
-
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));
|
|
248
268
|
this.connections.push(connection);
|
|
249
|
-
this.emit("connection-opened" /* CONNECTION_OPENED */, connection);
|
|
269
|
+
this.emit("connection-opened" /* DataStreamServerEvent.CONNECTION_OPENED */, connection);
|
|
250
270
|
};
|
|
251
271
|
DataStreamServer.prototype.handleSessionIdentification = function (connection, firstFrame, callback) {
|
|
252
272
|
var identifiedSession = undefined;
|
|
@@ -278,20 +298,20 @@ var DataStreamServer = /** @class */ (function (_super) {
|
|
|
278
298
|
};
|
|
279
299
|
DataStreamServer.prototype.handleMessageGlobally = function (connection, message) {
|
|
280
300
|
var _a;
|
|
281
|
-
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
|
|
282
302
|
var separator = "";
|
|
283
303
|
var args = [];
|
|
284
|
-
if (message.type === 1 /* EVENT */) {
|
|
304
|
+
if (message.type === 1 /* MessageType.EVENT */) {
|
|
285
305
|
separator = "-e-";
|
|
286
306
|
}
|
|
287
|
-
else if (message.type === 2 /* REQUEST */) {
|
|
307
|
+
else if (message.type === 2 /* MessageType.REQUEST */) {
|
|
288
308
|
separator = "-r-";
|
|
289
309
|
args.push(message.id);
|
|
290
310
|
}
|
|
291
311
|
args.push(message.message);
|
|
292
312
|
var hadListeners;
|
|
293
313
|
try {
|
|
294
|
-
hadListeners = (_a = this.internalEventEmitter).emit.apply(_a,
|
|
314
|
+
hadListeners = (_a = this.internalEventEmitter).emit.apply(_a, tslib_1.__spreadArray([message.protocol + separator + message.topic, connection], tslib_1.__read(args), false));
|
|
295
315
|
}
|
|
296
316
|
catch (error) {
|
|
297
317
|
hadListeners = true;
|
|
@@ -305,16 +325,16 @@ var DataStreamServer = /** @class */ (function (_super) {
|
|
|
305
325
|
DataStreamServer.prototype.connectionClosed = function (connection) {
|
|
306
326
|
debug("[%s] DataStream connection closed", connection.remoteAddress);
|
|
307
327
|
this.connections.splice(this.connections.indexOf(connection), 1);
|
|
308
|
-
this.emit("connection-closed" /* CONNECTION_CLOSED */, connection);
|
|
328
|
+
this.emit("connection-closed" /* DataStreamServerEvent.CONNECTION_CLOSED */, connection);
|
|
309
329
|
this.checkCloseable();
|
|
310
|
-
if (this.state === 3 /* CLOSING */ && this.removeListenersOnceClosed && this.connections.length === 0) {
|
|
330
|
+
if (this.state === 3 /* ServerState.CLOSING */ && this.removeListenersOnceClosed && this.connections.length === 0) {
|
|
311
331
|
this.removeAllListeners(); // see this.destroy()
|
|
312
332
|
}
|
|
313
333
|
};
|
|
314
334
|
DataStreamServer.prototype.checkCloseable = function () {
|
|
315
|
-
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 */) {
|
|
316
336
|
debug("Last connection disconnected. Closing the server now.");
|
|
317
|
-
this.state = 3 /* CLOSING */;
|
|
337
|
+
this.state = 3 /* ServerState.CLOSING */;
|
|
318
338
|
this.tcpServer.close();
|
|
319
339
|
}
|
|
320
340
|
};
|
|
@@ -323,10 +343,10 @@ var DataStreamServer = /** @class */ (function (_super) {
|
|
|
323
343
|
*/
|
|
324
344
|
DataStreamServer.prototype.destroy = function () {
|
|
325
345
|
var e_1, _a;
|
|
326
|
-
if (this.state > 0 /* UNINITIALIZED */ && this.state < 3 /* CLOSING */) {
|
|
346
|
+
if (this.state > 0 /* ServerState.UNINITIALIZED */ && this.state < 3 /* ServerState.CLOSING */) {
|
|
327
347
|
this.tcpServer.close();
|
|
328
348
|
try {
|
|
329
|
-
for (var _b =
|
|
349
|
+
for (var _b = tslib_1.__values(this.connections), _c = _b.next(); !_c.done; _c = _b.next()) {
|
|
330
350
|
var connection = _c.value;
|
|
331
351
|
connection.close();
|
|
332
352
|
}
|
|
@@ -339,14 +359,14 @@ var DataStreamServer = /** @class */ (function (_super) {
|
|
|
339
359
|
finally { if (e_1) throw e_1.error; }
|
|
340
360
|
}
|
|
341
361
|
}
|
|
342
|
-
this.state = 3 /* CLOSING */;
|
|
362
|
+
this.state = 3 /* ServerState.CLOSING */;
|
|
343
363
|
this.removeListenersOnceClosed = true;
|
|
344
364
|
this.internalEventEmitter.removeAllListeners();
|
|
345
365
|
};
|
|
346
366
|
DataStreamServer.prototype.closed = function () {
|
|
347
367
|
this.tcpServer = undefined;
|
|
348
368
|
this.tcpPort = undefined;
|
|
349
|
-
this.state = 0 /* UNINITIALIZED */;
|
|
369
|
+
this.state = 0 /* ServerState.UNINITIALIZED */;
|
|
350
370
|
};
|
|
351
371
|
DataStreamServer.version = "1.0";
|
|
352
372
|
DataStreamServer.accessoryToControllerInfo = Buffer.from("HDS-Read-Encryption-Key");
|
|
@@ -354,6 +374,9 @@ var DataStreamServer = /** @class */ (function (_super) {
|
|
|
354
374
|
return DataStreamServer;
|
|
355
375
|
}(events_1.EventEmitter));
|
|
356
376
|
exports.DataStreamServer = DataStreamServer;
|
|
377
|
+
/**
|
|
378
|
+
* @group HomeKit Data Streams (HDS)
|
|
379
|
+
*/
|
|
357
380
|
var DataStreamConnectionEvent;
|
|
358
381
|
(function (DataStreamConnectionEvent) {
|
|
359
382
|
/**
|
|
@@ -364,7 +387,7 @@ var DataStreamConnectionEvent;
|
|
|
364
387
|
*/
|
|
365
388
|
DataStreamConnectionEvent["IDENTIFICATION"] = "identification";
|
|
366
389
|
/**
|
|
367
|
-
* 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.
|
|
368
391
|
*/
|
|
369
392
|
DataStreamConnectionEvent["HANDLE_MESSAGE_GLOBALLY"] = "handle-message-globally";
|
|
370
393
|
/**
|
|
@@ -372,14 +395,20 @@ var DataStreamConnectionEvent;
|
|
|
372
395
|
*/
|
|
373
396
|
DataStreamConnectionEvent["CLOSED"] = "closed";
|
|
374
397
|
})(DataStreamConnectionEvent = exports.DataStreamConnectionEvent || (exports.DataStreamConnectionEvent = {}));
|
|
398
|
+
/**
|
|
399
|
+
* @group HomeKit Data Streams (HDS)
|
|
400
|
+
*/
|
|
375
401
|
var HDSConnectionErrorType;
|
|
376
402
|
(function (HDSConnectionErrorType) {
|
|
377
403
|
HDSConnectionErrorType[HDSConnectionErrorType["ILLEGAL_STATE"] = 1] = "ILLEGAL_STATE";
|
|
378
404
|
HDSConnectionErrorType[HDSConnectionErrorType["CLOSED_SOCKET"] = 2] = "CLOSED_SOCKET";
|
|
379
405
|
HDSConnectionErrorType[HDSConnectionErrorType["MAX_PAYLOAD_LENGTH"] = 3] = "MAX_PAYLOAD_LENGTH";
|
|
380
406
|
})(HDSConnectionErrorType = exports.HDSConnectionErrorType || (exports.HDSConnectionErrorType = {}));
|
|
407
|
+
/**
|
|
408
|
+
* @group HomeKit Data Streams (HDS)
|
|
409
|
+
*/
|
|
381
410
|
var HDSConnectionError = /** @class */ (function (_super) {
|
|
382
|
-
|
|
411
|
+
tslib_1.__extends(HDSConnectionError, _super);
|
|
383
412
|
function HDSConnectionError(message, type) {
|
|
384
413
|
var _this = _super.call(this, message) || this;
|
|
385
414
|
_this.type = type;
|
|
@@ -389,11 +418,13 @@ var HDSConnectionError = /** @class */ (function (_super) {
|
|
|
389
418
|
}(Error));
|
|
390
419
|
exports.HDSConnectionError = HDSConnectionError;
|
|
391
420
|
/**
|
|
392
|
-
* DataStream connection which holds any necessary state information, encryption
|
|
421
|
+
* DataStream connection which holds any necessary state information, encryption and decryption keys, manages
|
|
393
422
|
* protocol handlers and also handles sending and receiving of data stream frames.
|
|
423
|
+
*
|
|
424
|
+
* @group HomeKit Data Streams (HDS)
|
|
394
425
|
*/
|
|
395
426
|
var DataStreamConnection = /** @class */ (function (_super) {
|
|
396
|
-
|
|
427
|
+
tslib_1.__extends(DataStreamConnection, _super);
|
|
397
428
|
function DataStreamConnection(socket) {
|
|
398
429
|
var _a;
|
|
399
430
|
var _this = _super.call(this) || this;
|
|
@@ -403,7 +434,7 @@ var DataStreamConnection = /** @class */ (function (_super) {
|
|
|
403
434
|
Thus, we find the correct PreparedDataStreamSession object by testing the encryption keys of all available
|
|
404
435
|
prepared sessions. Then we can reference this hds connection with the correct hap connection and mark it as identified.
|
|
405
436
|
*/
|
|
406
|
-
_this.state = 0 /* UNIDENTIFIED */;
|
|
437
|
+
_this.state = 0 /* ConnectionState.UNIDENTIFIED */;
|
|
407
438
|
_this.protocolHandlers = {}; // used to store protocolHandlers identified by their protocol name
|
|
408
439
|
_this.responseHandlers = {}; // used to store responseHandlers indexed by their respective requestId
|
|
409
440
|
_this.responseTimers = {}; // used to store response timeouts indexed by their respective requestId
|
|
@@ -416,9 +447,9 @@ var DataStreamConnection = /** @class */ (function (_super) {
|
|
|
416
447
|
_this.controllerToAccessoryNonce = 0;
|
|
417
448
|
_this.controllerToAccessoryNonceBuffer = Buffer.alloc(8);
|
|
418
449
|
_this.hapConnectionClosedListener = _this.onHAPSessionClosed.bind(_this);
|
|
419
|
-
_this.addProtocolHandler("control" /* CONTROL */, {
|
|
450
|
+
_this.addProtocolHandler("control" /* Protocols.CONTROL */, {
|
|
420
451
|
requestHandler: (_a = {},
|
|
421
|
-
_a["hello" /* HELLO */] = _this.handleHello.bind(_this),
|
|
452
|
+
_a["hello" /* Topics.HELLO */] = _this.handleHello.bind(_this),
|
|
422
453
|
_a),
|
|
423
454
|
});
|
|
424
455
|
_this.helloTimer = setTimeout(function () {
|
|
@@ -442,15 +473,15 @@ var DataStreamConnection = /** @class */ (function (_super) {
|
|
|
442
473
|
debug("[%s] Received hello message from client: %o", this.remoteAddress, message);
|
|
443
474
|
clearTimeout(this.helloTimer);
|
|
444
475
|
this.helloTimer = undefined;
|
|
445
|
-
this.state = 2 /* READY */;
|
|
446
|
-
this.sendResponse("control" /* CONTROL */, "hello" /* HELLO */, id);
|
|
476
|
+
this.state = 2 /* ConnectionState.READY */;
|
|
477
|
+
this.sendResponse("control" /* Protocols.CONTROL */, "hello" /* Topics.HELLO */, id);
|
|
447
478
|
};
|
|
448
479
|
/**
|
|
449
480
|
* Registers a new protocol handler to handle incoming messages.
|
|
450
481
|
* The same protocol cannot be registered multiple times.
|
|
451
482
|
*
|
|
452
|
-
* @param protocol
|
|
453
|
-
* @param protocolHandler
|
|
483
|
+
* @param protocol - name of the protocol to register the handler for
|
|
484
|
+
* @param protocolHandler - object to be registered as protocol handler
|
|
454
485
|
*/
|
|
455
486
|
DataStreamConnection.prototype.addProtocolHandler = function (protocol, protocolHandler) {
|
|
456
487
|
if (this.protocolHandlers[protocol] !== undefined) {
|
|
@@ -462,8 +493,8 @@ var DataStreamConnection = /** @class */ (function (_super) {
|
|
|
462
493
|
/**
|
|
463
494
|
* Removes a protocol handler if it is registered.
|
|
464
495
|
*
|
|
465
|
-
* @param protocol
|
|
466
|
-
* @param protocolHandler
|
|
496
|
+
* @param protocol - name of the protocol to unregister the handler for
|
|
497
|
+
* @param protocolHandler - object which will be unregistered
|
|
467
498
|
*/
|
|
468
499
|
DataStreamConnection.prototype.removeProtocolHandler = function (protocol, protocolHandler) {
|
|
469
500
|
var current = this.protocolHandlers[protocol];
|
|
@@ -474,9 +505,9 @@ var DataStreamConnection = /** @class */ (function (_super) {
|
|
|
474
505
|
/**
|
|
475
506
|
* Sends a new event message to the connected client.
|
|
476
507
|
*
|
|
477
|
-
* @param protocol
|
|
478
|
-
* @param event
|
|
479
|
-
* @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
|
|
480
511
|
*/
|
|
481
512
|
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
482
513
|
DataStreamConnection.prototype.sendEvent = function (protocol, event, message) {
|
|
@@ -490,11 +521,11 @@ var DataStreamConnection = /** @class */ (function (_super) {
|
|
|
490
521
|
/**
|
|
491
522
|
* Sends a new request message to the connected client.
|
|
492
523
|
*
|
|
493
|
-
* @param protocol
|
|
494
|
-
* @param request
|
|
495
|
-
* @param message
|
|
496
|
-
* @param callback
|
|
497
|
-
*
|
|
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
|
|
498
529
|
*/
|
|
499
530
|
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
500
531
|
DataStreamConnection.prototype.sendRequest = function (protocol, request, message, callback) {
|
|
@@ -525,11 +556,11 @@ var DataStreamConnection = /** @class */ (function (_super) {
|
|
|
525
556
|
/**
|
|
526
557
|
* Send a new response message to a received request message to the client.
|
|
527
558
|
*
|
|
528
|
-
* @param protocol
|
|
529
|
-
* @param response
|
|
530
|
-
* @param id
|
|
531
|
-
* @param status
|
|
532
|
-
* @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
|
|
533
564
|
*/
|
|
534
565
|
DataStreamConnection.prototype.sendResponse = function (protocol, response, id, status,
|
|
535
566
|
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
@@ -546,7 +577,7 @@ var DataStreamConnection = /** @class */ (function (_super) {
|
|
|
546
577
|
};
|
|
547
578
|
DataStreamConnection.prototype.onSocketData = function (data) {
|
|
548
579
|
var _this = this;
|
|
549
|
-
if (this.state >= 3 /* CLOSING */) {
|
|
580
|
+
if (this.state >= 3 /* ConnectionState.CLOSING */) {
|
|
550
581
|
return;
|
|
551
582
|
}
|
|
552
583
|
var frameIndex = 0;
|
|
@@ -554,22 +585,22 @@ var DataStreamConnection = /** @class */ (function (_super) {
|
|
|
554
585
|
if (frames.length === 0) { // not enough data
|
|
555
586
|
return;
|
|
556
587
|
}
|
|
557
|
-
if (this.state === 0 /* UNIDENTIFIED */) {
|
|
588
|
+
if (this.state === 0 /* ConnectionState.UNIDENTIFIED */) {
|
|
558
589
|
// at the beginning we are only interested in trying to decrypt the first frame in order to test decryption keys
|
|
559
590
|
var firstFrame = frames[frameIndex++];
|
|
560
|
-
this.emit("identification" /* IDENTIFICATION */, firstFrame, function (identifiedSession) {
|
|
591
|
+
this.emit("identification" /* DataStreamConnectionEvent.IDENTIFICATION */, firstFrame, function (identifiedSession) {
|
|
561
592
|
if (identifiedSession) {
|
|
562
593
|
// horray, we found our connection
|
|
563
594
|
_this.connection = identifiedSession.connection;
|
|
564
595
|
_this.accessoryToControllerEncryptionKey = identifiedSession.accessoryToControllerEncryptionKey;
|
|
565
596
|
_this.controllerToAccessoryEncryptionKey = identifiedSession.controllerToAccessoryEncryptionKey;
|
|
566
|
-
_this.state = 1 /* EXPECTING_HELLO */;
|
|
597
|
+
_this.state = 1 /* ConnectionState.EXPECTING_HELLO */;
|
|
567
598
|
// below listener is removed in .close()
|
|
568
|
-
_this.connection.on("closed" /* CLOSED */, _this.hapConnectionClosedListener); // register close listener
|
|
569
|
-
debug("[%s] Registering CLOSED handler to HAP connection. Connection currently has %d close handlers!", _this.remoteAddress, _this.connection.listeners("closed" /* CLOSED */).length);
|
|
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);
|
|
570
601
|
}
|
|
571
602
|
});
|
|
572
|
-
if (this.state === 0 /* UNIDENTIFIED */) {
|
|
603
|
+
if (this.state === 0 /* ConnectionState.UNIDENTIFIED */) {
|
|
573
604
|
// did not find a prepared connection, server already closed this connection; nothing to do here
|
|
574
605
|
return;
|
|
575
606
|
}
|
|
@@ -582,9 +613,9 @@ var DataStreamConnection = /** @class */ (function (_super) {
|
|
|
582
613
|
}
|
|
583
614
|
}
|
|
584
615
|
var messages = this.decodePayloads(frames); // decode contents of payload
|
|
585
|
-
if (this.state === 1 /* EXPECTING_HELLO */) {
|
|
616
|
+
if (this.state === 1 /* ConnectionState.EXPECTING_HELLO */) {
|
|
586
617
|
var firstMessage = messages[0];
|
|
587
|
-
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 */) {
|
|
588
619
|
// first message is not the expected hello request
|
|
589
620
|
debug("[%s] First message received was not the expected hello message. Instead got: %o", this.remoteAddress, firstMessage);
|
|
590
621
|
this.close();
|
|
@@ -592,8 +623,8 @@ var DataStreamConnection = /** @class */ (function (_super) {
|
|
|
592
623
|
}
|
|
593
624
|
}
|
|
594
625
|
messages.forEach(function (message) {
|
|
595
|
-
if (message.type === 3 /* RESPONSE */) {
|
|
596
|
-
// 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;
|
|
597
628
|
// probably they are as the requestId is unique per connection no matter what protocol is used
|
|
598
629
|
var responseHandler = _this.responseHandlers[message.id];
|
|
599
630
|
var responseTimer = _this.responseTimers[message.id];
|
|
@@ -619,10 +650,10 @@ var DataStreamConnection = /** @class */ (function (_super) {
|
|
|
619
650
|
var handler = _this.protocolHandlers[message.protocol];
|
|
620
651
|
if (handler === undefined) {
|
|
621
652
|
// send message to the server to check if there are some global handlers for it
|
|
622
|
-
_this.emit("handle-message-globally" /* HANDLE_MESSAGE_GLOBALLY */, message);
|
|
653
|
+
_this.emit("handle-message-globally" /* DataStreamConnectionEvent.HANDLE_MESSAGE_GLOBALLY */, message);
|
|
623
654
|
return;
|
|
624
655
|
}
|
|
625
|
-
if (message.type === 1 /* EVENT */) {
|
|
656
|
+
if (message.type === 1 /* MessageType.EVENT */) {
|
|
626
657
|
var eventHandler = void 0;
|
|
627
658
|
if (!handler.eventHandler || !(eventHandler = handler.eventHandler[message.topic])) {
|
|
628
659
|
debug("[%s] WARNING no event handler was found for message: %o", _this.remoteAddress, message);
|
|
@@ -636,7 +667,7 @@ var DataStreamConnection = /** @class */ (function (_super) {
|
|
|
636
667
|
debug(error.stack);
|
|
637
668
|
}
|
|
638
669
|
}
|
|
639
|
-
else if (message.type === 2 /* REQUEST */) {
|
|
670
|
+
else if (message.type === 2 /* MessageType.REQUEST */) {
|
|
640
671
|
var requestHandler = void 0;
|
|
641
672
|
if (!handler.requestHandler || !(requestHandler = handler.requestHandler[message.topic])) {
|
|
642
673
|
debug("[%s] WARNING no request handler was found for message: %o", _this.remoteAddress, message);
|
|
@@ -704,6 +735,9 @@ var DataStreamConnection = /** @class */ (function (_super) {
|
|
|
704
735
|
}
|
|
705
736
|
return frames;
|
|
706
737
|
};
|
|
738
|
+
/**
|
|
739
|
+
* @private file-private API
|
|
740
|
+
*/
|
|
707
741
|
DataStreamConnection.prototype.decryptHDSFrame = function (frame, keyOverwrite) {
|
|
708
742
|
hapCrypto.writeUInt64LE(this.controllerToAccessoryNonce, this.controllerToAccessoryNonceBuffer, 0); // update nonce buffer
|
|
709
743
|
var key = keyOverwrite || this.controllerToAccessoryEncryptionKey;
|
|
@@ -723,7 +757,7 @@ var DataStreamConnection = /** @class */ (function (_super) {
|
|
|
723
757
|
frames.forEach(function (frame) {
|
|
724
758
|
var payload = frame.plaintextPayload;
|
|
725
759
|
if (!payload) {
|
|
726
|
-
throw new HDSConnectionError("Reached illegal state. Encountered HDSFrame with wasn't decrypted yet!", 1 /* ILLEGAL_STATE */);
|
|
760
|
+
throw new HDSConnectionError("Reached illegal state. Encountered HDSFrame with wasn't decrypted yet!", 1 /* HDSConnectionErrorType.ILLEGAL_STATE */);
|
|
727
761
|
}
|
|
728
762
|
var headerLength = payload.readUInt8(0);
|
|
729
763
|
var messageLength = payload.length - headerLength - 1;
|
|
@@ -757,16 +791,16 @@ var DataStreamConnection = /** @class */ (function (_super) {
|
|
|
757
791
|
var id = undefined;
|
|
758
792
|
var status = undefined;
|
|
759
793
|
if (headerDictionary.event !== undefined) {
|
|
760
|
-
type = 1 /* EVENT */;
|
|
794
|
+
type = 1 /* MessageType.EVENT */;
|
|
761
795
|
topic = headerDictionary.event;
|
|
762
796
|
}
|
|
763
797
|
else if (headerDictionary.request !== undefined) {
|
|
764
|
-
type = 2 /* REQUEST */;
|
|
798
|
+
type = 2 /* MessageType.REQUEST */;
|
|
765
799
|
topic = headerDictionary.request;
|
|
766
800
|
id = headerDictionary.id;
|
|
767
801
|
}
|
|
768
802
|
else if (headerDictionary.response !== undefined) {
|
|
769
|
-
type = 3 /* RESPONSE */;
|
|
803
|
+
type = 3 /* MessageType.RESPONSE */;
|
|
770
804
|
topic = headerDictionary.response;
|
|
771
805
|
id = headerDictionary.id;
|
|
772
806
|
status = headerDictionary.status;
|
|
@@ -789,8 +823,8 @@ var DataStreamConnection = /** @class */ (function (_super) {
|
|
|
789
823
|
};
|
|
790
824
|
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
791
825
|
DataStreamConnection.prototype.sendHDSFrame = function (header, message) {
|
|
792
|
-
if (this.state >= 3 /* CLOSING */) {
|
|
793
|
-
throw new HDSConnectionError("Cannot send message on closing/closed socket!", 2 /* CLOSED_SOCKET */);
|
|
826
|
+
if (this.state >= 3 /* ConnectionState.CLOSING */) {
|
|
827
|
+
throw new HDSConnectionError("Cannot send message on closing/closed socket!", 2 /* HDSConnectionErrorType.CLOSED_SOCKET */);
|
|
794
828
|
}
|
|
795
829
|
var headerWriter = new DataStreamParser_1.DataStreamWriter();
|
|
796
830
|
var messageWriter = new DataStreamParser_1.DataStreamWriter();
|
|
@@ -800,7 +834,7 @@ var DataStreamConnection = /** @class */ (function (_super) {
|
|
|
800
834
|
payloadHeaderBuffer.writeUInt8(headerWriter.length(), 0);
|
|
801
835
|
var payloadBuffer = Buffer.concat([payloadHeaderBuffer, headerWriter.getData(), messageWriter.getData()]);
|
|
802
836
|
if (payloadBuffer.length > DataStreamConnection.MAX_PAYLOAD_LENGTH) {
|
|
803
|
-
throw new HDSConnectionError("Tried sending payload with length larger than the maximum allowed for data stream", 3 /* MAX_PAYLOAD_LENGTH */);
|
|
837
|
+
throw new HDSConnectionError("Tried sending payload with length larger than the maximum allowed for data stream", 3 /* HDSConnectionErrorType.MAX_PAYLOAD_LENGTH */);
|
|
804
838
|
}
|
|
805
839
|
var frameTypeBuffer = Buffer.alloc(1);
|
|
806
840
|
frameTypeBuffer.writeUInt8(1, 0);
|
|
@@ -824,14 +858,14 @@ var DataStreamConnection = /** @class */ (function (_super) {
|
|
|
824
858
|
//*/
|
|
825
859
|
};
|
|
826
860
|
DataStreamConnection.prototype.close = function () {
|
|
827
|
-
if (this.state >= 3 /* CLOSING */) {
|
|
861
|
+
if (this.state >= 3 /* ConnectionState.CLOSING */) {
|
|
828
862
|
return; // connection is already closing/closed
|
|
829
863
|
}
|
|
830
|
-
this.state = 3 /* CLOSING */;
|
|
864
|
+
this.state = 3 /* ConnectionState.CLOSING */;
|
|
831
865
|
this.socket.end();
|
|
832
866
|
};
|
|
833
867
|
DataStreamConnection.prototype.isConsideredClosed = function () {
|
|
834
|
-
return this.state >= 3 /* CLOSING */;
|
|
868
|
+
return this.state >= 3 /* ConnectionState.CLOSING */;
|
|
835
869
|
};
|
|
836
870
|
DataStreamConnection.prototype.onHAPSessionClosed = function () {
|
|
837
871
|
// If the hap connection is closed it is probably also a good idea to close the data stream connection
|
|
@@ -845,9 +879,9 @@ var DataStreamConnection = /** @class */ (function (_super) {
|
|
|
845
879
|
DataStreamConnection.prototype.onSocketClose = function () {
|
|
846
880
|
var _a;
|
|
847
881
|
// this instance is now considered completely dead
|
|
848
|
-
this.state = 4 /* CLOSED */;
|
|
849
|
-
this.emit("closed" /* CLOSED */);
|
|
850
|
-
(_a = this.connection) === null || _a === void 0 ? void 0 : _a.removeListener("closed" /* CLOSED */, this.hapConnectionClosedListener);
|
|
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);
|
|
851
885
|
this.removeAllListeners();
|
|
852
886
|
};
|
|
853
887
|
DataStreamConnection.MAX_PAYLOAD_LENGTH = 1048575;
|