hap-nodejs 0.10.0-beta.1 → 0.10.0-beta.10
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 +1 -1
- package/dist/BridgedCore.js +7 -6
- package/dist/BridgedCore.js.map +1 -1
- package/dist/Core.js +14 -12
- package/dist/Core.js.map +1 -1
- package/dist/accessories/AirConditioner_accessory.js +9 -9
- package/dist/accessories/AirConditioner_accessory.js.map +1 -1
- package/dist/accessories/AppleTVRemote_accessory.js +17 -16
- package/dist/accessories/AppleTVRemote_accessory.js.map +1 -1
- package/dist/accessories/Camera_accessory.js +415 -36
- package/dist/accessories/Camera_accessory.js.map +1 -1
- package/dist/accessories/Fan_accessory.js +10 -15
- package/dist/accessories/Fan_accessory.js.map +1 -1
- package/dist/accessories/GarageDoorOpener_accessory.js +7 -8
- package/dist/accessories/GarageDoorOpener_accessory.js.map +1 -1
- package/dist/accessories/Light-AdaptiveLighting_accessory.js +3 -4
- package/dist/accessories/Light-AdaptiveLighting_accessory.js.map +1 -1
- package/dist/accessories/Light_accessory.js +23 -14
- package/dist/accessories/Light_accessory.js.map +1 -1
- package/dist/accessories/Lock_accessory.js +7 -8
- package/dist/accessories/Lock_accessory.js.map +1 -1
- package/dist/accessories/MotionSensor_accessory.js +5 -6
- package/dist/accessories/MotionSensor_accessory.js.map +1 -1
- package/dist/accessories/Outlet_accessory.js +5 -6
- package/dist/accessories/Outlet_accessory.js.map +1 -1
- package/dist/accessories/SmartSpeaker_accessory.js +6 -6
- package/dist/accessories/SmartSpeaker_accessory.js.map +1 -1
- package/dist/accessories/Sprinkler_accessory.js +12 -13
- package/dist/accessories/Sprinkler_accessory.js.map +1 -1
- package/dist/accessories/TV_accessory.js +4 -5
- package/dist/accessories/TV_accessory.js.map +1 -1
- package/dist/accessories/TemperatureSensor_accessory.js +5 -6
- package/dist/accessories/TemperatureSensor_accessory.js.map +1 -1
- package/dist/accessories/Wi-FiRouter_accessory.d.ts +1 -1
- package/dist/accessories/Wi-FiRouter_accessory.d.ts.map +1 -1
- package/dist/accessories/Wi-FiRouter_accessory.js +7 -8
- package/dist/accessories/Wi-FiRouter_accessory.js.map +1 -1
- package/dist/accessories/Wi-FiSatellite_accessory.d.ts +1 -1
- package/dist/accessories/Wi-FiSatellite_accessory.d.ts.map +1 -1
- package/dist/accessories/Wi-FiSatellite_accessory.js +6 -7
- package/dist/accessories/Wi-FiSatellite_accessory.js.map +1 -1
- package/dist/accessories/gstreamer-audioProducer.d.ts.map +1 -1
- package/dist/accessories/gstreamer-audioProducer.js +21 -22
- package/dist/accessories/gstreamer-audioProducer.js.map +1 -1
- package/dist/index.d.ts +27 -22
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +35 -24
- package/dist/index.js.map +1 -1
- package/dist/internal-types.d.ts +2 -0
- package/dist/internal-types.d.ts.map +1 -1
- package/dist/internal-types.js.map +1 -1
- package/dist/lib/Accessory.d.ts +38 -17
- package/dist/lib/Accessory.d.ts.map +1 -1
- package/dist/lib/Accessory.js +345 -273
- package/dist/lib/Accessory.js.map +1 -1
- package/dist/lib/AccessoryLoader.d.ts +10 -10
- package/dist/lib/AccessoryLoader.d.ts.map +1 -1
- package/dist/lib/AccessoryLoader.js +109 -99
- package/dist/lib/AccessoryLoader.js.map +1 -1
- package/dist/lib/Advertiser.d.ts +23 -3
- package/dist/lib/Advertiser.d.ts.map +1 -1
- package/dist/lib/Advertiser.js +242 -29
- package/dist/lib/Advertiser.js.map +1 -1
- package/dist/lib/Bridge.d.ts +1 -1
- package/dist/lib/Bridge.d.ts.map +1 -1
- package/dist/lib/Bridge.js +1 -1
- package/dist/lib/Bridge.js.map +1 -1
- package/dist/lib/Characteristic.d.ts +22 -21
- package/dist/lib/Characteristic.d.ts.map +1 -1
- package/dist/lib/Characteristic.js +147 -144
- package/dist/lib/Characteristic.js.map +1 -1
- package/dist/lib/HAPServer.d.ts +2 -2
- package/dist/lib/HAPServer.d.ts.map +1 -1
- package/dist/lib/HAPServer.js +43 -39
- package/dist/lib/HAPServer.js.map +1 -1
- package/dist/lib/Service.d.ts +3 -3
- package/dist/lib/Service.d.ts.map +1 -1
- package/dist/lib/Service.js +51 -47
- package/dist/lib/Service.js.map +1 -1
- package/dist/lib/camera/Camera.d.ts +2 -2
- package/dist/lib/camera/Camera.d.ts.map +1 -1
- package/dist/lib/camera/Camera.js +3 -3
- package/dist/lib/camera/Camera.js.map +1 -1
- package/dist/lib/camera/RTPProxy.d.ts +19 -19
- package/dist/lib/camera/RTPProxy.d.ts.map +1 -1
- package/dist/lib/camera/RTPProxy.js +230 -208
- package/dist/lib/camera/RTPProxy.js.map +1 -1
- package/dist/lib/camera/RTPStreamManagement.d.ts +46 -10
- package/dist/lib/camera/RTPStreamManagement.d.ts.map +1 -1
- package/dist/lib/camera/RTPStreamManagement.js +124 -49
- package/dist/lib/camera/RTPStreamManagement.js.map +1 -1
- package/dist/lib/camera/RecordingManagement.d.ts +267 -0
- package/dist/lib/camera/RecordingManagement.d.ts.map +1 -0
- package/dist/lib/camera/RecordingManagement.js +750 -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 +4 -3
- package/dist/lib/camera/index.js.map +1 -1
- package/dist/lib/controller/AdaptiveLightingController.d.ts +9 -9
- package/dist/lib/controller/AdaptiveLightingController.d.ts.map +1 -1
- package/dist/lib/controller/AdaptiveLightingController.js +37 -31
- package/dist/lib/controller/AdaptiveLightingController.js.map +1 -1
- package/dist/lib/controller/CameraController.d.ts +253 -7
- package/dist/lib/controller/CameraController.d.ts.map +1 -1
- package/dist/lib/controller/CameraController.js +382 -35
- package/dist/lib/controller/CameraController.js.map +1 -1
- package/dist/lib/controller/Controller.d.ts +3 -3
- package/dist/lib/controller/Controller.d.ts.map +1 -1
- package/dist/lib/controller/Controller.js.map +1 -1
- package/dist/lib/controller/DoorbellController.d.ts +43 -1
- package/dist/lib/controller/DoorbellController.d.ts.map +1 -1
- package/dist/lib/controller/DoorbellController.js +64 -12
- package/dist/lib/controller/DoorbellController.js.map +1 -1
- package/dist/lib/controller/RemoteController.d.ts +4 -4
- package/dist/lib/controller/RemoteController.d.ts.map +1 -1
- package/dist/lib/controller/RemoteController.js +79 -69
- package/dist/lib/controller/RemoteController.js.map +1 -1
- package/dist/lib/controller/index.d.ts +4 -4
- package/dist/lib/controller/index.js +5 -5
- package/dist/lib/controller/index.js.map +1 -1
- package/dist/lib/datastream/DataStreamManagement.d.ts.map +1 -1
- package/dist/lib/datastream/DataStreamManagement.js +12 -11
- package/dist/lib/datastream/DataStreamManagement.js.map +1 -1
- package/dist/lib/datastream/DataStreamParser.d.ts +24 -24
- package/dist/lib/datastream/DataStreamParser.d.ts.map +1 -1
- package/dist/lib/datastream/DataStreamParser.js +31 -22
- package/dist/lib/datastream/DataStreamParser.js.map +1 -1
- package/dist/lib/datastream/DataStreamServer.d.ts +24 -5
- package/dist/lib/datastream/DataStreamServer.d.ts.map +1 -1
- package/dist/lib/datastream/DataStreamServer.js +109 -68
- package/dist/lib/datastream/DataStreamServer.js.map +1 -1
- package/dist/lib/datastream/index.d.ts +3 -3
- package/dist/lib/datastream/index.js +3 -3
- package/dist/lib/datastream/index.js.map +1 -1
- package/dist/lib/definitions/CharacteristicDefinitions.js +249 -249
- package/dist/lib/definitions/CharacteristicDefinitions.js.map +1 -1
- package/dist/lib/definitions/ServiceDefinitions.js +75 -75
- package/dist/lib/definitions/ServiceDefinitions.js.map +1 -1
- package/dist/lib/definitions/generate-definitions.d.ts.map +1 -1
- package/dist/lib/definitions/generate-definitions.js +76 -72
- 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 +34 -16
- 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 +6 -6
- package/dist/lib/model/AccessoryInfo.d.ts.map +1 -1
- package/dist/lib/model/AccessoryInfo.js +86 -76
- package/dist/lib/model/AccessoryInfo.js.map +1 -1
- package/dist/lib/model/ControllerStorage.d.ts.map +1 -1
- package/dist/lib/model/ControllerStorage.js +9 -9
- package/dist/lib/model/ControllerStorage.js.map +1 -1
- package/dist/lib/model/HAPStorage.d.ts.map +1 -1
- package/dist/lib/model/HAPStorage.js +2 -1
- package/dist/lib/model/HAPStorage.js.map +1 -1
- package/dist/lib/model/IdentifierCache.d.ts +11 -11
- package/dist/lib/model/IdentifierCache.d.ts.map +1 -1
- package/dist/lib/model/IdentifierCache.js +69 -67
- package/dist/lib/model/IdentifierCache.js.map +1 -1
- package/dist/lib/tv/AccessControlManagement.d.ts +1 -1
- package/dist/lib/tv/AccessControlManagement.d.ts.map +1 -1
- package/dist/lib/tv/AccessControlManagement.js +2 -2
- package/dist/lib/tv/AccessControlManagement.js.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.map +1 -1
- package/dist/lib/util/color-utils.js +2 -2
- package/dist/lib/util/color-utils.js.map +1 -1
- package/dist/lib/util/eventedhttp.d.ts +4 -4
- package/dist/lib/util/eventedhttp.d.ts.map +1 -1
- package/dist/lib/util/eventedhttp.js +54 -51
- package/dist/lib/util/eventedhttp.js.map +1 -1
- package/dist/lib/util/hapCrypto.d.ts +5 -5
- package/dist/lib/util/hapCrypto.d.ts.map +1 -1
- package/dist/lib/util/hapCrypto.js +66 -82
- package/dist/lib/util/hapCrypto.js.map +1 -1
- package/dist/lib/util/hapStatusError.js +3 -3
- package/dist/lib/util/hapStatusError.js.map +1 -1
- package/dist/lib/util/net-utils.d.ts.map +1 -1
- package/dist/lib/util/net-utils.js +4 -6
- package/dist/lib/util/net-utils.js.map +1 -1
- package/dist/lib/util/once.d.ts +1 -1
- package/dist/lib/util/once.d.ts.map +1 -1
- package/dist/lib/util/once.js +2 -1
- package/dist/lib/util/once.js.map +1 -1
- package/dist/lib/util/promise-utils.d.ts +2 -0
- package/dist/lib/util/promise-utils.d.ts.map +1 -0
- package/dist/lib/util/promise-utils.js +10 -0
- package/dist/lib/util/promise-utils.js.map +1 -0
- package/dist/lib/util/request-util.d.ts.map +1 -1
- package/dist/lib/util/request-util.js +1 -0
- package/dist/lib/util/request-util.js.map +1 -1
- package/dist/lib/util/time.d.ts +1 -1
- package/dist/lib/util/time.d.ts.map +1 -1
- package/dist/lib/util/time.js +8 -8
- package/dist/lib/util/time.js.map +1 -1
- package/dist/lib/util/tlv.d.ts.map +1 -1
- package/dist/lib/util/tlv.js +15 -12
- package/dist/lib/util/tlv.js.map +1 -1
- package/dist/lib/util/uuid.d.ts.map +1 -1
- package/dist/lib/util/uuid.js +26 -20
- package/dist/lib/util/uuid.js.map +1 -1
- package/dist/types.d.ts +0 -1
- package/dist/types.d.ts.map +1 -1
- package/package.json +22 -19
package/dist/lib/Accessory.js
CHANGED
|
@@ -2,11 +2,11 @@
|
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.Accessory = exports.AccessoryEventTypes = exports.MDNSAdvertiser = exports.CharacteristicWarningType = exports.Categories = void 0;
|
|
4
4
|
var tslib_1 = require("tslib");
|
|
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"));
|
|
5
|
+
var assert_1 = (0, tslib_1.__importDefault)(require("assert"));
|
|
6
|
+
var crypto_1 = (0, tslib_1.__importDefault)(require("crypto"));
|
|
7
|
+
var debug_1 = (0, tslib_1.__importDefault)(require("debug"));
|
|
8
8
|
var events_1 = require("events");
|
|
9
|
-
var net_1 = tslib_1.__importDefault(require("net"));
|
|
9
|
+
var net_1 = (0, tslib_1.__importDefault)(require("net"));
|
|
10
10
|
var Advertiser_1 = require("./Advertiser");
|
|
11
11
|
// noinspection JSDeprecatedSymbols
|
|
12
12
|
var camera_1 = require("./camera");
|
|
@@ -19,9 +19,9 @@ var IdentifierCache_1 = require("./model/IdentifierCache");
|
|
|
19
19
|
var Service_1 = require("./Service");
|
|
20
20
|
var clone_1 = require("./util/clone");
|
|
21
21
|
var request_util_1 = require("./util/request-util");
|
|
22
|
-
var uuid = tslib_1.__importStar(require("./util/uuid"));
|
|
22
|
+
var uuid = (0, tslib_1.__importStar)(require("./util/uuid"));
|
|
23
23
|
var uuid_1 = require("./util/uuid");
|
|
24
|
-
var debug = debug_1.default(
|
|
24
|
+
var debug = (0, debug_1.default)("HAP-NodeJS:Accessory");
|
|
25
25
|
var MAX_ACCESSORIES = 149; // Maximum number of bridged accessories per bridge.
|
|
26
26
|
var MAX_SERVICES = 100;
|
|
27
27
|
// Known category values. Category is a hint to iOS clients about what "type" of Accessory this represents, for UI only.
|
|
@@ -87,6 +87,10 @@ var MDNSAdvertiser;
|
|
|
87
87
|
* Use the `bonjour-hap` module as advertiser.
|
|
88
88
|
*/
|
|
89
89
|
MDNSAdvertiser["BONJOUR"] = "bonjour-hap";
|
|
90
|
+
/**
|
|
91
|
+
* Use Avahi/D-Bus as advertiser.
|
|
92
|
+
*/
|
|
93
|
+
MDNSAdvertiser["AVAHI"] = "avahi";
|
|
90
94
|
})(MDNSAdvertiser = exports.MDNSAdvertiser || (exports.MDNSAdvertiser = {}));
|
|
91
95
|
var WriteRequestState;
|
|
92
96
|
(function (WriteRequestState) {
|
|
@@ -105,7 +109,16 @@ var AccessoryEventTypes;
|
|
|
105
109
|
* You must call the callback for identification to be successful.
|
|
106
110
|
*/
|
|
107
111
|
AccessoryEventTypes["IDENTIFY"] = "identify";
|
|
112
|
+
/**
|
|
113
|
+
* This event is emitted once the HAP TCP socket is bound.
|
|
114
|
+
* At this point the mdns advertisement isn't yet available. Use the {@link ADVERTISED} if you require the accessory to be discoverable.
|
|
115
|
+
*/
|
|
108
116
|
AccessoryEventTypes["LISTENING"] = "listening";
|
|
117
|
+
/**
|
|
118
|
+
* This event is emitted once the mDNS suite has fully advertised the presence of the accessory.
|
|
119
|
+
* This event is guaranteed to be called after {@link LISTENING}.
|
|
120
|
+
*/
|
|
121
|
+
AccessoryEventTypes["ADVERTISED"] = "advertised";
|
|
109
122
|
AccessoryEventTypes["SERVICE_CONFIGURATION_CHANGE"] = "service-configurationChange";
|
|
110
123
|
/**
|
|
111
124
|
* Emitted after a change in the value of one of the provided Service's Characteristics.
|
|
@@ -125,7 +138,7 @@ var AccessoryEventTypes;
|
|
|
125
138
|
* Accessories, Services, and Characteristics for iOS clients to reference later.
|
|
126
139
|
*/
|
|
127
140
|
var Accessory = /** @class */ (function (_super) {
|
|
128
|
-
tslib_1.__extends(Accessory, _super);
|
|
141
|
+
(0, tslib_1.__extends)(Accessory, _super);
|
|
129
142
|
function Accessory(displayName, UUID) {
|
|
130
143
|
var _this = _super.call(this) || this;
|
|
131
144
|
_this.displayName = displayName;
|
|
@@ -139,11 +152,17 @@ var Accessory = /** @class */ (function (_super) {
|
|
|
139
152
|
_this.category = 1 /* OTHER */;
|
|
140
153
|
_this.services = [];
|
|
141
154
|
_this.shouldPurgeUnusedIDs = true; // Purge unused ids by default
|
|
155
|
+
/**
|
|
156
|
+
* Captures if initialization steps inside {@link publish} have been called.
|
|
157
|
+
* This is important when calling {@link publish} multiple times (e.g. after calling {@link unpublish}).
|
|
158
|
+
* @private Private API
|
|
159
|
+
*/
|
|
160
|
+
_this.initialized = false;
|
|
142
161
|
_this.controllers = {};
|
|
143
162
|
_this._setupID = null;
|
|
144
163
|
_this.controllerStorage = new ControllerStorage_1.ControllerStorage(_this);
|
|
145
164
|
/**
|
|
146
|
-
* This property captures the time when we last
|
|
165
|
+
* This property captures the time when we last served a /accessories request.
|
|
147
166
|
* For multiple bursts of /accessories request we don't want to always contact GET handlers
|
|
148
167
|
*/
|
|
149
168
|
_this.lastAccessoriesRequest = 0;
|
|
@@ -156,32 +175,14 @@ var Accessory = /** @class */ (function (_super) {
|
|
|
156
175
|
_this.getPrimaryAccessory = function () {
|
|
157
176
|
return _this.bridged ? _this.bridge : _this;
|
|
158
177
|
};
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
_this.shouldPurgeUnusedIDs = true;
|
|
164
|
-
};
|
|
165
|
-
/**
|
|
166
|
-
* Manually purge the unused ids if you like, comes handy
|
|
167
|
-
* when you have disabled auto purge so you can do it manually
|
|
168
|
-
*/
|
|
169
|
-
_this.purgeUnusedIDs = function () {
|
|
170
|
-
//Cache the state of the purge mechanism and set it to true
|
|
171
|
-
var oldValue = _this.shouldPurgeUnusedIDs;
|
|
172
|
-
_this.shouldPurgeUnusedIDs = true;
|
|
173
|
-
//Reassign all ids
|
|
174
|
-
_this._assignIDs(_this._identifierCache);
|
|
175
|
-
//Revert back the purge mechanism state
|
|
176
|
-
_this.shouldPurgeUnusedIDs = oldValue;
|
|
177
|
-
};
|
|
178
|
-
assert_1.default(displayName, "Accessories must be created with a non-empty displayName.");
|
|
179
|
-
assert_1.default(UUID, "Accessories must be created with a valid UUID.");
|
|
180
|
-
assert_1.default(uuid.isValid(UUID), "UUID '" + UUID + "' is not a valid UUID. Try using the provided 'generateUUID' function to create a valid UUID from any arbitrary string, like a serial number.");
|
|
178
|
+
(0, assert_1.default)(displayName, "Accessories must be created with a non-empty displayName.");
|
|
179
|
+
(0, assert_1.default)(UUID, "Accessories must be created with a valid UUID.");
|
|
180
|
+
(0, assert_1.default)(uuid.isValid(UUID), "UUID '" + UUID + "' is not a valid UUID. Try using the provided 'generateUUID' function to create a " +
|
|
181
|
+
"valid UUID from any arbitrary string, like a serial number.");
|
|
181
182
|
// create our initial "Accessory Information" Service that all Accessories are expected to have
|
|
182
183
|
_this.addService(Service_1.Service.AccessoryInformation)
|
|
183
184
|
.setCharacteristic(Characteristic_1.Characteristic.Name, displayName);
|
|
184
|
-
// sign up for when iOS attempts to "set" the Identify characteristic - this means a paired device wishes
|
|
185
|
+
// sign up for when iOS attempts to "set" the `Identify` characteristic - this means a paired device wishes
|
|
185
186
|
// for us to identify ourselves (as opposed to an unpaired device - that case is handled by HAPServer 'identify' event)
|
|
186
187
|
_this.getService(Service_1.Service.AccessoryInformation)
|
|
187
188
|
.getCharacteristic(Characteristic_1.Characteristic.Identify)
|
|
@@ -205,6 +206,7 @@ var Accessory = /** @class */ (function (_super) {
|
|
|
205
206
|
callback();
|
|
206
207
|
}
|
|
207
208
|
};
|
|
209
|
+
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
208
210
|
Accessory.prototype.addService = function (serviceParam) {
|
|
209
211
|
var e_1, _a;
|
|
210
212
|
var constructorArgs = [];
|
|
@@ -213,19 +215,23 @@ var Accessory = /** @class */ (function (_super) {
|
|
|
213
215
|
}
|
|
214
216
|
// service might be a constructor like `Service.AccessoryInformation` instead of an instance
|
|
215
217
|
// of Service. Coerce if necessary.
|
|
216
|
-
var service = typeof serviceParam ===
|
|
218
|
+
var service = typeof serviceParam === "function"
|
|
217
219
|
? new serviceParam(constructorArgs[0], constructorArgs[1], constructorArgs[2])
|
|
218
220
|
: serviceParam;
|
|
219
221
|
try {
|
|
220
222
|
// check for UUID+subtype conflict
|
|
221
|
-
for (var _b = tslib_1.__values(this.services), _c = _b.next(); !_c.done; _c = _b.next()) {
|
|
223
|
+
for (var _b = (0, tslib_1.__values)(this.services), _c = _b.next(); !_c.done; _c = _b.next()) {
|
|
222
224
|
var existing = _c.value;
|
|
223
225
|
if (existing.UUID === service.UUID) {
|
|
224
226
|
// OK we have two Services with the same UUID. Check that each defines a `subtype` property and that each is unique.
|
|
225
|
-
if (!service.subtype)
|
|
226
|
-
throw new Error("Cannot add a Service with the same UUID '" + existing.UUID +
|
|
227
|
-
|
|
228
|
-
|
|
227
|
+
if (!service.subtype) {
|
|
228
|
+
throw new Error("Cannot add a Service with the same UUID '" + existing.UUID +
|
|
229
|
+
"' as another Service in this Accessory without also defining a unique 'subtype' property.");
|
|
230
|
+
}
|
|
231
|
+
if (service.subtype === existing.subtype) {
|
|
232
|
+
throw new Error("Cannot add a Service with the same UUID '" + existing.UUID +
|
|
233
|
+
"' and subtype '" + existing.subtype + "' as another Service in this Accessory.");
|
|
234
|
+
}
|
|
229
235
|
}
|
|
230
236
|
}
|
|
231
237
|
}
|
|
@@ -281,7 +287,7 @@ var Accessory = /** @class */ (function (_super) {
|
|
|
281
287
|
Accessory.prototype.removeLinkedService = function (removed) {
|
|
282
288
|
var e_2, _a;
|
|
283
289
|
try {
|
|
284
|
-
for (var _b = tslib_1.__values(this.services), _c = _b.next(); !_c.done; _c = _b.next()) {
|
|
290
|
+
for (var _b = (0, tslib_1.__values)(this.services), _c = _b.next(); !_c.done; _c = _b.next()) {
|
|
285
291
|
var service = _c.value;
|
|
286
292
|
service.removeLinkedService(removed);
|
|
287
293
|
}
|
|
@@ -297,12 +303,13 @@ var Accessory = /** @class */ (function (_super) {
|
|
|
297
303
|
Accessory.prototype.getService = function (name) {
|
|
298
304
|
var e_3, _a;
|
|
299
305
|
try {
|
|
300
|
-
for (var _b = tslib_1.__values(this.services), _c = _b.next(); !_c.done; _c = _b.next()) {
|
|
306
|
+
for (var _b = (0, tslib_1.__values)(this.services), _c = _b.next(); !_c.done; _c = _b.next()) {
|
|
301
307
|
var service = _c.value;
|
|
302
|
-
if (typeof name ===
|
|
308
|
+
if (typeof name === "string" && (service.displayName === name || service.name === name || service.subtype === name)) {
|
|
303
309
|
return service;
|
|
310
|
+
// @ts-expect-error: UUID property
|
|
304
311
|
}
|
|
305
|
-
else if (typeof name ===
|
|
312
|
+
else if (typeof name === "function" && ((service instanceof name) || (name.UUID === service.UUID))) {
|
|
306
313
|
return service;
|
|
307
314
|
}
|
|
308
315
|
}
|
|
@@ -319,10 +326,11 @@ var Accessory = /** @class */ (function (_super) {
|
|
|
319
326
|
Accessory.prototype.getServiceById = function (uuid, subType) {
|
|
320
327
|
var e_4, _a;
|
|
321
328
|
try {
|
|
322
|
-
for (var _b = tslib_1.__values(this.services), _c = _b.next(); !_c.done; _c = _b.next()) {
|
|
329
|
+
for (var _b = (0, tslib_1.__values)(this.services), _c = _b.next(); !_c.done; _c = _b.next()) {
|
|
323
330
|
var service = _c.value;
|
|
324
331
|
if (typeof uuid === "string" && (service.displayName === uuid || service.name === uuid) && service.subtype === subType) {
|
|
325
332
|
return service;
|
|
333
|
+
// @ts-expect-error: UUID property
|
|
326
334
|
}
|
|
327
335
|
else if (typeof uuid === "function" && ((service instanceof uuid) || (uuid.UUID === service.UUID)) && service.subtype === subType) {
|
|
328
336
|
return service;
|
|
@@ -342,10 +350,11 @@ var Accessory = /** @class */ (function (_super) {
|
|
|
342
350
|
* @deprecated Not supported anymore
|
|
343
351
|
*/
|
|
344
352
|
Accessory.prototype.updateReachability = function (reachable) {
|
|
345
|
-
if (!this.bridged)
|
|
353
|
+
if (!this.bridged) {
|
|
346
354
|
throw new Error("Cannot update reachability on non-bridged accessory!");
|
|
355
|
+
}
|
|
347
356
|
this.reachable = reachable;
|
|
348
|
-
debug(
|
|
357
|
+
debug("Reachability update is no longer being supported.");
|
|
349
358
|
};
|
|
350
359
|
Accessory.prototype.addBridgedAccessory = function (accessory, deferUpdate) {
|
|
351
360
|
var e_5, _a;
|
|
@@ -356,7 +365,7 @@ var Accessory = /** @class */ (function (_super) {
|
|
|
356
365
|
}
|
|
357
366
|
try {
|
|
358
367
|
// check for UUID conflict
|
|
359
|
-
for (var _b = tslib_1.__values(this.bridgedAccessories), _c = _b.next(); !_c.done; _c = _b.next()) {
|
|
368
|
+
for (var _b = (0, tslib_1.__values)(this.bridgedAccessories), _c = _b.next(); !_c.done; _c = _b.next()) {
|
|
360
369
|
var existing = _c.value;
|
|
361
370
|
if (existing.UUID === accessory.UUID) {
|
|
362
371
|
throw new Error("Cannot add a bridged Accessory with the same UUID as another bridged Accessory: " + existing.UUID);
|
|
@@ -389,7 +398,7 @@ var Accessory = /** @class */ (function (_super) {
|
|
|
389
398
|
Accessory.prototype.addBridgedAccessories = function (accessories) {
|
|
390
399
|
var e_6, _a;
|
|
391
400
|
try {
|
|
392
|
-
for (var accessories_1 = tslib_1.__values(accessories), accessories_1_1 = accessories_1.next(); !accessories_1_1.done; accessories_1_1 = accessories_1.next()) {
|
|
401
|
+
for (var accessories_1 = (0, tslib_1.__values)(accessories), accessories_1_1 = accessories_1.next(); !accessories_1_1.done; accessories_1_1 = accessories_1.next()) {
|
|
393
402
|
var accessory = accessories_1_1.value;
|
|
394
403
|
this.addBridgedAccessory(accessory, true);
|
|
395
404
|
}
|
|
@@ -404,14 +413,16 @@ var Accessory = /** @class */ (function (_super) {
|
|
|
404
413
|
this.enqueueConfigurationUpdate();
|
|
405
414
|
};
|
|
406
415
|
Accessory.prototype.removeBridgedAccessory = function (accessory, deferUpdate) {
|
|
407
|
-
if (accessory._isBridge)
|
|
416
|
+
if (accessory._isBridge) {
|
|
408
417
|
throw new Error("Cannot Bridge another Bridge!");
|
|
418
|
+
}
|
|
409
419
|
// check for UUID conflict
|
|
410
420
|
var foundMatchAccessory = this.bridgedAccessories.findIndex(function (existing) {
|
|
411
421
|
return existing.UUID === accessory.UUID;
|
|
412
422
|
});
|
|
413
|
-
if (foundMatchAccessory === -1)
|
|
423
|
+
if (foundMatchAccessory === -1) {
|
|
414
424
|
throw new Error("Cannot find the bridged Accessory to remove.");
|
|
425
|
+
}
|
|
415
426
|
this.bridgedAccessories.splice(foundMatchAccessory, 1);
|
|
416
427
|
accessory.removeAllListeners();
|
|
417
428
|
if (!deferUpdate) {
|
|
@@ -421,7 +432,7 @@ var Accessory = /** @class */ (function (_super) {
|
|
|
421
432
|
Accessory.prototype.removeBridgedAccessories = function (accessories) {
|
|
422
433
|
var e_7, _a;
|
|
423
434
|
try {
|
|
424
|
-
for (var accessories_2 = tslib_1.__values(accessories), accessories_2_1 = accessories_2.next(); !accessories_2_1.done; accessories_2_1 = accessories_2.next()) {
|
|
435
|
+
for (var accessories_2 = (0, tslib_1.__values)(accessories), accessories_2_1 = accessories_2.next(); !accessories_2_1.done; accessories_2_1 = accessories_2.next()) {
|
|
425
436
|
var accessory = accessories_2_1.value;
|
|
426
437
|
this.removeBridgedAccessory(accessory, true);
|
|
427
438
|
}
|
|
@@ -444,7 +455,7 @@ var Accessory = /** @class */ (function (_super) {
|
|
|
444
455
|
Accessory.prototype.getCharacteristicByIID = function (iid) {
|
|
445
456
|
var e_8, _a;
|
|
446
457
|
try {
|
|
447
|
-
for (var _b = tslib_1.__values(this.services), _c = _b.next(); !_c.done; _c = _b.next()) {
|
|
458
|
+
for (var _b = (0, tslib_1.__values)(this.services), _c = _b.next(); !_c.done; _c = _b.next()) {
|
|
448
459
|
var service = _c.value;
|
|
449
460
|
var characteristic = service.getCharacteristicByIID(iid);
|
|
450
461
|
if (characteristic) {
|
|
@@ -466,7 +477,7 @@ var Accessory = /** @class */ (function (_super) {
|
|
|
466
477
|
return this;
|
|
467
478
|
}
|
|
468
479
|
try {
|
|
469
|
-
for (var _b = tslib_1.__values(this.bridgedAccessories), _c = _b.next(); !_c.done; _c = _b.next()) {
|
|
480
|
+
for (var _b = (0, tslib_1.__values)(this.bridgedAccessories), _c = _b.next(); !_c.done; _c = _b.next()) {
|
|
470
481
|
var accessory = _c.value;
|
|
471
482
|
if (accessory.aid === aid) {
|
|
472
483
|
return accessory;
|
|
@@ -529,7 +540,7 @@ var Accessory = /** @class */ (function (_super) {
|
|
|
529
540
|
return; // ignore those services, as they get replaced by the RTPStreamManagement
|
|
530
541
|
}
|
|
531
542
|
// all other services get added. We can't really control possibly linking to any of those ignored services
|
|
532
|
-
// so this is really only half
|
|
543
|
+
// so this is really only half-baked stuff.
|
|
533
544
|
_this.addService(service);
|
|
534
545
|
});
|
|
535
546
|
// replace stream controllers; basically only to still support the "forceStop" call
|
|
@@ -558,15 +569,15 @@ var Accessory = /** @class */ (function (_super) {
|
|
|
558
569
|
: controllerConstructor;
|
|
559
570
|
var id = controller.controllerId();
|
|
560
571
|
if (this.controllers[id]) {
|
|
561
|
-
throw new Error("A Controller with the type/id '"
|
|
572
|
+
throw new Error("A Controller with the type/id '".concat(id, "' was already added to the accessory ").concat(this.displayName));
|
|
562
573
|
}
|
|
563
574
|
var savedServiceMap = this.serializedControllers && this.serializedControllers[id];
|
|
564
575
|
var serviceMap;
|
|
565
576
|
if (savedServiceMap) { // we found data to restore from
|
|
566
|
-
var clonedServiceMap = clone_1.clone(savedServiceMap);
|
|
577
|
+
var clonedServiceMap = (0, clone_1.clone)(savedServiceMap);
|
|
567
578
|
var updatedServiceMap = controller.initWithServices(savedServiceMap); // init controller with existing services
|
|
568
|
-
serviceMap = updatedServiceMap || savedServiceMap; // initWithServices could return
|
|
569
|
-
if (updatedServiceMap) { // controller returned a ServiceMap and thus signaled
|
|
579
|
+
serviceMap = updatedServiceMap || savedServiceMap; // initWithServices could return an updated serviceMap, otherwise just use the existing one
|
|
580
|
+
if (updatedServiceMap) { // controller returned a ServiceMap and thus signaled an updated set of services
|
|
570
581
|
// clonedServiceMap is altered by this method, should not be touched again after this call (for the future people)
|
|
571
582
|
this.handleUpdatedControllerServiceMap(clonedServiceMap, updatedServiceMap);
|
|
572
583
|
}
|
|
@@ -591,7 +602,7 @@ var Accessory = /** @class */ (function (_super) {
|
|
|
591
602
|
controller: controller,
|
|
592
603
|
serviceMap: serviceMap,
|
|
593
604
|
};
|
|
594
|
-
if (controller_1.isSerializableController(controller)) {
|
|
605
|
+
if ((0, controller_1.isSerializableController)(controller)) {
|
|
595
606
|
this.controllerStorage.trackController(controller);
|
|
596
607
|
}
|
|
597
608
|
this.controllers[id] = context;
|
|
@@ -612,9 +623,10 @@ var Accessory = /** @class */ (function (_super) {
|
|
|
612
623
|
var storedController = this.controllers[id];
|
|
613
624
|
if (storedController) {
|
|
614
625
|
if (storedController.controller !== controller) {
|
|
615
|
-
throw new Error("[" + this.displayName + "] tried removing a controller with the id/type '" + id +
|
|
626
|
+
throw new Error("[" + this.displayName + "] tried removing a controller with the id/type '" + id +
|
|
627
|
+
"' though provided controller isn't the same which is registered!");
|
|
616
628
|
}
|
|
617
|
-
if (controller_1.isSerializableController(controller)) {
|
|
629
|
+
if ((0, controller_1.isSerializableController)(controller)) {
|
|
618
630
|
// this will reset the state change delegate before we call handleControllerRemoved()
|
|
619
631
|
this.controllerStorage.untrackController(controller);
|
|
620
632
|
}
|
|
@@ -639,13 +651,13 @@ var Accessory = /** @class */ (function (_super) {
|
|
|
639
651
|
Accessory.prototype.handleAccessoryUnpairedForControllers = function () {
|
|
640
652
|
var e_10, _a;
|
|
641
653
|
try {
|
|
642
|
-
for (var _b = tslib_1.__values(Object.values(this.controllers)), _c = _b.next(); !_c.done; _c = _b.next()) {
|
|
654
|
+
for (var _b = (0, tslib_1.__values)(Object.values(this.controllers)), _c = _b.next(); !_c.done; _c = _b.next()) {
|
|
643
655
|
var context = _c.value;
|
|
644
656
|
var controller = context.controller;
|
|
645
657
|
if (controller.handleFactoryReset) { // if the controller implements handleFactoryReset, setup event handlers for this controller
|
|
646
658
|
controller.handleFactoryReset();
|
|
647
659
|
}
|
|
648
|
-
if (controller_1.isSerializableController(controller)) {
|
|
660
|
+
if ((0, controller_1.isSerializableController)(controller)) {
|
|
649
661
|
this.controllerStorage.purgeControllerData(controller);
|
|
650
662
|
}
|
|
651
663
|
}
|
|
@@ -660,7 +672,7 @@ var Accessory = /** @class */ (function (_super) {
|
|
|
660
672
|
};
|
|
661
673
|
Accessory.prototype.handleUpdatedControllerServiceMap = function (originalServiceMap, updatedServiceMap) {
|
|
662
674
|
var _this = this;
|
|
663
|
-
updatedServiceMap = clone_1.clone(updatedServiceMap); // clone it so we can alter it
|
|
675
|
+
updatedServiceMap = (0, clone_1.clone)(updatedServiceMap); // clone it so we can alter it
|
|
664
676
|
Object.keys(originalServiceMap).forEach(function (name) {
|
|
665
677
|
var service = originalServiceMap[name];
|
|
666
678
|
var updatedService = updatedServiceMap[name];
|
|
@@ -690,7 +702,7 @@ var Accessory = /** @class */ (function (_super) {
|
|
|
690
702
|
return this._setupURI;
|
|
691
703
|
}
|
|
692
704
|
var buffer = Buffer.alloc(8);
|
|
693
|
-
var setupCode = this._accessoryInfo && parseInt(this._accessoryInfo.pincode.replace(/-/g,
|
|
705
|
+
var setupCode = this._accessoryInfo && parseInt(this._accessoryInfo.pincode.replace(/-/g, ""), 10);
|
|
694
706
|
var value_low = setupCode;
|
|
695
707
|
var value_high = this._accessoryInfo && this._accessoryInfo.category >> 1;
|
|
696
708
|
value_low |= 1 << 28; // Supports IP;
|
|
@@ -700,7 +712,7 @@ var Accessory = /** @class */ (function (_super) {
|
|
|
700
712
|
}
|
|
701
713
|
buffer.writeUInt32BE(value_high, 0);
|
|
702
714
|
var encodedPayload = (buffer.readUInt32BE(4) + (buffer.readUInt32BE(0) * Math.pow(2, 32))).toString(36).toUpperCase();
|
|
703
|
-
if (encodedPayload.length
|
|
715
|
+
if (encodedPayload.length !== 9) {
|
|
704
716
|
for (var i = 0; i <= 9 - encodedPayload.length; i++) {
|
|
705
717
|
encodedPayload = "0" + encodedPayload;
|
|
706
718
|
}
|
|
@@ -721,6 +733,7 @@ var Accessory = /** @class */ (function (_super) {
|
|
|
721
733
|
"This might prevent the accessory from being added to the Home app or leading to the accessory being unresponsive!");
|
|
722
734
|
}
|
|
723
735
|
else {
|
|
736
|
+
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
724
737
|
var checkValue = function (name, value) {
|
|
725
738
|
if (!value) {
|
|
726
739
|
console.log("HAP-NodeJS WARNING: The accessory '" + _this.displayName + "' is getting published with the characteristic '" + name + "'" +
|
|
@@ -739,7 +752,7 @@ var Accessory = /** @class */ (function (_super) {
|
|
|
739
752
|
}
|
|
740
753
|
if (mainAccessory) {
|
|
741
754
|
// the main accessory which is advertised via bonjour must have a name with length <= 63 (limitation of DNS FQDN names)
|
|
742
|
-
assert_1.default(Buffer.from(this.displayName, "utf8").length <= 63, "Accessory displayName cannot be longer than 63 bytes!");
|
|
755
|
+
(0, assert_1.default)(Buffer.from(this.displayName, "utf8").length <= 63, "Accessory displayName cannot be longer than 63 bytes!");
|
|
743
756
|
}
|
|
744
757
|
if (this.bridged) {
|
|
745
758
|
this.bridgedAccessories.forEach(function (accessory) { return accessory.validateAccessory(); });
|
|
@@ -767,7 +780,7 @@ var Accessory = /** @class */ (function (_super) {
|
|
|
767
780
|
this.aid = 1;
|
|
768
781
|
}
|
|
769
782
|
try {
|
|
770
|
-
for (var _c = tslib_1.__values(this.services), _d = _c.next(); !_d.done; _d = _c.next()) {
|
|
783
|
+
for (var _c = (0, tslib_1.__values)(this.services), _d = _c.next(); !_d.done; _d = _c.next()) {
|
|
771
784
|
var service = _d.value;
|
|
772
785
|
if (this._isBridge) {
|
|
773
786
|
service._assignIDs(identifierCache, this.UUID, 2000000000);
|
|
@@ -786,7 +799,7 @@ var Accessory = /** @class */ (function (_super) {
|
|
|
786
799
|
}
|
|
787
800
|
try {
|
|
788
801
|
// now assign IDs for any Accessories we are bridging
|
|
789
|
-
for (var _e = tslib_1.__values(this.bridgedAccessories), _f = _e.next(); !_f.done; _f = _e.next()) {
|
|
802
|
+
for (var _e = (0, tslib_1.__values)(this.bridgedAccessories), _f = _e.next(); !_f.done; _f = _e.next()) {
|
|
790
803
|
var accessory = _f.value;
|
|
791
804
|
accessory._assignIDs(identifierCache);
|
|
792
805
|
}
|
|
@@ -802,25 +815,45 @@ var Accessory = /** @class */ (function (_super) {
|
|
|
802
815
|
// that have been removed since the last call to assignIDs())
|
|
803
816
|
if (this._identifierCache) {
|
|
804
817
|
//Check weather we want to purge the unused ids
|
|
805
|
-
if (this.shouldPurgeUnusedIDs)
|
|
818
|
+
if (this.shouldPurgeUnusedIDs) {
|
|
806
819
|
this._identifierCache.stopTrackingUsageAndExpireUnused();
|
|
820
|
+
}
|
|
807
821
|
//Save in case we have new ones
|
|
808
822
|
this._identifierCache.save();
|
|
809
823
|
}
|
|
810
824
|
};
|
|
825
|
+
Accessory.prototype.disableUnusedIDPurge = function () {
|
|
826
|
+
this.shouldPurgeUnusedIDs = false;
|
|
827
|
+
};
|
|
828
|
+
Accessory.prototype.enableUnusedIDPurge = function () {
|
|
829
|
+
this.shouldPurgeUnusedIDs = true;
|
|
830
|
+
};
|
|
831
|
+
/**
|
|
832
|
+
* Manually purge the unused ids if you like, comes handy
|
|
833
|
+
* when you have disabled auto purge so you can do it manually
|
|
834
|
+
*/
|
|
835
|
+
Accessory.prototype.purgeUnusedIDs = function () {
|
|
836
|
+
//Cache the state of the purge mechanism and set it to true
|
|
837
|
+
var oldValue = this.shouldPurgeUnusedIDs;
|
|
838
|
+
this.shouldPurgeUnusedIDs = true;
|
|
839
|
+
//Reassign all ids
|
|
840
|
+
this._assignIDs(this._identifierCache);
|
|
841
|
+
// Revert the purge mechanism state
|
|
842
|
+
this.shouldPurgeUnusedIDs = oldValue;
|
|
843
|
+
};
|
|
811
844
|
/**
|
|
812
845
|
* Returns a JSON representation of this accessory suitable for delivering to HAP clients.
|
|
813
846
|
*/
|
|
814
847
|
Accessory.prototype.toHAP = function (connection, contactGetHandlers) {
|
|
815
848
|
if (contactGetHandlers === void 0) { contactGetHandlers = true; }
|
|
816
|
-
return tslib_1.__awaiter(this, void 0, void 0, function () {
|
|
849
|
+
return (0, tslib_1.__awaiter)(this, void 0, void 0, function () {
|
|
817
850
|
var accessory, accessories, _a, _b, _c, _d;
|
|
818
851
|
var _e;
|
|
819
|
-
return tslib_1.__generator(this, function (_f) {
|
|
852
|
+
return (0, tslib_1.__generator)(this, function (_f) {
|
|
820
853
|
switch (_f.label) {
|
|
821
854
|
case 0:
|
|
822
|
-
assert_1.default(this.aid, "aid cannot be undefined for accessory '" + this.displayName + "'");
|
|
823
|
-
assert_1.default(this.services.length, "accessory '" + this.displayName + "' does not have any services!");
|
|
855
|
+
(0, assert_1.default)(this.aid, "aid cannot be undefined for accessory '" + this.displayName + "'");
|
|
856
|
+
(0, assert_1.default)(this.services.length, "accessory '" + this.displayName + "' does not have any services!");
|
|
824
857
|
_e = {
|
|
825
858
|
aid: this.aid
|
|
826
859
|
};
|
|
@@ -836,7 +869,7 @@ var Accessory = /** @class */ (function (_super) {
|
|
|
836
869
|
return [4 /*yield*/, Promise.all(this.bridgedAccessories
|
|
837
870
|
.map(function (accessory) { return accessory.toHAP(connection, contactGetHandlers).then(function (value) { return value[0]; }); }))];
|
|
838
871
|
case 2:
|
|
839
|
-
_b.apply(_a, _c.concat([tslib_1.__spreadArray.apply(void 0, _d.concat([tslib_1.__read.apply(void 0, [_f.sent()])]))]));
|
|
872
|
+
_b.apply(_a, _c.concat([tslib_1.__spreadArray.apply(void 0, _d.concat([tslib_1.__read.apply(void 0, [_f.sent()]), false]))]));
|
|
840
873
|
_f.label = 3;
|
|
841
874
|
case 3: return [2 /*return*/, accessories];
|
|
842
875
|
}
|
|
@@ -852,8 +885,8 @@ var Accessory = /** @class */ (function (_super) {
|
|
|
852
885
|
if (assignIds) {
|
|
853
886
|
this._assignIDs(this._identifierCache); // make sure our aid/iid's are all assigned
|
|
854
887
|
}
|
|
855
|
-
assert_1.default(this.aid, "aid cannot be undefined for accessory '" + this.displayName + "'");
|
|
856
|
-
assert_1.default(this.services.length, "accessory '" + this.displayName + "' does not have any services!");
|
|
888
|
+
(0, assert_1.default)(this.aid, "aid cannot be undefined for accessory '" + this.displayName + "'");
|
|
889
|
+
(0, assert_1.default)(this.services.length, "accessory '" + this.displayName + "' does not have any services!");
|
|
857
890
|
var accessory = {
|
|
858
891
|
aid: this.aid,
|
|
859
892
|
services: this.services.map(function (service) { return service.internalHAPRepresentation(); }),
|
|
@@ -861,7 +894,7 @@ var Accessory = /** @class */ (function (_super) {
|
|
|
861
894
|
var accessories = [accessory];
|
|
862
895
|
if (!this.bridged) {
|
|
863
896
|
try {
|
|
864
|
-
for (var _b = tslib_1.__values(this.bridgedAccessories), _c = _b.next(); !_c.done; _c = _b.next()) {
|
|
897
|
+
for (var _b = (0, tslib_1.__values)(this.bridgedAccessories), _c = _b.next(); !_c.done; _c = _b.next()) {
|
|
865
898
|
var accessory_1 = _c.value;
|
|
866
899
|
accessories.push(accessory_1.internalHAPRepresentation(false)[0]);
|
|
867
900
|
}
|
|
@@ -891,130 +924,151 @@ var Accessory = /** @class */ (function (_super) {
|
|
|
891
924
|
* new Accessory.
|
|
892
925
|
*/
|
|
893
926
|
Accessory.prototype.publish = function (info, allowInsecureRequest) {
|
|
894
|
-
var _this = this;
|
|
895
927
|
var _a, _b;
|
|
896
|
-
|
|
897
|
-
|
|
898
|
-
|
|
899
|
-
|
|
900
|
-
|
|
901
|
-
|
|
902
|
-
|
|
903
|
-
|
|
904
|
-
|
|
905
|
-
|
|
906
|
-
|
|
907
|
-
|
|
908
|
-
|
|
909
|
-
|
|
910
|
-
|
|
911
|
-
|
|
912
|
-
|
|
913
|
-
|
|
914
|
-
|
|
915
|
-
|
|
916
|
-
|
|
917
|
-
|
|
918
|
-
|
|
919
|
-
|
|
920
|
-
|
|
921
|
-
|
|
922
|
-
|
|
923
|
-
|
|
924
|
-
|
|
925
|
-
|
|
926
|
-
|
|
927
|
-
|
|
928
|
-
|
|
929
|
-
|
|
930
|
-
|
|
931
|
-
|
|
932
|
-
|
|
933
|
-
|
|
934
|
-
|
|
935
|
-
|
|
936
|
-
|
|
937
|
-
|
|
938
|
-
|
|
939
|
-
|
|
940
|
-
|
|
941
|
-
|
|
942
|
-
|
|
943
|
-
|
|
944
|
-
|
|
945
|
-
|
|
946
|
-
|
|
947
|
-
|
|
948
|
-
|
|
949
|
-
|
|
950
|
-
|
|
951
|
-
|
|
952
|
-
|
|
953
|
-
|
|
954
|
-
|
|
955
|
-
|
|
956
|
-
|
|
957
|
-
|
|
958
|
-
|
|
959
|
-
|
|
960
|
-
|
|
961
|
-
|
|
962
|
-
|
|
963
|
-
|
|
964
|
-
|
|
965
|
-
|
|
966
|
-
|
|
967
|
-
|
|
968
|
-
|
|
969
|
-
|
|
970
|
-
|
|
971
|
-
|
|
972
|
-
|
|
973
|
-
|
|
974
|
-
|
|
975
|
-
|
|
976
|
-
|
|
977
|
-
|
|
978
|
-
|
|
979
|
-
|
|
980
|
-
|
|
981
|
-
|
|
982
|
-
|
|
983
|
-
|
|
984
|
-
|
|
985
|
-
|
|
986
|
-
|
|
987
|
-
|
|
988
|
-
|
|
989
|
-
|
|
990
|
-
|
|
991
|
-
|
|
992
|
-
|
|
993
|
-
|
|
994
|
-
|
|
995
|
-
|
|
996
|
-
|
|
997
|
-
|
|
998
|
-
|
|
999
|
-
|
|
1000
|
-
|
|
1001
|
-
|
|
928
|
+
return (0, tslib_1.__awaiter)(this, void 0, void 0, function () {
|
|
929
|
+
var service, config, parsed, defaultAdvertiser, _c;
|
|
930
|
+
var _this = this;
|
|
931
|
+
return (0, tslib_1.__generator)(this, function (_d) {
|
|
932
|
+
switch (_d.label) {
|
|
933
|
+
case 0:
|
|
934
|
+
// noinspection JSDeprecatedSymbols
|
|
935
|
+
if (!info.advertiser && info.useLegacyAdvertiser != null) {
|
|
936
|
+
// noinspection JSDeprecatedSymbols
|
|
937
|
+
info.advertiser = info.useLegacyAdvertiser ? "bonjour-hap" /* BONJOUR */ : "ciao" /* CIAO */;
|
|
938
|
+
console.warn("DEPRECATED The PublishInfo.useLegacyAdvertiser option has been removed. " +
|
|
939
|
+
"Please use the PublishInfo.advertiser property to enable \"ciao\" (useLegacyAdvertiser=false) " +
|
|
940
|
+
"or \"bonjour-hap\" (useLegacyAdvertiser=true) mdns advertiser libraries!");
|
|
941
|
+
}
|
|
942
|
+
// noinspection JSDeprecatedSymbols
|
|
943
|
+
if (info.mdns && info.advertiser !== "bonjour-hap" /* BONJOUR */) {
|
|
944
|
+
console.log("DEPRECATED user supplied a custom 'mdns' option. This option is deprecated and ignored. " +
|
|
945
|
+
"Please move to the new 'bind' option.");
|
|
946
|
+
}
|
|
947
|
+
service = this.getService(Service_1.Service.ProtocolInformation);
|
|
948
|
+
if (!service) {
|
|
949
|
+
service = this.addService(Service_1.Service.ProtocolInformation); // add the protocol information service to the primary accessory
|
|
950
|
+
}
|
|
951
|
+
service.setCharacteristic(Characteristic_1.Characteristic.Version, Advertiser_1.CiaoAdvertiser.protocolVersionService);
|
|
952
|
+
if (this.lastKnownUsername && this.lastKnownUsername !== info.username) { // username changed since last publish
|
|
953
|
+
Accessory.cleanupAccessoryData(this.lastKnownUsername); // delete old Accessory data
|
|
954
|
+
}
|
|
955
|
+
if (!this.initialized && ((_a = info.addIdentifyingMaterial) !== null && _a !== void 0 ? _a : true)) {
|
|
956
|
+
// adding some identifying material to our displayName if its our first publish() call
|
|
957
|
+
this.displayName = this.displayName + " " + crypto_1.default.createHash("sha512")
|
|
958
|
+
.update(info.username, "utf8")
|
|
959
|
+
.digest("hex").slice(0, 4).toUpperCase();
|
|
960
|
+
this.getService(Service_1.Service.AccessoryInformation).updateCharacteristic(Characteristic_1.Characteristic.Name, this.displayName);
|
|
961
|
+
}
|
|
962
|
+
// attempt to load existing AccessoryInfo from disk
|
|
963
|
+
this._accessoryInfo = AccessoryInfo_1.AccessoryInfo.load(info.username);
|
|
964
|
+
// if we don't have one, create a new one.
|
|
965
|
+
if (!this._accessoryInfo) {
|
|
966
|
+
debug("[%s] Creating new AccessoryInfo for our HAP server", this.displayName);
|
|
967
|
+
this._accessoryInfo = AccessoryInfo_1.AccessoryInfo.create(info.username);
|
|
968
|
+
}
|
|
969
|
+
if (info.setupID) {
|
|
970
|
+
this._setupID = info.setupID;
|
|
971
|
+
}
|
|
972
|
+
else if (this._accessoryInfo.setupID === undefined || this._accessoryInfo.setupID === "") {
|
|
973
|
+
this._setupID = Accessory._generateSetupID();
|
|
974
|
+
}
|
|
975
|
+
else {
|
|
976
|
+
this._setupID = this._accessoryInfo.setupID;
|
|
977
|
+
}
|
|
978
|
+
this._accessoryInfo.setupID = this._setupID;
|
|
979
|
+
// make sure we have up-to-date values in AccessoryInfo, then save it in case they changed (or if we just created it)
|
|
980
|
+
this._accessoryInfo.displayName = this.displayName;
|
|
981
|
+
this._accessoryInfo.model = this.getService(Service_1.Service.AccessoryInformation).getCharacteristic(Characteristic_1.Characteristic.Model).value;
|
|
982
|
+
this._accessoryInfo.category = info.category || 1 /* OTHER */;
|
|
983
|
+
this._accessoryInfo.pincode = info.pincode;
|
|
984
|
+
this._accessoryInfo.save();
|
|
985
|
+
// create our IdentifierCache so we can provide clients with stable aid/iid's
|
|
986
|
+
this._identifierCache = IdentifierCache_1.IdentifierCache.load(info.username);
|
|
987
|
+
// if we don't have one, create a new one.
|
|
988
|
+
if (!this._identifierCache) {
|
|
989
|
+
debug("[%s] Creating new IdentifierCache", this.displayName);
|
|
990
|
+
this._identifierCache = new IdentifierCache_1.IdentifierCache(info.username);
|
|
991
|
+
}
|
|
992
|
+
//If it's bridge and there are not accessories already assigned to the bridge
|
|
993
|
+
//probably purge is not needed since it's going to delete all the ids
|
|
994
|
+
//of accessories that might be added later. Useful when dynamically adding
|
|
995
|
+
//accessories.
|
|
996
|
+
if (this._isBridge && this.bridgedAccessories.length === 0) {
|
|
997
|
+
this.disableUnusedIDPurge();
|
|
998
|
+
this.controllerStorage.purgeUnidentifiedAccessoryData = false;
|
|
999
|
+
}
|
|
1000
|
+
if (!this.initialized) { // controller storage is only loaded from disk the first time we publish!
|
|
1001
|
+
this.controllerStorage.load(info.username); // initializing controller data
|
|
1002
|
+
}
|
|
1003
|
+
// assign aid/iid
|
|
1004
|
+
this._assignIDs(this._identifierCache);
|
|
1005
|
+
config = this.internalHAPRepresentation(false);
|
|
1006
|
+
// TODO queue this check until about 5 seconds after startup, allowing some last changes after the publish call
|
|
1007
|
+
// without constantly incrementing the current config number
|
|
1008
|
+
this._accessoryInfo.checkForCurrentConfigurationNumberIncrement(config, true);
|
|
1009
|
+
this.validateAccessory(true);
|
|
1010
|
+
parsed = Accessory.parseBindOption(info);
|
|
1011
|
+
if (!((_b = info.advertiser) !== null && _b !== void 0)) return [3 /*break*/, 1];
|
|
1012
|
+
_c = _b;
|
|
1013
|
+
return [3 /*break*/, 3];
|
|
1014
|
+
case 1: return [4 /*yield*/, Advertiser_1.AvahiAdvertiser.isAvailable()];
|
|
1015
|
+
case 2:
|
|
1016
|
+
_c = ((_d.sent()) ? "avahi" /* AVAHI */ : "bonjour-hap" /* BONJOUR */);
|
|
1017
|
+
_d.label = 3;
|
|
1018
|
+
case 3:
|
|
1019
|
+
defaultAdvertiser = _c;
|
|
1020
|
+
switch (defaultAdvertiser) {
|
|
1021
|
+
case "ciao" /* CIAO */:
|
|
1022
|
+
this._advertiser = new Advertiser_1.CiaoAdvertiser(this._accessoryInfo, {
|
|
1023
|
+
interface: parsed.advertiserAddress,
|
|
1024
|
+
}, {
|
|
1025
|
+
restrictedAddresses: parsed.serviceRestrictedAddress,
|
|
1026
|
+
disabledIpv6: parsed.serviceDisableIpv6,
|
|
1027
|
+
});
|
|
1028
|
+
break;
|
|
1029
|
+
case "bonjour-hap" /* BONJOUR */:
|
|
1030
|
+
// noinspection JSDeprecatedSymbols
|
|
1031
|
+
this._advertiser = new Advertiser_1.BonjourHAPAdvertiser(this._accessoryInfo, info.mdns, {
|
|
1032
|
+
restrictedAddresses: parsed.serviceRestrictedAddress,
|
|
1033
|
+
disabledIpv6: parsed.serviceDisableIpv6,
|
|
1034
|
+
});
|
|
1035
|
+
break;
|
|
1036
|
+
case "avahi" /* AVAHI */:
|
|
1037
|
+
this._advertiser = new Advertiser_1.AvahiAdvertiser(this._accessoryInfo);
|
|
1038
|
+
break;
|
|
1039
|
+
default:
|
|
1040
|
+
throw new Error("Unsupported advertiser setting: '" + info.advertiser + "'");
|
|
1041
|
+
}
|
|
1042
|
+
this._advertiser.on("updated-name" /* UPDATED_NAME */, function (name) {
|
|
1043
|
+
_this.displayName = name;
|
|
1044
|
+
if (_this._accessoryInfo) {
|
|
1045
|
+
_this._accessoryInfo.displayName = name;
|
|
1046
|
+
_this._accessoryInfo.save();
|
|
1047
|
+
}
|
|
1048
|
+
// bonjour service name MUST match the name in the accessory information service
|
|
1049
|
+
_this.getService(Service_1.Service.AccessoryInformation)
|
|
1050
|
+
.updateCharacteristic(Characteristic_1.Characteristic.Name, name);
|
|
1051
|
+
});
|
|
1052
|
+
// create our HAP server which handles all communication between iOS devices and us
|
|
1053
|
+
this._server = new HAPServer_1.HAPServer(this._accessoryInfo);
|
|
1054
|
+
this._server.allowInsecureRequest = !!allowInsecureRequest;
|
|
1055
|
+
this._server.on("listening" /* LISTENING */, this.onListening.bind(this));
|
|
1056
|
+
this._server.on("identify" /* IDENTIFY */, this.identificationRequest.bind(this, false));
|
|
1057
|
+
this._server.on("pair" /* PAIR */, this.handleInitialPairSetupFinished.bind(this));
|
|
1058
|
+
this._server.on("add-pairing" /* ADD_PAIRING */, this.handleAddPairing.bind(this));
|
|
1059
|
+
this._server.on("remove-pairing" /* REMOVE_PAIRING */, this.handleRemovePairing.bind(this));
|
|
1060
|
+
this._server.on("list-pairings" /* LIST_PAIRINGS */, this.handleListPairings.bind(this));
|
|
1061
|
+
this._server.on("accessories" /* ACCESSORIES */, this.handleAccessories.bind(this));
|
|
1062
|
+
this._server.on("get-characteristics" /* GET_CHARACTERISTICS */, this.handleGetCharacteristics.bind(this));
|
|
1063
|
+
this._server.on("set-characteristics" /* SET_CHARACTERISTICS */, this.handleSetCharacteristics.bind(this));
|
|
1064
|
+
this._server.on("connection-closed" /* CONNECTION_CLOSED */, this.handleHAPConnectionClosed.bind(this));
|
|
1065
|
+
this._server.on("request-resource" /* REQUEST_RESOURCE */, this.handleResource.bind(this));
|
|
1066
|
+
this._server.listen(info.port, parsed.serverAddress);
|
|
1067
|
+
this.initialized = true;
|
|
1068
|
+
return [2 /*return*/];
|
|
1069
|
+
}
|
|
1070
|
+
});
|
|
1002
1071
|
});
|
|
1003
|
-
// create our HAP server which handles all communication between iOS devices and us
|
|
1004
|
-
this._server = new HAPServer_1.HAPServer(this._accessoryInfo);
|
|
1005
|
-
this._server.allowInsecureRequest = !!allowInsecureRequest;
|
|
1006
|
-
this._server.on("listening" /* LISTENING */, this.onListening.bind(this));
|
|
1007
|
-
this._server.on("identify" /* IDENTIFY */, this.identificationRequest.bind(this, false));
|
|
1008
|
-
this._server.on("pair" /* PAIR */, this.handleInitialPairSetupFinished.bind(this));
|
|
1009
|
-
this._server.on("add-pairing" /* ADD_PAIRING */, this.handleAddPairing.bind(this));
|
|
1010
|
-
this._server.on("remove-pairing" /* REMOVE_PAIRING */, this.handleRemovePairing.bind(this));
|
|
1011
|
-
this._server.on("list-pairings" /* LIST_PAIRINGS */, this.handleListPairings.bind(this));
|
|
1012
|
-
this._server.on("accessories" /* ACCESSORIES */, this.handleAccessories.bind(this));
|
|
1013
|
-
this._server.on("get-characteristics" /* GET_CHARACTERISTICS */, this.handleGetCharacteristics.bind(this));
|
|
1014
|
-
this._server.on("set-characteristics" /* SET_CHARACTERISTICS */, this.handleSetCharacteristics.bind(this));
|
|
1015
|
-
this._server.on("connection-closed" /* CONNECTION_CLOSED */, this.handleHAPConnectionClosed.bind(this));
|
|
1016
|
-
this._server.on("request-resource" /* REQUEST_RESOURCE */, this.handleResource.bind(this));
|
|
1017
|
-
this._server.listen(info.port, parsed.serverAddress);
|
|
1018
1072
|
};
|
|
1019
1073
|
/**
|
|
1020
1074
|
* Removes this Accessory from the local network
|
|
@@ -1022,7 +1076,7 @@ var Accessory = /** @class */ (function (_super) {
|
|
|
1022
1076
|
* Trying to invoke publish() on the object will result undefined behavior
|
|
1023
1077
|
*/
|
|
1024
1078
|
Accessory.prototype.destroy = function () {
|
|
1025
|
-
this.unpublish();
|
|
1079
|
+
var promise = this.unpublish();
|
|
1026
1080
|
if (this._accessoryInfo) {
|
|
1027
1081
|
Accessory.cleanupAccessoryData(this._accessoryInfo.username);
|
|
1028
1082
|
this._accessoryInfo = undefined;
|
|
@@ -1030,17 +1084,29 @@ var Accessory = /** @class */ (function (_super) {
|
|
|
1030
1084
|
this.controllerStorage = new ControllerStorage_1.ControllerStorage(this);
|
|
1031
1085
|
}
|
|
1032
1086
|
this.removeAllListeners();
|
|
1087
|
+
return promise;
|
|
1033
1088
|
};
|
|
1034
1089
|
Accessory.prototype.unpublish = function () {
|
|
1035
|
-
|
|
1036
|
-
|
|
1037
|
-
|
|
1038
|
-
|
|
1039
|
-
|
|
1040
|
-
|
|
1041
|
-
|
|
1042
|
-
|
|
1043
|
-
|
|
1090
|
+
return (0, tslib_1.__awaiter)(this, void 0, void 0, function () {
|
|
1091
|
+
return (0, tslib_1.__generator)(this, function (_a) {
|
|
1092
|
+
switch (_a.label) {
|
|
1093
|
+
case 0:
|
|
1094
|
+
if (this._server) {
|
|
1095
|
+
this._server.destroy();
|
|
1096
|
+
this._server = undefined;
|
|
1097
|
+
}
|
|
1098
|
+
if (!this._advertiser) return [3 /*break*/, 2];
|
|
1099
|
+
// noinspection JSIgnoredPromiseFromCall
|
|
1100
|
+
return [4 /*yield*/, this._advertiser.destroy()];
|
|
1101
|
+
case 1:
|
|
1102
|
+
// noinspection JSIgnoredPromiseFromCall
|
|
1103
|
+
_a.sent();
|
|
1104
|
+
this._advertiser = undefined;
|
|
1105
|
+
_a.label = 2;
|
|
1106
|
+
case 2: return [2 /*return*/];
|
|
1107
|
+
}
|
|
1108
|
+
});
|
|
1109
|
+
});
|
|
1044
1110
|
};
|
|
1045
1111
|
Accessory.prototype.enqueueConfigurationUpdate = function () {
|
|
1046
1112
|
var _this = this;
|
|
@@ -1066,11 +1132,13 @@ var Accessory = /** @class */ (function (_super) {
|
|
|
1066
1132
|
// not responding or new accessories/services not yet shown
|
|
1067
1133
|
};
|
|
1068
1134
|
Accessory.prototype.onListening = function (port, hostname) {
|
|
1069
|
-
|
|
1135
|
+
var _this = this;
|
|
1136
|
+
(0, assert_1.default)(this._advertiser, "Advertiser wasn't created at onListening!");
|
|
1070
1137
|
// the HAP server is listening, so we can now start advertising our presence.
|
|
1071
1138
|
this._advertiser.initPort(port);
|
|
1072
|
-
|
|
1073
|
-
|
|
1139
|
+
this._advertiser.startAdvertising()
|
|
1140
|
+
.then(function () { return _this.emit("advertised" /* ADVERTISED */); })
|
|
1141
|
+
.catch(function (reason) { return console.error("Could not create mDNS advertisement. The HAP-Server won't be discoverable: " + reason); });
|
|
1074
1142
|
this.emit("listening" /* LISTENING */, port, hostname);
|
|
1075
1143
|
};
|
|
1076
1144
|
Accessory.prototype.handleInitialPairSetupFinished = function (username, publicKey, callback) {
|
|
@@ -1124,7 +1192,7 @@ var Accessory = /** @class */ (function (_super) {
|
|
|
1124
1192
|
this.emit("unpaired" /* UNPAIRED */);
|
|
1125
1193
|
this.handleAccessoryUnpairedForControllers();
|
|
1126
1194
|
try {
|
|
1127
|
-
for (var _b = tslib_1.__values(this.bridgedAccessories), _c = _b.next(); !_c.done; _c = _b.next()) {
|
|
1195
|
+
for (var _b = (0, tslib_1.__values)(this.bridgedAccessories), _c = _b.next(); !_c.done; _c = _b.next()) {
|
|
1128
1196
|
var accessory = _c.value;
|
|
1129
1197
|
accessory.handleAccessoryUnpairedForControllers();
|
|
1130
1198
|
}
|
|
@@ -1178,7 +1246,7 @@ var Accessory = /** @class */ (function (_super) {
|
|
|
1178
1246
|
var timeout = setTimeout(function () {
|
|
1179
1247
|
var e_16, _a;
|
|
1180
1248
|
try {
|
|
1181
|
-
for (var missingCharacteristics_1 = tslib_1.__values(missingCharacteristics), missingCharacteristics_1_1 = missingCharacteristics_1.next(); !missingCharacteristics_1_1.done; missingCharacteristics_1_1 = missingCharacteristics_1.next()) {
|
|
1249
|
+
for (var missingCharacteristics_1 = (0, tslib_1.__values)(missingCharacteristics), missingCharacteristics_1_1 = missingCharacteristics_1.next(); !missingCharacteristics_1_1.done; missingCharacteristics_1_1 = missingCharacteristics_1.next()) {
|
|
1182
1250
|
var id = missingCharacteristics_1_1.value;
|
|
1183
1251
|
var split = id.split(".");
|
|
1184
1252
|
var aid = parseInt(split[0], 10);
|
|
@@ -1201,7 +1269,7 @@ var Accessory = /** @class */ (function (_super) {
|
|
|
1201
1269
|
var e_17, _a;
|
|
1202
1270
|
timeout = undefined;
|
|
1203
1271
|
try {
|
|
1204
|
-
for (var missingCharacteristics_2 = tslib_1.__values(missingCharacteristics), missingCharacteristics_2_1 = missingCharacteristics_2.next(); !missingCharacteristics_2_1.done; missingCharacteristics_2_1 = missingCharacteristics_2.next()) {
|
|
1272
|
+
for (var missingCharacteristics_2 = (0, tslib_1.__values)(missingCharacteristics), missingCharacteristics_2_1 = missingCharacteristics_2.next(); !missingCharacteristics_2_1.done; missingCharacteristics_2_1 = missingCharacteristics_2.next()) {
|
|
1205
1273
|
var id = missingCharacteristics_2_1.value;
|
|
1206
1274
|
var split = id.split(".");
|
|
1207
1275
|
var aid = parseInt(split[0], 10);
|
|
@@ -1209,7 +1277,8 @@ var Accessory = /** @class */ (function (_super) {
|
|
|
1209
1277
|
var accessory = _this.getAccessoryByAID(aid);
|
|
1210
1278
|
var characteristic = accessory.getCharacteristicByIID(iid);
|
|
1211
1279
|
_this.sendCharacteristicWarning(characteristic, "timeout-read" /* TIMEOUT_READ */, "The read handler for the characteristic '" +
|
|
1212
|
-
characteristic.displayName + "' on the accessory '" + accessory.displayName + "' didn't respond at all!.
|
|
1280
|
+
characteristic.displayName + "' on the accessory '" + accessory.displayName + "' didn't respond at all!. " +
|
|
1281
|
+
"Please check that you properly call the callback!");
|
|
1213
1282
|
characteristics.push({
|
|
1214
1283
|
aid: aid,
|
|
1215
1284
|
iid: iid,
|
|
@@ -1233,9 +1302,9 @@ var Accessory = /** @class */ (function (_super) {
|
|
|
1233
1302
|
var _loop_1 = function (id) {
|
|
1234
1303
|
var name = id.aid + "." + id.iid;
|
|
1235
1304
|
this_1.handleCharacteristicRead(connection, id, request).then(function (value) {
|
|
1236
|
-
return tslib_1.__assign({ aid: id.aid, iid: id.iid }, value);
|
|
1305
|
+
return (0, tslib_1.__assign)({ aid: id.aid, iid: id.iid }, value);
|
|
1237
1306
|
}, function (reason) {
|
|
1238
|
-
console.error("["
|
|
1307
|
+
console.error("[".concat(_this.displayName, "] Read request for characteristic ").concat(name, " encountered an error: ").concat(reason.stack));
|
|
1239
1308
|
return {
|
|
1240
1309
|
aid: id.aid,
|
|
1241
1310
|
iid: id.iid,
|
|
@@ -1258,7 +1327,7 @@ var Accessory = /** @class */ (function (_super) {
|
|
|
1258
1327
|
};
|
|
1259
1328
|
var this_1 = this;
|
|
1260
1329
|
try {
|
|
1261
|
-
for (var _b = tslib_1.__values(request.ids), _c = _b.next(); !_c.done; _c = _b.next()) {
|
|
1330
|
+
for (var _b = (0, tslib_1.__values)(request.ids), _c = _b.next(); !_c.done; _c = _b.next()) {
|
|
1262
1331
|
var id = _c.value;
|
|
1263
1332
|
_loop_1(id);
|
|
1264
1333
|
}
|
|
@@ -1272,34 +1341,34 @@ var Accessory = /** @class */ (function (_super) {
|
|
|
1272
1341
|
}
|
|
1273
1342
|
};
|
|
1274
1343
|
Accessory.prototype.handleCharacteristicRead = function (connection, id, request) {
|
|
1275
|
-
return tslib_1.__awaiter(this, void 0, void 0, function () {
|
|
1344
|
+
return (0, tslib_1.__awaiter)(this, void 0, void 0, function () {
|
|
1276
1345
|
var characteristic, verifiable;
|
|
1277
1346
|
var _this = this;
|
|
1278
|
-
return tslib_1.__generator(this, function (_a) {
|
|
1347
|
+
return (0, tslib_1.__generator)(this, function (_a) {
|
|
1279
1348
|
characteristic = this.findCharacteristic(id.aid, id.iid);
|
|
1280
1349
|
if (!characteristic) {
|
|
1281
|
-
debug(
|
|
1350
|
+
debug("[%s] Could not find a Characteristic with aid of %s and iid of %s", this.displayName, id.aid, id.iid);
|
|
1282
1351
|
return [2 /*return*/, { status: -70410 /* INVALID_VALUE_IN_REQUEST */ }];
|
|
1283
1352
|
}
|
|
1284
1353
|
if (!characteristic.props.perms.includes("pr" /* PAIRED_READ */)) { // check if read is allowed for this characteristic
|
|
1285
|
-
debug(
|
|
1354
|
+
debug("[%s] Tried reading from characteristic which does not allow reading (aid of %s and iid of %s)", this.displayName, id.aid, id.iid);
|
|
1286
1355
|
return [2 /*return*/, { status: -70405 /* WRITE_ONLY_CHARACTERISTIC */ }];
|
|
1287
1356
|
}
|
|
1288
1357
|
if (characteristic.props.adminOnlyAccess && characteristic.props.adminOnlyAccess.includes(0 /* READ */)) {
|
|
1289
1358
|
verifiable = true;
|
|
1290
1359
|
if (!connection.username || !this._accessoryInfo) {
|
|
1291
1360
|
verifiable = false;
|
|
1292
|
-
debug(
|
|
1361
|
+
debug("[%s] Could not verify admin permissions for Characteristic which requires admin permissions for reading (aid of %s and iid of %s)", this.displayName, id.aid, id.iid);
|
|
1293
1362
|
}
|
|
1294
1363
|
if (!verifiable || !this._accessoryInfo.hasAdminPermissions(connection.username)) {
|
|
1295
1364
|
return [2 /*return*/, { status: -70401 /* INSUFFICIENT_PRIVILEGES */ }];
|
|
1296
1365
|
}
|
|
1297
1366
|
}
|
|
1298
1367
|
return [2 /*return*/, characteristic.handleGetRequest(connection).then(function (value) {
|
|
1299
|
-
value = request_util_1.formatOutgoingCharacteristicValue(value, characteristic.props);
|
|
1300
|
-
debug(
|
|
1368
|
+
value = (0, request_util_1.formatOutgoingCharacteristicValue)(value, characteristic.props);
|
|
1369
|
+
debug("[%s] Got Characteristic \"%s\" value: \"%s\"", _this.displayName, characteristic.displayName, value);
|
|
1301
1370
|
var data = {
|
|
1302
|
-
value: value ==
|
|
1371
|
+
value: value == null ? null : value,
|
|
1303
1372
|
};
|
|
1304
1373
|
if (request.includeMeta) {
|
|
1305
1374
|
data.format = characteristic.props.format;
|
|
@@ -1313,15 +1382,15 @@ var Accessory = /** @class */ (function (_super) {
|
|
|
1313
1382
|
data.perms = characteristic.props.perms;
|
|
1314
1383
|
}
|
|
1315
1384
|
if (request.includeType) {
|
|
1316
|
-
data.type = uuid_1.toShortForm(_this.UUID);
|
|
1385
|
+
data.type = (0, uuid_1.toShortForm)(_this.UUID);
|
|
1317
1386
|
}
|
|
1318
1387
|
if (request.includeEvent) {
|
|
1319
1388
|
data.ev = connection.hasEventNotifications(id.aid, id.iid);
|
|
1320
1389
|
}
|
|
1321
1390
|
return data;
|
|
1322
1391
|
}, function (reason) {
|
|
1323
|
-
// @ts-expect-error
|
|
1324
|
-
debug(
|
|
1392
|
+
// @ts-expect-error: forceConsistentCasingInFileNames compiler option
|
|
1393
|
+
debug("[%s] Error getting value for characteristic \"%s\": %s", _this.displayName, characteristic.displayName, HAPServer_1.HAPStatus[reason]);
|
|
1325
1394
|
return { status: reason };
|
|
1326
1395
|
})];
|
|
1327
1396
|
});
|
|
@@ -1357,7 +1426,7 @@ var Accessory = /** @class */ (function (_super) {
|
|
|
1357
1426
|
var timeout = setTimeout(function () {
|
|
1358
1427
|
var e_19, _a;
|
|
1359
1428
|
try {
|
|
1360
|
-
for (var missingCharacteristics_3 = tslib_1.__values(missingCharacteristics), missingCharacteristics_3_1 = missingCharacteristics_3.next(); !missingCharacteristics_3_1.done; missingCharacteristics_3_1 = missingCharacteristics_3.next()) {
|
|
1429
|
+
for (var missingCharacteristics_3 = (0, tslib_1.__values)(missingCharacteristics), missingCharacteristics_3_1 = missingCharacteristics_3.next(); !missingCharacteristics_3_1.done; missingCharacteristics_3_1 = missingCharacteristics_3.next()) {
|
|
1361
1430
|
var id = missingCharacteristics_3_1.value;
|
|
1362
1431
|
var split = id.split(".");
|
|
1363
1432
|
var aid = parseInt(split[0], 10);
|
|
@@ -1380,7 +1449,7 @@ var Accessory = /** @class */ (function (_super) {
|
|
|
1380
1449
|
var e_20, _a;
|
|
1381
1450
|
timeout = undefined;
|
|
1382
1451
|
try {
|
|
1383
|
-
for (var missingCharacteristics_4 = tslib_1.__values(missingCharacteristics), missingCharacteristics_4_1 = missingCharacteristics_4.next(); !missingCharacteristics_4_1.done; missingCharacteristics_4_1 = missingCharacteristics_4.next()) {
|
|
1452
|
+
for (var missingCharacteristics_4 = (0, tslib_1.__values)(missingCharacteristics), missingCharacteristics_4_1 = missingCharacteristics_4.next(); !missingCharacteristics_4_1.done; missingCharacteristics_4_1 = missingCharacteristics_4.next()) {
|
|
1384
1453
|
var id = missingCharacteristics_4_1.value;
|
|
1385
1454
|
var split = id.split(".");
|
|
1386
1455
|
var aid = parseInt(split[0], 10);
|
|
@@ -1388,7 +1457,8 @@ var Accessory = /** @class */ (function (_super) {
|
|
|
1388
1457
|
var accessory = _this.getAccessoryByAID(aid);
|
|
1389
1458
|
var characteristic = accessory.getCharacteristicByIID(iid);
|
|
1390
1459
|
_this.sendCharacteristicWarning(characteristic, "timeout-write" /* TIMEOUT_WRITE */, "The write handler for the characteristic '" +
|
|
1391
|
-
characteristic.displayName + "' on the accessory '" + accessory.displayName + "' didn't respond at all!.
|
|
1460
|
+
characteristic.displayName + "' on the accessory '" + accessory.displayName + "' didn't respond at all!. " +
|
|
1461
|
+
"Please check that you properly call the callback!");
|
|
1392
1462
|
characteristics.push({
|
|
1393
1463
|
aid: aid,
|
|
1394
1464
|
iid: iid,
|
|
@@ -1412,9 +1482,9 @@ var Accessory = /** @class */ (function (_super) {
|
|
|
1412
1482
|
var _loop_2 = function (data) {
|
|
1413
1483
|
var name = data.aid + "." + data.iid;
|
|
1414
1484
|
this_2.handleCharacteristicWrite(connection, data, writeState).then(function (value) {
|
|
1415
|
-
return tslib_1.__assign({ aid: data.aid, iid: data.iid }, value);
|
|
1485
|
+
return (0, tslib_1.__assign)({ aid: data.aid, iid: data.iid }, value);
|
|
1416
1486
|
}, function (reason) {
|
|
1417
|
-
console.error("["
|
|
1487
|
+
console.error("[".concat(_this.displayName, "] Write request for characteristic ").concat(name, " encountered an error: ").concat(reason.stack));
|
|
1418
1488
|
return {
|
|
1419
1489
|
aid: data.aid,
|
|
1420
1490
|
iid: data.iid,
|
|
@@ -1437,7 +1507,7 @@ var Accessory = /** @class */ (function (_super) {
|
|
|
1437
1507
|
};
|
|
1438
1508
|
var this_2 = this;
|
|
1439
1509
|
try {
|
|
1440
|
-
for (var _b = tslib_1.__values(writeRequest.characteristics), _c = _b.next(); !_c.done; _c = _b.next()) {
|
|
1510
|
+
for (var _b = (0, tslib_1.__values)(writeRequest.characteristics), _c = _b.next(); !_c.done; _c = _b.next()) {
|
|
1441
1511
|
var data = _c.value;
|
|
1442
1512
|
_loop_2(data);
|
|
1443
1513
|
}
|
|
@@ -1451,33 +1521,33 @@ var Accessory = /** @class */ (function (_super) {
|
|
|
1451
1521
|
}
|
|
1452
1522
|
};
|
|
1453
1523
|
Accessory.prototype.handleCharacteristicWrite = function (connection, data, writeState) {
|
|
1454
|
-
return tslib_1.__awaiter(this, void 0, void 0, function () {
|
|
1524
|
+
return (0, tslib_1.__awaiter)(this, void 0, void 0, function () {
|
|
1455
1525
|
var characteristic, evResponse, notificationsEnabled, verifiable, verifiable, allowWrite;
|
|
1456
1526
|
var _this = this;
|
|
1457
|
-
return tslib_1.__generator(this, function (_a) {
|
|
1527
|
+
return (0, tslib_1.__generator)(this, function (_a) {
|
|
1458
1528
|
characteristic = this.findCharacteristic(data.aid, data.iid);
|
|
1459
1529
|
evResponse = undefined;
|
|
1460
1530
|
if (!characteristic) {
|
|
1461
|
-
debug(
|
|
1531
|
+
debug("[%s] Could not find a Characteristic with aid of %s and iid of %s", this.displayName, data.aid, data.iid);
|
|
1462
1532
|
return [2 /*return*/, { status: -70410 /* INVALID_VALUE_IN_REQUEST */ }];
|
|
1463
1533
|
}
|
|
1464
1534
|
if (writeState === 2 /* TIMED_WRITE_REJECTED */) {
|
|
1465
1535
|
return [2 /*return*/, { status: -70410 /* INVALID_VALUE_IN_REQUEST */ }];
|
|
1466
1536
|
}
|
|
1467
|
-
if (data.ev !=
|
|
1537
|
+
if (data.ev != null) { // register/unregister event notifications
|
|
1468
1538
|
notificationsEnabled = connection.hasEventNotifications(data.aid, data.iid);
|
|
1469
1539
|
// it seems like the Home App sends unregister requests for characteristics which don't have notify permissions
|
|
1470
1540
|
// see https://github.com/homebridge/HAP-NodeJS/issues/868
|
|
1471
|
-
if (notificationsEnabled
|
|
1541
|
+
if (notificationsEnabled !== data.ev) {
|
|
1472
1542
|
if (!characteristic.props.perms.includes("ev" /* NOTIFY */)) { // check if notify is allowed for this characteristic
|
|
1473
|
-
debug(
|
|
1543
|
+
debug("[%s] Tried %s notifications for Characteristic which does not allow notify (aid of %s and iid of %s)", this.displayName, data.ev ? "enabling" : "disabling", data.aid, data.iid);
|
|
1474
1544
|
return [2 /*return*/, { status: -70406 /* NOTIFICATION_NOT_SUPPORTED */ }];
|
|
1475
1545
|
}
|
|
1476
1546
|
if (characteristic.props.adminOnlyAccess && characteristic.props.adminOnlyAccess.includes(2 /* NOTIFY */)) {
|
|
1477
1547
|
verifiable = true;
|
|
1478
1548
|
if (!connection.username || !this._accessoryInfo) {
|
|
1479
1549
|
verifiable = false;
|
|
1480
|
-
debug(
|
|
1550
|
+
debug("[%s] Could not verify admin permissions for Characteristic which requires admin permissions for notify (aid of %s and iid of %s)", this.displayName, data.aid, data.iid);
|
|
1481
1551
|
}
|
|
1482
1552
|
if (!verifiable || !this._accessoryInfo.hasAdminPermissions(connection.username)) {
|
|
1483
1553
|
return [2 /*return*/, { status: -70401 /* INSUFFICIENT_PRIVILEGES */ }];
|
|
@@ -1488,27 +1558,27 @@ var Accessory = /** @class */ (function (_super) {
|
|
|
1488
1558
|
connection.enableEventNotifications(data.aid, data.iid);
|
|
1489
1559
|
characteristic.subscribe();
|
|
1490
1560
|
evResponse = true;
|
|
1491
|
-
debug(
|
|
1561
|
+
debug("[%s] Registered Characteristic \"%s\" on \"%s\" for events", connection.remoteAddress, characteristic.displayName, this.displayName);
|
|
1492
1562
|
}
|
|
1493
1563
|
else {
|
|
1494
1564
|
characteristic.unsubscribe();
|
|
1495
1565
|
connection.disableEventNotifications(data.aid, data.iid);
|
|
1496
1566
|
evResponse = false;
|
|
1497
|
-
debug(
|
|
1567
|
+
debug("[%s] Unregistered Characteristic \"%s\" on \"%s\" for events", connection.remoteAddress, characteristic.displayName, this.displayName);
|
|
1498
1568
|
}
|
|
1499
1569
|
}
|
|
1500
1570
|
// response is returned below in the else block
|
|
1501
1571
|
}
|
|
1502
|
-
if (data.value !=
|
|
1572
|
+
if (data.value != null) {
|
|
1503
1573
|
if (!characteristic.props.perms.includes("pw" /* PAIRED_WRITE */)) { // check if write is allowed for this characteristic
|
|
1504
|
-
debug(
|
|
1574
|
+
debug("[%s] Tried writing to Characteristic which does not allow writing (aid of %s and iid of %s)", this.displayName, data.aid, data.iid);
|
|
1505
1575
|
return [2 /*return*/, { status: -70404 /* READ_ONLY_CHARACTERISTIC */ }];
|
|
1506
1576
|
}
|
|
1507
1577
|
if (characteristic.props.adminOnlyAccess && characteristic.props.adminOnlyAccess.includes(1 /* WRITE */)) {
|
|
1508
1578
|
verifiable = true;
|
|
1509
1579
|
if (!connection.username || !this._accessoryInfo) {
|
|
1510
1580
|
verifiable = false;
|
|
1511
|
-
debug(
|
|
1581
|
+
debug("[%s] Could not verify admin permissions for Characteristic which requires admin permissions for write (aid of %s and iid of %s)", this.displayName, data.aid, data.iid);
|
|
1512
1582
|
}
|
|
1513
1583
|
if (!verifiable || !this._accessoryInfo.hasAdminPermissions(connection.username)) {
|
|
1514
1584
|
return [2 /*return*/, { status: -70401 /* INSUFFICIENT_PRIVILEGES */ }];
|
|
@@ -1520,7 +1590,7 @@ var Accessory = /** @class */ (function (_super) {
|
|
|
1520
1590
|
allowWrite = characteristic.additionalAuthorizationHandler(data.authData);
|
|
1521
1591
|
}
|
|
1522
1592
|
catch (error) {
|
|
1523
|
-
console.
|
|
1593
|
+
console.warn("[" + this.displayName + "] Additional authorization handler has thrown an error when checking authData: " + error.stack);
|
|
1524
1594
|
allowWrite = false;
|
|
1525
1595
|
}
|
|
1526
1596
|
if (!allowWrite) {
|
|
@@ -1528,18 +1598,19 @@ var Accessory = /** @class */ (function (_super) {
|
|
|
1528
1598
|
}
|
|
1529
1599
|
}
|
|
1530
1600
|
if (characteristic.props.perms.includes("tw" /* TIMED_WRITE */) && writeState !== 1 /* TIMED_WRITE_AUTHENTICATED */) {
|
|
1531
|
-
debug(
|
|
1601
|
+
debug("[%s] Tried writing to a timed write only Characteristic without properly preparing (iid of %s and aid of %s)", this.displayName, data.aid, data.iid);
|
|
1532
1602
|
return [2 /*return*/, { status: -70410 /* INVALID_VALUE_IN_REQUEST */ }];
|
|
1533
1603
|
}
|
|
1534
1604
|
return [2 /*return*/, characteristic.handleSetRequest(data.value, connection).then(function (value) {
|
|
1535
|
-
debug(
|
|
1605
|
+
debug("[%s] Setting Characteristic \"%s\" to value %s", _this.displayName, characteristic.displayName, data.value);
|
|
1536
1606
|
return {
|
|
1537
|
-
|
|
1607
|
+
// if write response is requests and value is provided, return that
|
|
1608
|
+
value: data.r && value ? (0, request_util_1.formatOutgoingCharacteristicValue)(value, characteristic.props) : undefined,
|
|
1538
1609
|
ev: evResponse,
|
|
1539
1610
|
};
|
|
1540
1611
|
}, function (status) {
|
|
1541
|
-
// @ts-expect-error
|
|
1542
|
-
debug(
|
|
1612
|
+
// @ts-expect-error: forceConsistentCasingInFileNames compiler option
|
|
1613
|
+
debug("[%s] Error setting Characteristic \"%s\" to value %s: ", _this.displayName, characteristic.displayName, data.value, HAPServer_1.HAPStatus[status]);
|
|
1543
1614
|
return { status: status };
|
|
1544
1615
|
})];
|
|
1545
1616
|
}
|
|
@@ -1571,10 +1642,11 @@ var Accessory = /** @class */ (function (_super) {
|
|
|
1571
1642
|
callback({ httpCode: 404 /* NOT_FOUND */, status: -70409 /* RESOURCE_DOES_NOT_EXIST */ });
|
|
1572
1643
|
return;
|
|
1573
1644
|
}
|
|
1574
|
-
controller.handleSnapshotRequest(data["image-height"], data["image-width"], accessory === null || accessory === void 0 ? void 0 : accessory.displayName
|
|
1645
|
+
controller.handleSnapshotRequest(data["image-height"], data["image-width"], accessory === null || accessory === void 0 ? void 0 : accessory.displayName, data.reason)
|
|
1646
|
+
.then(function (buffer) {
|
|
1575
1647
|
callback(undefined, buffer);
|
|
1576
1648
|
}, function (status) {
|
|
1577
|
-
callback({ httpCode:
|
|
1649
|
+
callback({ httpCode: 207 /* MULTI_STATUS */, status: status });
|
|
1578
1650
|
});
|
|
1579
1651
|
return;
|
|
1580
1652
|
}
|
|
@@ -1587,7 +1659,7 @@ var Accessory = /** @class */ (function (_super) {
|
|
|
1587
1659
|
this.activeCameraController.handleCloseConnection(connection.sessionID);
|
|
1588
1660
|
}
|
|
1589
1661
|
try {
|
|
1590
|
-
for (var _b = tslib_1.__values(connection.getRegisteredEvents()), _c = _b.next(); !_c.done; _c = _b.next()) {
|
|
1662
|
+
for (var _b = (0, tslib_1.__values)(connection.getRegisteredEvents()), _c = _b.next(); !_c.done; _c = _b.next()) {
|
|
1591
1663
|
var event = _c.value;
|
|
1592
1664
|
var ids = event.split(".");
|
|
1593
1665
|
var aid = parseInt(ids[0], 10);
|
|
@@ -1628,17 +1700,17 @@ var Accessory = /** @class */ (function (_super) {
|
|
|
1628
1700
|
};
|
|
1629
1701
|
Accessory.prototype.handleCharacteristicChangeEvent = function (accessory, service, change) {
|
|
1630
1702
|
if (this.bridged) { // forward this to our main accessory
|
|
1631
|
-
this.emit("service-characteristic-change" /* SERVICE_CHARACTERISTIC_CHANGE */, tslib_1.__assign(tslib_1.__assign({}, change), { service: service }));
|
|
1703
|
+
this.emit("service-characteristic-change" /* SERVICE_CHARACTERISTIC_CHANGE */, (0, tslib_1.__assign)((0, tslib_1.__assign)({}, change), { service: service }));
|
|
1632
1704
|
}
|
|
1633
1705
|
else {
|
|
1634
1706
|
if (!this._server) {
|
|
1635
1707
|
return; // we're not running a HAPServer, so there's no one to notify about this event
|
|
1636
1708
|
}
|
|
1637
|
-
if (accessory.aid ==
|
|
1709
|
+
if (accessory.aid == null || change.characteristic.iid == null) {
|
|
1638
1710
|
debug("[%s] Muting event notification for %s as ids aren't yet assigned!", accessory.displayName, change.characteristic.displayName);
|
|
1639
1711
|
return;
|
|
1640
1712
|
}
|
|
1641
|
-
if (change.context !=
|
|
1713
|
+
if (change.context != null && typeof change.context === "object" && change.context.omitEventUpdate) {
|
|
1642
1714
|
debug("[%s] Omitting event updates for %s as specified in the context object!", accessory.displayName, change.characteristic.displayName);
|
|
1643
1715
|
return;
|
|
1644
1716
|
}
|
|
@@ -1654,7 +1726,7 @@ var Accessory = /** @class */ (function (_super) {
|
|
|
1654
1726
|
var uuid_2 = change.characteristic.UUID;
|
|
1655
1727
|
var immediateDelivery = uuid_2 === Characteristic_1.Characteristic.ButtonEvent.UUID || uuid_2 === Characteristic_1.Characteristic.ProgrammableSwitchEvent.UUID
|
|
1656
1728
|
|| uuid_2 === Characteristic_1.Characteristic.MotionDetected.UUID || uuid_2 === Characteristic_1.Characteristic.ContactSensorState.UUID;
|
|
1657
|
-
var value = request_util_1.formatOutgoingCharacteristicValue(change.newValue, change.characteristic.props);
|
|
1729
|
+
var value = (0, request_util_1.formatOutgoingCharacteristicValue)(change.newValue, change.characteristic.props);
|
|
1658
1730
|
this._server.sendEventNotifications(accessory.aid, change.characteristic.iid, value, change.originator, immediateDelivery);
|
|
1659
1731
|
}
|
|
1660
1732
|
};
|
|
@@ -1669,10 +1741,10 @@ var Accessory = /** @class */ (function (_super) {
|
|
|
1669
1741
|
};
|
|
1670
1742
|
Accessory.prototype.handleCharacteristicWarning = function (warning) {
|
|
1671
1743
|
var _a;
|
|
1672
|
-
warning.originatorChain = tslib_1.__spreadArray([this.displayName], tslib_1.__read(warning.originatorChain));
|
|
1744
|
+
warning.originatorChain = (0, tslib_1.__spreadArray)([this.displayName], (0, tslib_1.__read)(warning.originatorChain), false);
|
|
1673
1745
|
var emitted = this.emit("characteristic-warning" /* CHARACTERISTIC_WARNING */, warning);
|
|
1674
1746
|
if (!emitted) {
|
|
1675
|
-
var message = "["
|
|
1747
|
+
var message = "[".concat(warning.originatorChain.join("@"), "] ").concat(warning.message);
|
|
1676
1748
|
if (warning.type === "error-message" /* ERROR_MESSAGE */
|
|
1677
1749
|
|| warning.type === "timeout-read" /* TIMEOUT_READ */ || warning.type === "timeout-write" /* TIMEOUT_WRITE */) {
|
|
1678
1750
|
console.error(message);
|
|
@@ -1692,7 +1764,7 @@ var Accessory = /** @class */ (function (_super) {
|
|
|
1692
1764
|
var e_22, _a;
|
|
1693
1765
|
var _this = this;
|
|
1694
1766
|
try {
|
|
1695
|
-
for (var targetServices_1 = tslib_1.__values(targetServices), targetServices_1_1 = targetServices_1.next(); !targetServices_1_1.done; targetServices_1_1 = targetServices_1.next()) {
|
|
1767
|
+
for (var targetServices_1 = (0, tslib_1.__values)(targetServices), targetServices_1_1 = targetServices_1.next(); !targetServices_1_1.done; targetServices_1_1 = targetServices_1.next()) {
|
|
1696
1768
|
var service = targetServices_1_1.value;
|
|
1697
1769
|
this.setupServiceEventHandlers(service);
|
|
1698
1770
|
}
|
|
@@ -1717,9 +1789,9 @@ var Accessory = /** @class */ (function (_super) {
|
|
|
1717
1789
|
});
|
|
1718
1790
|
};
|
|
1719
1791
|
Accessory._generateSetupID = function () {
|
|
1720
|
-
var chars =
|
|
1792
|
+
var chars = "0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ";
|
|
1721
1793
|
var max = chars.length;
|
|
1722
|
-
var setupID =
|
|
1794
|
+
var setupID = "";
|
|
1723
1795
|
for (var i = 0; i < 4; i++) {
|
|
1724
1796
|
var index = Math.floor(Math.random() * max);
|
|
1725
1797
|
setupID += chars.charAt(index);
|
|
@@ -1761,7 +1833,7 @@ var Accessory = /** @class */ (function (_super) {
|
|
|
1761
1833
|
});
|
|
1762
1834
|
// also save controller which didn't get initialized (could lead to service duplication if we throw that data away)
|
|
1763
1835
|
accessory.serializedControllers && Object.entries(accessory.serializedControllers).forEach(function (_a) {
|
|
1764
|
-
var _b = tslib_1.__read(_a, 2), id = _b[0], serviceMap = _b[1];
|
|
1836
|
+
var _b = (0, tslib_1.__read)(_a, 2), id = _b[0], serviceMap = _b[1];
|
|
1765
1837
|
controllers.push({
|
|
1766
1838
|
type: id,
|
|
1767
1839
|
services: Accessory.serializeServiceMap(serviceMap),
|
|
@@ -1798,8 +1870,8 @@ var Accessory = /** @class */ (function (_super) {
|
|
|
1798
1870
|
});
|
|
1799
1871
|
};
|
|
1800
1872
|
try {
|
|
1801
|
-
for (var _b = tslib_1.__values(Object.entries(json.linkedServices)), _c = _b.next(); !_c.done; _c = _b.next()) {
|
|
1802
|
-
var _d = tslib_1.__read(_c.value, 2), serviceId = _d[0], linkedServicesKeys = _d[1];
|
|
1873
|
+
for (var _b = (0, tslib_1.__values)(Object.entries(json.linkedServices)), _c = _b.next(); !_c.done; _c = _b.next()) {
|
|
1874
|
+
var _d = (0, tslib_1.__read)(_c.value, 2), serviceId = _d[0], linkedServicesKeys = _d[1];
|
|
1803
1875
|
_loop_3(serviceId, linkedServicesKeys);
|
|
1804
1876
|
}
|
|
1805
1877
|
}
|
|
@@ -1828,7 +1900,7 @@ var Accessory = /** @class */ (function (_super) {
|
|
|
1828
1900
|
Accessory.serializeServiceMap = function (serviceMap) {
|
|
1829
1901
|
var serialized = {};
|
|
1830
1902
|
Object.entries(serviceMap).forEach(function (_a) {
|
|
1831
|
-
var _b = tslib_1.__read(_a, 2), name = _b[0], service = _b[1];
|
|
1903
|
+
var _b = (0, tslib_1.__read)(_a, 2), name = _b[0], service = _b[1];
|
|
1832
1904
|
if (!service) {
|
|
1833
1905
|
return;
|
|
1834
1906
|
}
|
|
@@ -1839,7 +1911,7 @@ var Accessory = /** @class */ (function (_super) {
|
|
|
1839
1911
|
Accessory.deserializeServiceMap = function (serializedServiceMap, servicesMap) {
|
|
1840
1912
|
var controllerServiceMap = {};
|
|
1841
1913
|
Object.entries(serializedServiceMap).forEach(function (_a) {
|
|
1842
|
-
var _b = tslib_1.__read(_a, 2), name = _b[0], serviceId = _b[1];
|
|
1914
|
+
var _b = (0, tslib_1.__read)(_a, 2), name = _b[0], serviceId = _b[1];
|
|
1843
1915
|
var service = servicesMap[serviceId];
|
|
1844
1916
|
if (service) {
|
|
1845
1917
|
controllerServiceMap[name] = service;
|
|
@@ -1884,7 +1956,7 @@ var Accessory = /** @class */ (function (_super) {
|
|
|
1884
1956
|
advertiserAddress = Array.from(entries);
|
|
1885
1957
|
var bindUnspecifiedIpv6 = false; // we bind on "::" if there are interface names, or we detect ipv6 addresses
|
|
1886
1958
|
try {
|
|
1887
|
-
for (var entries_1 = tslib_1.__values(entries), entries_1_1 = entries_1.next(); !entries_1_1.done; entries_1_1 = entries_1.next()) {
|
|
1959
|
+
for (var entries_1 = (0, tslib_1.__values)(entries), entries_1_1 = entries_1.next(); !entries_1_1.done; entries_1_1 = entries_1.next()) {
|
|
1888
1960
|
var entry = entries_1_1.value;
|
|
1889
1961
|
var version = net_1.default.isIP(entry);
|
|
1890
1962
|
if (version === 0 || version === 6) {
|
|
@@ -1916,9 +1988,9 @@ var Accessory = /** @class */ (function (_super) {
|
|
|
1916
1988
|
};
|
|
1917
1989
|
};
|
|
1918
1990
|
/**
|
|
1919
|
-
* @deprecated Please use the Categories const enum above.
|
|
1991
|
+
* @deprecated Please use the Categories const enum above.
|
|
1920
1992
|
*/
|
|
1921
|
-
// @ts-
|
|
1993
|
+
// @ts-expect-error: forceConsistentCasingInFileNames compiler option
|
|
1922
1994
|
Accessory.Categories = Categories;
|
|
1923
1995
|
return Accessory;
|
|
1924
1996
|
}(events_1.EventEmitter));
|