hap-nodejs 0.10.0-beta.0 → 0.10.0-beta.4
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 -1
- package/dist/BridgedCore.js +3 -3
- package/dist/BridgedCore.js.map +1 -1
- package/dist/Core.js +3 -3
- package/dist/Core.js.map +1 -1
- package/dist/accessories/AppleTVRemote_accessory.js +8 -8
- package/dist/accessories/AppleTVRemote_accessory.js.map +1 -1
- package/dist/accessories/Camera_accessory.js +2 -2
- package/dist/accessories/Camera_accessory.js.map +1 -1
- package/dist/accessories/Fan_accessory.js +4 -4
- package/dist/accessories/gstreamer-audioProducer.js +7 -7
- package/dist/accessories/gstreamer-audioProducer.js.map +1 -1
- package/dist/index.d.ts +5 -0
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +34 -24
- package/dist/index.js.map +1 -1
- package/dist/lib/Accessory.d.ts +25 -4
- package/dist/lib/Accessory.d.ts.map +1 -1
- package/dist/lib/Accessory.js +121 -81
- package/dist/lib/Accessory.js.map +1 -1
- package/dist/lib/AccessoryLoader.js +5 -5
- package/dist/lib/AccessoryLoader.js.map +1 -1
- package/dist/lib/Advertiser.d.ts +19 -2
- package/dist/lib/Advertiser.d.ts.map +1 -1
- package/dist/lib/Advertiser.js +120 -25
- package/dist/lib/Advertiser.js.map +1 -1
- package/dist/lib/Bridge.js +1 -1
- package/dist/lib/Bridge.js.map +1 -1
- package/dist/lib/Characteristic.d.ts +13 -1
- package/dist/lib/Characteristic.d.ts.map +1 -1
- package/dist/lib/Characteristic.js +48 -48
- package/dist/lib/Characteristic.js.map +1 -1
- package/dist/lib/HAPServer.js +26 -26
- package/dist/lib/HAPServer.js.map +1 -1
- package/dist/lib/Service.d.ts +5 -1
- package/dist/lib/Service.d.ts.map +1 -1
- package/dist/lib/Service.js +29 -25
- package/dist/lib/Service.js.map +1 -1
- package/dist/lib/camera/RTPProxy.js +1 -1
- package/dist/lib/camera/RTPProxy.js.map +1 -1
- package/dist/lib/camera/RTPStreamManagement.d.ts +2 -2
- package/dist/lib/camera/RTPStreamManagement.d.ts.map +1 -1
- package/dist/lib/camera/RTPStreamManagement.js +16 -15
- package/dist/lib/camera/RTPStreamManagement.js.map +1 -1
- package/dist/lib/camera/index.js +3 -3
- package/dist/lib/camera/index.js.map +1 -1
- package/dist/lib/controller/AdaptiveLightingController.js +12 -12
- package/dist/lib/controller/AdaptiveLightingController.js.map +1 -1
- package/dist/lib/controller/CameraController.js +5 -5
- package/dist/lib/controller/CameraController.js.map +1 -1
- package/dist/lib/controller/DoorbellController.js +1 -1
- package/dist/lib/controller/DoorbellController.js.map +1 -1
- package/dist/lib/controller/RemoteController.js +20 -20
- 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.js +3 -3
- package/dist/lib/datastream/DataStreamManagement.js.map +1 -1
- package/dist/lib/datastream/DataStreamParser.js +15 -15
- package/dist/lib/datastream/DataStreamParser.js.map +1 -1
- package/dist/lib/datastream/DataStreamServer.js +10 -10
- 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.d.ts +84 -0
- package/dist/lib/definitions/CharacteristicDefinitions.d.ts.map +1 -1
- package/dist/lib/definitions/CharacteristicDefinitions.js +471 -243
- package/dist/lib/definitions/CharacteristicDefinitions.js.map +1 -1
- package/dist/lib/definitions/ServiceDefinitions.d.ts +28 -0
- package/dist/lib/definitions/ServiceDefinitions.d.ts.map +1 -1
- package/dist/lib/definitions/ServiceDefinitions.js +158 -74
- package/dist/lib/definitions/ServiceDefinitions.js.map +1 -1
- package/dist/lib/definitions/generate-definitions.js +59 -59
- package/dist/lib/definitions/generate-definitions.js.map +1 -1
- package/dist/lib/definitions/generator-configuration.js +2 -2
- 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.js +9 -9
- package/dist/lib/model/AccessoryInfo.js.map +1 -1
- package/dist/lib/model/ControllerStorage.js +6 -6
- package/dist/lib/model/ControllerStorage.js.map +1 -1
- package/dist/lib/model/HAPStorage.js +1 -1
- package/dist/lib/model/HAPStorage.js.map +1 -1
- package/dist/lib/model/IdentifierCache.js +2 -2
- package/dist/lib/model/IdentifierCache.js.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 +4 -4
- package/dist/lib/util/clone.js.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.js +32 -32
- package/dist/lib/util/eventedhttp.js.map +1 -1
- package/dist/lib/util/hapCrypto.d.ts.map +1 -1
- package/dist/lib/util/hapCrypto.js +20 -7
- package/dist/lib/util/hapCrypto.js.map +1 -1
- package/dist/lib/util/hapStatusError.js +2 -2
- package/dist/lib/util/hapStatusError.js.map +1 -1
- package/dist/lib/util/net-utils.js +6 -6
- package/dist/lib/util/net-utils.js.map +1 -1
- package/dist/lib/util/once.js +1 -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/time.js +3 -3
- package/dist/lib/util/time.js.map +1 -1
- package/dist/lib/util/tlv.js +6 -6
- package/dist/lib/util/tlv.js.map +1 -1
- package/dist/lib/util/uuid.js +1 -1
- package/dist/lib/util/uuid.js.map +1 -1
- package/package.json +17 -17
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('HAP-NodeJS:Accessory');
|
|
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;
|
|
@@ -175,9 +194,9 @@ var Accessory = /** @class */ (function (_super) {
|
|
|
175
194
|
//Revert back the purge mechanism state
|
|
176
195
|
_this.shouldPurgeUnusedIDs = oldValue;
|
|
177
196
|
};
|
|
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.");
|
|
197
|
+
(0, assert_1.default)(displayName, "Accessories must be created with a non-empty displayName.");
|
|
198
|
+
(0, assert_1.default)(UUID, "Accessories must be created with a valid UUID.");
|
|
199
|
+
(0, 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.");
|
|
181
200
|
// create our initial "Accessory Information" Service that all Accessories are expected to have
|
|
182
201
|
_this.addService(Service_1.Service.AccessoryInformation)
|
|
183
202
|
.setCharacteristic(Characteristic_1.Characteristic.Name, displayName);
|
|
@@ -218,7 +237,7 @@ var Accessory = /** @class */ (function (_super) {
|
|
|
218
237
|
: serviceParam;
|
|
219
238
|
try {
|
|
220
239
|
// check for UUID+subtype conflict
|
|
221
|
-
for (var _b = tslib_1.__values(this.services), _c = _b.next(); !_c.done; _c = _b.next()) {
|
|
240
|
+
for (var _b = (0, tslib_1.__values)(this.services), _c = _b.next(); !_c.done; _c = _b.next()) {
|
|
222
241
|
var existing = _c.value;
|
|
223
242
|
if (existing.UUID === service.UUID) {
|
|
224
243
|
// OK we have two Services with the same UUID. Check that each defines a `subtype` property and that each is unique.
|
|
@@ -281,7 +300,7 @@ var Accessory = /** @class */ (function (_super) {
|
|
|
281
300
|
Accessory.prototype.removeLinkedService = function (removed) {
|
|
282
301
|
var e_2, _a;
|
|
283
302
|
try {
|
|
284
|
-
for (var _b = tslib_1.__values(this.services), _c = _b.next(); !_c.done; _c = _b.next()) {
|
|
303
|
+
for (var _b = (0, tslib_1.__values)(this.services), _c = _b.next(); !_c.done; _c = _b.next()) {
|
|
285
304
|
var service = _c.value;
|
|
286
305
|
service.removeLinkedService(removed);
|
|
287
306
|
}
|
|
@@ -297,10 +316,11 @@ var Accessory = /** @class */ (function (_super) {
|
|
|
297
316
|
Accessory.prototype.getService = function (name) {
|
|
298
317
|
var e_3, _a;
|
|
299
318
|
try {
|
|
300
|
-
for (var _b = tslib_1.__values(this.services), _c = _b.next(); !_c.done; _c = _b.next()) {
|
|
319
|
+
for (var _b = (0, tslib_1.__values)(this.services), _c = _b.next(); !_c.done; _c = _b.next()) {
|
|
301
320
|
var service = _c.value;
|
|
302
321
|
if (typeof name === 'string' && (service.displayName === name || service.name === name || service.subtype === name)) {
|
|
303
322
|
return service;
|
|
323
|
+
// @ts-expect-error
|
|
304
324
|
}
|
|
305
325
|
else if (typeof name === 'function' && ((service instanceof name) || (name.UUID === service.UUID))) {
|
|
306
326
|
return service;
|
|
@@ -319,10 +339,11 @@ var Accessory = /** @class */ (function (_super) {
|
|
|
319
339
|
Accessory.prototype.getServiceById = function (uuid, subType) {
|
|
320
340
|
var e_4, _a;
|
|
321
341
|
try {
|
|
322
|
-
for (var _b = tslib_1.__values(this.services), _c = _b.next(); !_c.done; _c = _b.next()) {
|
|
342
|
+
for (var _b = (0, tslib_1.__values)(this.services), _c = _b.next(); !_c.done; _c = _b.next()) {
|
|
323
343
|
var service = _c.value;
|
|
324
344
|
if (typeof uuid === "string" && (service.displayName === uuid || service.name === uuid) && service.subtype === subType) {
|
|
325
345
|
return service;
|
|
346
|
+
// @ts-expect-error
|
|
326
347
|
}
|
|
327
348
|
else if (typeof uuid === "function" && ((service instanceof uuid) || (uuid.UUID === service.UUID)) && service.subtype === subType) {
|
|
328
349
|
return service;
|
|
@@ -356,7 +377,7 @@ var Accessory = /** @class */ (function (_super) {
|
|
|
356
377
|
}
|
|
357
378
|
try {
|
|
358
379
|
// check for UUID conflict
|
|
359
|
-
for (var _b = tslib_1.__values(this.bridgedAccessories), _c = _b.next(); !_c.done; _c = _b.next()) {
|
|
380
|
+
for (var _b = (0, tslib_1.__values)(this.bridgedAccessories), _c = _b.next(); !_c.done; _c = _b.next()) {
|
|
360
381
|
var existing = _c.value;
|
|
361
382
|
if (existing.UUID === accessory.UUID) {
|
|
362
383
|
throw new Error("Cannot add a bridged Accessory with the same UUID as another bridged Accessory: " + existing.UUID);
|
|
@@ -389,7 +410,7 @@ var Accessory = /** @class */ (function (_super) {
|
|
|
389
410
|
Accessory.prototype.addBridgedAccessories = function (accessories) {
|
|
390
411
|
var e_6, _a;
|
|
391
412
|
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()) {
|
|
413
|
+
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
414
|
var accessory = accessories_1_1.value;
|
|
394
415
|
this.addBridgedAccessory(accessory, true);
|
|
395
416
|
}
|
|
@@ -421,7 +442,7 @@ var Accessory = /** @class */ (function (_super) {
|
|
|
421
442
|
Accessory.prototype.removeBridgedAccessories = function (accessories) {
|
|
422
443
|
var e_7, _a;
|
|
423
444
|
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()) {
|
|
445
|
+
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
446
|
var accessory = accessories_2_1.value;
|
|
426
447
|
this.removeBridgedAccessory(accessory, true);
|
|
427
448
|
}
|
|
@@ -444,7 +465,7 @@ var Accessory = /** @class */ (function (_super) {
|
|
|
444
465
|
Accessory.prototype.getCharacteristicByIID = function (iid) {
|
|
445
466
|
var e_8, _a;
|
|
446
467
|
try {
|
|
447
|
-
for (var _b = tslib_1.__values(this.services), _c = _b.next(); !_c.done; _c = _b.next()) {
|
|
468
|
+
for (var _b = (0, tslib_1.__values)(this.services), _c = _b.next(); !_c.done; _c = _b.next()) {
|
|
448
469
|
var service = _c.value;
|
|
449
470
|
var characteristic = service.getCharacteristicByIID(iid);
|
|
450
471
|
if (characteristic) {
|
|
@@ -466,7 +487,7 @@ var Accessory = /** @class */ (function (_super) {
|
|
|
466
487
|
return this;
|
|
467
488
|
}
|
|
468
489
|
try {
|
|
469
|
-
for (var _b = tslib_1.__values(this.bridgedAccessories), _c = _b.next(); !_c.done; _c = _b.next()) {
|
|
490
|
+
for (var _b = (0, tslib_1.__values)(this.bridgedAccessories), _c = _b.next(); !_c.done; _c = _b.next()) {
|
|
470
491
|
var accessory = _c.value;
|
|
471
492
|
if (accessory.aid === aid) {
|
|
472
493
|
return accessory;
|
|
@@ -563,7 +584,7 @@ var Accessory = /** @class */ (function (_super) {
|
|
|
563
584
|
var savedServiceMap = this.serializedControllers && this.serializedControllers[id];
|
|
564
585
|
var serviceMap;
|
|
565
586
|
if (savedServiceMap) { // we found data to restore from
|
|
566
|
-
var clonedServiceMap = clone_1.clone(savedServiceMap);
|
|
587
|
+
var clonedServiceMap = (0, clone_1.clone)(savedServiceMap);
|
|
567
588
|
var updatedServiceMap = controller.initWithServices(savedServiceMap); // init controller with existing services
|
|
568
589
|
serviceMap = updatedServiceMap || savedServiceMap; // initWithServices could return a updated serviceMap, otherwise just use the existing one
|
|
569
590
|
if (updatedServiceMap) { // controller returned a ServiceMap and thus signaled a updated set of services
|
|
@@ -591,7 +612,7 @@ var Accessory = /** @class */ (function (_super) {
|
|
|
591
612
|
controller: controller,
|
|
592
613
|
serviceMap: serviceMap,
|
|
593
614
|
};
|
|
594
|
-
if (controller_1.isSerializableController(controller)) {
|
|
615
|
+
if ((0, controller_1.isSerializableController)(controller)) {
|
|
595
616
|
this.controllerStorage.trackController(controller);
|
|
596
617
|
}
|
|
597
618
|
this.controllers[id] = context;
|
|
@@ -614,7 +635,7 @@ var Accessory = /** @class */ (function (_super) {
|
|
|
614
635
|
if (storedController.controller !== controller) {
|
|
615
636
|
throw new Error("[" + this.displayName + "] tried removing a controller with the id/type '" + id + "' though provided controller isn't the same which is registered!");
|
|
616
637
|
}
|
|
617
|
-
if (controller_1.isSerializableController(controller)) {
|
|
638
|
+
if ((0, controller_1.isSerializableController)(controller)) {
|
|
618
639
|
// this will reset the state change delegate before we call handleControllerRemoved()
|
|
619
640
|
this.controllerStorage.untrackController(controller);
|
|
620
641
|
}
|
|
@@ -639,13 +660,13 @@ var Accessory = /** @class */ (function (_super) {
|
|
|
639
660
|
Accessory.prototype.handleAccessoryUnpairedForControllers = function () {
|
|
640
661
|
var e_10, _a;
|
|
641
662
|
try {
|
|
642
|
-
for (var _b = tslib_1.__values(Object.values(this.controllers)), _c = _b.next(); !_c.done; _c = _b.next()) {
|
|
663
|
+
for (var _b = (0, tslib_1.__values)(Object.values(this.controllers)), _c = _b.next(); !_c.done; _c = _b.next()) {
|
|
643
664
|
var context = _c.value;
|
|
644
665
|
var controller = context.controller;
|
|
645
666
|
if (controller.handleFactoryReset) { // if the controller implements handleFactoryReset, setup event handlers for this controller
|
|
646
667
|
controller.handleFactoryReset();
|
|
647
668
|
}
|
|
648
|
-
if (controller_1.isSerializableController(controller)) {
|
|
669
|
+
if ((0, controller_1.isSerializableController)(controller)) {
|
|
649
670
|
this.controllerStorage.purgeControllerData(controller);
|
|
650
671
|
}
|
|
651
672
|
}
|
|
@@ -660,7 +681,7 @@ var Accessory = /** @class */ (function (_super) {
|
|
|
660
681
|
};
|
|
661
682
|
Accessory.prototype.handleUpdatedControllerServiceMap = function (originalServiceMap, updatedServiceMap) {
|
|
662
683
|
var _this = this;
|
|
663
|
-
updatedServiceMap = clone_1.clone(updatedServiceMap); // clone it so we can alter it
|
|
684
|
+
updatedServiceMap = (0, clone_1.clone)(updatedServiceMap); // clone it so we can alter it
|
|
664
685
|
Object.keys(originalServiceMap).forEach(function (name) {
|
|
665
686
|
var service = originalServiceMap[name];
|
|
666
687
|
var updatedService = updatedServiceMap[name];
|
|
@@ -739,7 +760,7 @@ var Accessory = /** @class */ (function (_super) {
|
|
|
739
760
|
}
|
|
740
761
|
if (mainAccessory) {
|
|
741
762
|
// 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!");
|
|
763
|
+
(0, assert_1.default)(Buffer.from(this.displayName, "utf8").length <= 63, "Accessory displayName cannot be longer than 63 bytes!");
|
|
743
764
|
}
|
|
744
765
|
if (this.bridged) {
|
|
745
766
|
this.bridgedAccessories.forEach(function (accessory) { return accessory.validateAccessory(); });
|
|
@@ -767,7 +788,7 @@ var Accessory = /** @class */ (function (_super) {
|
|
|
767
788
|
this.aid = 1;
|
|
768
789
|
}
|
|
769
790
|
try {
|
|
770
|
-
for (var _c = tslib_1.__values(this.services), _d = _c.next(); !_d.done; _d = _c.next()) {
|
|
791
|
+
for (var _c = (0, tslib_1.__values)(this.services), _d = _c.next(); !_d.done; _d = _c.next()) {
|
|
771
792
|
var service = _d.value;
|
|
772
793
|
if (this._isBridge) {
|
|
773
794
|
service._assignIDs(identifierCache, this.UUID, 2000000000);
|
|
@@ -786,7 +807,7 @@ var Accessory = /** @class */ (function (_super) {
|
|
|
786
807
|
}
|
|
787
808
|
try {
|
|
788
809
|
// 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()) {
|
|
810
|
+
for (var _e = (0, tslib_1.__values)(this.bridgedAccessories), _f = _e.next(); !_f.done; _f = _e.next()) {
|
|
790
811
|
var accessory = _f.value;
|
|
791
812
|
accessory._assignIDs(identifierCache);
|
|
792
813
|
}
|
|
@@ -813,14 +834,14 @@ var Accessory = /** @class */ (function (_super) {
|
|
|
813
834
|
*/
|
|
814
835
|
Accessory.prototype.toHAP = function (connection, contactGetHandlers) {
|
|
815
836
|
if (contactGetHandlers === void 0) { contactGetHandlers = true; }
|
|
816
|
-
return tslib_1.__awaiter(this, void 0, void 0, function () {
|
|
837
|
+
return (0, tslib_1.__awaiter)(this, void 0, void 0, function () {
|
|
817
838
|
var accessory, accessories, _a, _b, _c, _d;
|
|
818
839
|
var _e;
|
|
819
|
-
return tslib_1.__generator(this, function (_f) {
|
|
840
|
+
return (0, tslib_1.__generator)(this, function (_f) {
|
|
820
841
|
switch (_f.label) {
|
|
821
842
|
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!");
|
|
843
|
+
(0, assert_1.default)(this.aid, "aid cannot be undefined for accessory '" + this.displayName + "'");
|
|
844
|
+
(0, assert_1.default)(this.services.length, "accessory '" + this.displayName + "' does not have any services!");
|
|
824
845
|
_e = {
|
|
825
846
|
aid: this.aid
|
|
826
847
|
};
|
|
@@ -836,7 +857,7 @@ var Accessory = /** @class */ (function (_super) {
|
|
|
836
857
|
return [4 /*yield*/, Promise.all(this.bridgedAccessories
|
|
837
858
|
.map(function (accessory) { return accessory.toHAP(connection, contactGetHandlers).then(function (value) { return value[0]; }); }))];
|
|
838
859
|
case 2:
|
|
839
|
-
_b.apply(_a, _c.concat([tslib_1.__spreadArray.apply(void 0, _d.concat([tslib_1.__read.apply(void 0, [_f.sent()])]))]));
|
|
860
|
+
_b.apply(_a, _c.concat([tslib_1.__spreadArray.apply(void 0, _d.concat([tslib_1.__read.apply(void 0, [_f.sent()]), false]))]));
|
|
840
861
|
_f.label = 3;
|
|
841
862
|
case 3: return [2 /*return*/, accessories];
|
|
842
863
|
}
|
|
@@ -852,8 +873,8 @@ var Accessory = /** @class */ (function (_super) {
|
|
|
852
873
|
if (assignIds) {
|
|
853
874
|
this._assignIDs(this._identifierCache); // make sure our aid/iid's are all assigned
|
|
854
875
|
}
|
|
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!");
|
|
876
|
+
(0, assert_1.default)(this.aid, "aid cannot be undefined for accessory '" + this.displayName + "'");
|
|
877
|
+
(0, assert_1.default)(this.services.length, "accessory '" + this.displayName + "' does not have any services!");
|
|
857
878
|
var accessory = {
|
|
858
879
|
aid: this.aid,
|
|
859
880
|
services: this.services.map(function (service) { return service.internalHAPRepresentation(); }),
|
|
@@ -861,7 +882,7 @@ var Accessory = /** @class */ (function (_super) {
|
|
|
861
882
|
var accessories = [accessory];
|
|
862
883
|
if (!this.bridged) {
|
|
863
884
|
try {
|
|
864
|
-
for (var _b = tslib_1.__values(this.bridgedAccessories), _c = _b.next(); !_c.done; _c = _b.next()) {
|
|
885
|
+
for (var _b = (0, tslib_1.__values)(this.bridgedAccessories), _c = _b.next(); !_c.done; _c = _b.next()) {
|
|
865
886
|
var accessory_1 = _c.value;
|
|
866
887
|
accessories.push(accessory_1.internalHAPRepresentation(false)[0]);
|
|
867
888
|
}
|
|
@@ -913,8 +934,8 @@ var Accessory = /** @class */ (function (_super) {
|
|
|
913
934
|
if (this.lastKnownUsername && this.lastKnownUsername !== info.username) { // username changed since last publish
|
|
914
935
|
Accessory.cleanupAccessoryData(this.lastKnownUsername); // delete old Accessory data
|
|
915
936
|
}
|
|
916
|
-
if ((_a = info.addIdentifyingMaterial) !== null && _a !== void 0 ? _a : true) {
|
|
917
|
-
// adding some identifying material to our displayName
|
|
937
|
+
if (!this.initialized && ((_a = info.addIdentifyingMaterial) !== null && _a !== void 0 ? _a : true)) {
|
|
938
|
+
// adding some identifying material to our displayName if its our first publish() call
|
|
918
939
|
this.displayName = this.displayName + " " + crypto_1.default.createHash('sha512')
|
|
919
940
|
.update(info.username, 'utf8')
|
|
920
941
|
.digest('hex').slice(0, 4).toUpperCase();
|
|
@@ -958,7 +979,9 @@ var Accessory = /** @class */ (function (_super) {
|
|
|
958
979
|
this.disableUnusedIDPurge();
|
|
959
980
|
this.controllerStorage.purgeUnidentifiedAccessoryData = false;
|
|
960
981
|
}
|
|
961
|
-
this.
|
|
982
|
+
if (!this.initialized) { // controller storage is only loaded from disk the first time we publish!
|
|
983
|
+
this.controllerStorage.load(info.username); // initializing controller data
|
|
984
|
+
}
|
|
962
985
|
// assign aid/iid
|
|
963
986
|
this._assignIDs(this._identifierCache);
|
|
964
987
|
// get our accessory information in HAP format and determine if our configuration (that is, our
|
|
@@ -987,6 +1010,9 @@ var Accessory = /** @class */ (function (_super) {
|
|
|
987
1010
|
disabledIpv6: parsed.serviceDisableIpv6,
|
|
988
1011
|
});
|
|
989
1012
|
break;
|
|
1013
|
+
case "avahi" /* AVAHI */:
|
|
1014
|
+
this._advertiser = new Advertiser_1.AvahiAdvertiser(this._accessoryInfo);
|
|
1015
|
+
break;
|
|
990
1016
|
default:
|
|
991
1017
|
throw new Error("Unsupported advertiser setting: '" + info.advertiser + "'");
|
|
992
1018
|
}
|
|
@@ -1015,6 +1041,7 @@ var Accessory = /** @class */ (function (_super) {
|
|
|
1015
1041
|
this._server.on("connection-closed" /* CONNECTION_CLOSED */, this.handleHAPConnectionClosed.bind(this));
|
|
1016
1042
|
this._server.on("request-resource" /* REQUEST_RESOURCE */, this.handleResource.bind(this));
|
|
1017
1043
|
this._server.listen(info.port, parsed.serverAddress);
|
|
1044
|
+
this.initialized = true;
|
|
1018
1045
|
};
|
|
1019
1046
|
/**
|
|
1020
1047
|
* Removes this Accessory from the local network
|
|
@@ -1022,7 +1049,7 @@ var Accessory = /** @class */ (function (_super) {
|
|
|
1022
1049
|
* Trying to invoke publish() on the object will result undefined behavior
|
|
1023
1050
|
*/
|
|
1024
1051
|
Accessory.prototype.destroy = function () {
|
|
1025
|
-
this.unpublish();
|
|
1052
|
+
var promise = this.unpublish();
|
|
1026
1053
|
if (this._accessoryInfo) {
|
|
1027
1054
|
Accessory.cleanupAccessoryData(this._accessoryInfo.username);
|
|
1028
1055
|
this._accessoryInfo = undefined;
|
|
@@ -1030,17 +1057,29 @@ var Accessory = /** @class */ (function (_super) {
|
|
|
1030
1057
|
this.controllerStorage = new ControllerStorage_1.ControllerStorage(this);
|
|
1031
1058
|
}
|
|
1032
1059
|
this.removeAllListeners();
|
|
1060
|
+
return promise;
|
|
1033
1061
|
};
|
|
1034
1062
|
Accessory.prototype.unpublish = function () {
|
|
1035
|
-
|
|
1036
|
-
|
|
1037
|
-
|
|
1038
|
-
|
|
1039
|
-
|
|
1040
|
-
|
|
1041
|
-
|
|
1042
|
-
|
|
1043
|
-
|
|
1063
|
+
return (0, tslib_1.__awaiter)(this, void 0, void 0, function () {
|
|
1064
|
+
return (0, tslib_1.__generator)(this, function (_a) {
|
|
1065
|
+
switch (_a.label) {
|
|
1066
|
+
case 0:
|
|
1067
|
+
if (this._server) {
|
|
1068
|
+
this._server.destroy();
|
|
1069
|
+
this._server = undefined;
|
|
1070
|
+
}
|
|
1071
|
+
if (!this._advertiser) return [3 /*break*/, 2];
|
|
1072
|
+
// noinspection JSIgnoredPromiseFromCall
|
|
1073
|
+
return [4 /*yield*/, this._advertiser.destroy()];
|
|
1074
|
+
case 1:
|
|
1075
|
+
// noinspection JSIgnoredPromiseFromCall
|
|
1076
|
+
_a.sent();
|
|
1077
|
+
this._advertiser = undefined;
|
|
1078
|
+
_a.label = 2;
|
|
1079
|
+
case 2: return [2 /*return*/];
|
|
1080
|
+
}
|
|
1081
|
+
});
|
|
1082
|
+
});
|
|
1044
1083
|
};
|
|
1045
1084
|
Accessory.prototype.enqueueConfigurationUpdate = function () {
|
|
1046
1085
|
var _this = this;
|
|
@@ -1066,11 +1105,12 @@ var Accessory = /** @class */ (function (_super) {
|
|
|
1066
1105
|
// not responding or new accessories/services not yet shown
|
|
1067
1106
|
};
|
|
1068
1107
|
Accessory.prototype.onListening = function (port, hostname) {
|
|
1069
|
-
|
|
1108
|
+
var _this = this;
|
|
1109
|
+
(0, assert_1.default)(this._advertiser, "Advertiser wasn't created at onListening!");
|
|
1070
1110
|
// the HAP server is listening, so we can now start advertising our presence.
|
|
1071
1111
|
this._advertiser.initPort(port);
|
|
1072
|
-
|
|
1073
|
-
|
|
1112
|
+
this._advertiser.startAdvertising()
|
|
1113
|
+
.then(function () { return _this.emit("advertised" /* ADVERTISED */); });
|
|
1074
1114
|
this.emit("listening" /* LISTENING */, port, hostname);
|
|
1075
1115
|
};
|
|
1076
1116
|
Accessory.prototype.handleInitialPairSetupFinished = function (username, publicKey, callback) {
|
|
@@ -1124,7 +1164,7 @@ var Accessory = /** @class */ (function (_super) {
|
|
|
1124
1164
|
this.emit("unpaired" /* UNPAIRED */);
|
|
1125
1165
|
this.handleAccessoryUnpairedForControllers();
|
|
1126
1166
|
try {
|
|
1127
|
-
for (var _b = tslib_1.__values(this.bridgedAccessories), _c = _b.next(); !_c.done; _c = _b.next()) {
|
|
1167
|
+
for (var _b = (0, tslib_1.__values)(this.bridgedAccessories), _c = _b.next(); !_c.done; _c = _b.next()) {
|
|
1128
1168
|
var accessory = _c.value;
|
|
1129
1169
|
accessory.handleAccessoryUnpairedForControllers();
|
|
1130
1170
|
}
|
|
@@ -1178,7 +1218,7 @@ var Accessory = /** @class */ (function (_super) {
|
|
|
1178
1218
|
var timeout = setTimeout(function () {
|
|
1179
1219
|
var e_16, _a;
|
|
1180
1220
|
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()) {
|
|
1221
|
+
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
1222
|
var id = missingCharacteristics_1_1.value;
|
|
1183
1223
|
var split = id.split(".");
|
|
1184
1224
|
var aid = parseInt(split[0], 10);
|
|
@@ -1201,7 +1241,7 @@ var Accessory = /** @class */ (function (_super) {
|
|
|
1201
1241
|
var e_17, _a;
|
|
1202
1242
|
timeout = undefined;
|
|
1203
1243
|
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()) {
|
|
1244
|
+
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
1245
|
var id = missingCharacteristics_2_1.value;
|
|
1206
1246
|
var split = id.split(".");
|
|
1207
1247
|
var aid = parseInt(split[0], 10);
|
|
@@ -1233,7 +1273,7 @@ var Accessory = /** @class */ (function (_super) {
|
|
|
1233
1273
|
var _loop_1 = function (id) {
|
|
1234
1274
|
var name = id.aid + "." + id.iid;
|
|
1235
1275
|
this_1.handleCharacteristicRead(connection, id, request).then(function (value) {
|
|
1236
|
-
return tslib_1.__assign({ aid: id.aid, iid: id.iid }, value);
|
|
1276
|
+
return (0, tslib_1.__assign)({ aid: id.aid, iid: id.iid }, value);
|
|
1237
1277
|
}, function (reason) {
|
|
1238
1278
|
console.error("[" + _this.displayName + "] Read request for characteristic " + name + " encountered an error: " + reason.stack);
|
|
1239
1279
|
return {
|
|
@@ -1258,7 +1298,7 @@ var Accessory = /** @class */ (function (_super) {
|
|
|
1258
1298
|
};
|
|
1259
1299
|
var this_1 = this;
|
|
1260
1300
|
try {
|
|
1261
|
-
for (var _b = tslib_1.__values(request.ids), _c = _b.next(); !_c.done; _c = _b.next()) {
|
|
1301
|
+
for (var _b = (0, tslib_1.__values)(request.ids), _c = _b.next(); !_c.done; _c = _b.next()) {
|
|
1262
1302
|
var id = _c.value;
|
|
1263
1303
|
_loop_1(id);
|
|
1264
1304
|
}
|
|
@@ -1272,10 +1312,10 @@ var Accessory = /** @class */ (function (_super) {
|
|
|
1272
1312
|
}
|
|
1273
1313
|
};
|
|
1274
1314
|
Accessory.prototype.handleCharacteristicRead = function (connection, id, request) {
|
|
1275
|
-
return tslib_1.__awaiter(this, void 0, void 0, function () {
|
|
1315
|
+
return (0, tslib_1.__awaiter)(this, void 0, void 0, function () {
|
|
1276
1316
|
var characteristic, verifiable;
|
|
1277
1317
|
var _this = this;
|
|
1278
|
-
return tslib_1.__generator(this, function (_a) {
|
|
1318
|
+
return (0, tslib_1.__generator)(this, function (_a) {
|
|
1279
1319
|
characteristic = this.findCharacteristic(id.aid, id.iid);
|
|
1280
1320
|
if (!characteristic) {
|
|
1281
1321
|
debug('[%s] Could not find a Characteristic with aid of %s and iid of %s', this.displayName, id.aid, id.iid);
|
|
@@ -1296,7 +1336,7 @@ var Accessory = /** @class */ (function (_super) {
|
|
|
1296
1336
|
}
|
|
1297
1337
|
}
|
|
1298
1338
|
return [2 /*return*/, characteristic.handleGetRequest(connection).then(function (value) {
|
|
1299
|
-
value = request_util_1.formatOutgoingCharacteristicValue(value, characteristic.props);
|
|
1339
|
+
value = (0, request_util_1.formatOutgoingCharacteristicValue)(value, characteristic.props);
|
|
1300
1340
|
debug('[%s] Got Characteristic "%s" value: "%s"', _this.displayName, characteristic.displayName, value);
|
|
1301
1341
|
var data = {
|
|
1302
1342
|
value: value == undefined ? null : value,
|
|
@@ -1313,7 +1353,7 @@ var Accessory = /** @class */ (function (_super) {
|
|
|
1313
1353
|
data.perms = characteristic.props.perms;
|
|
1314
1354
|
}
|
|
1315
1355
|
if (request.includeType) {
|
|
1316
|
-
data.type = uuid_1.toShortForm(_this.UUID);
|
|
1356
|
+
data.type = (0, uuid_1.toShortForm)(_this.UUID);
|
|
1317
1357
|
}
|
|
1318
1358
|
if (request.includeEvent) {
|
|
1319
1359
|
data.ev = connection.hasEventNotifications(id.aid, id.iid);
|
|
@@ -1357,7 +1397,7 @@ var Accessory = /** @class */ (function (_super) {
|
|
|
1357
1397
|
var timeout = setTimeout(function () {
|
|
1358
1398
|
var e_19, _a;
|
|
1359
1399
|
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()) {
|
|
1400
|
+
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
1401
|
var id = missingCharacteristics_3_1.value;
|
|
1362
1402
|
var split = id.split(".");
|
|
1363
1403
|
var aid = parseInt(split[0], 10);
|
|
@@ -1380,7 +1420,7 @@ var Accessory = /** @class */ (function (_super) {
|
|
|
1380
1420
|
var e_20, _a;
|
|
1381
1421
|
timeout = undefined;
|
|
1382
1422
|
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()) {
|
|
1423
|
+
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
1424
|
var id = missingCharacteristics_4_1.value;
|
|
1385
1425
|
var split = id.split(".");
|
|
1386
1426
|
var aid = parseInt(split[0], 10);
|
|
@@ -1412,7 +1452,7 @@ var Accessory = /** @class */ (function (_super) {
|
|
|
1412
1452
|
var _loop_2 = function (data) {
|
|
1413
1453
|
var name = data.aid + "." + data.iid;
|
|
1414
1454
|
this_2.handleCharacteristicWrite(connection, data, writeState).then(function (value) {
|
|
1415
|
-
return tslib_1.__assign({ aid: data.aid, iid: data.iid }, value);
|
|
1455
|
+
return (0, tslib_1.__assign)({ aid: data.aid, iid: data.iid }, value);
|
|
1416
1456
|
}, function (reason) {
|
|
1417
1457
|
console.error("[" + _this.displayName + "] Write request for characteristic " + name + " encountered an error: " + reason.stack);
|
|
1418
1458
|
return {
|
|
@@ -1437,7 +1477,7 @@ var Accessory = /** @class */ (function (_super) {
|
|
|
1437
1477
|
};
|
|
1438
1478
|
var this_2 = this;
|
|
1439
1479
|
try {
|
|
1440
|
-
for (var _b = tslib_1.__values(writeRequest.characteristics), _c = _b.next(); !_c.done; _c = _b.next()) {
|
|
1480
|
+
for (var _b = (0, tslib_1.__values)(writeRequest.characteristics), _c = _b.next(); !_c.done; _c = _b.next()) {
|
|
1441
1481
|
var data = _c.value;
|
|
1442
1482
|
_loop_2(data);
|
|
1443
1483
|
}
|
|
@@ -1451,10 +1491,10 @@ var Accessory = /** @class */ (function (_super) {
|
|
|
1451
1491
|
}
|
|
1452
1492
|
};
|
|
1453
1493
|
Accessory.prototype.handleCharacteristicWrite = function (connection, data, writeState) {
|
|
1454
|
-
return tslib_1.__awaiter(this, void 0, void 0, function () {
|
|
1494
|
+
return (0, tslib_1.__awaiter)(this, void 0, void 0, function () {
|
|
1455
1495
|
var characteristic, evResponse, notificationsEnabled, verifiable, verifiable, allowWrite;
|
|
1456
1496
|
var _this = this;
|
|
1457
|
-
return tslib_1.__generator(this, function (_a) {
|
|
1497
|
+
return (0, tslib_1.__generator)(this, function (_a) {
|
|
1458
1498
|
characteristic = this.findCharacteristic(data.aid, data.iid);
|
|
1459
1499
|
evResponse = undefined;
|
|
1460
1500
|
if (!characteristic) {
|
|
@@ -1520,7 +1560,7 @@ var Accessory = /** @class */ (function (_super) {
|
|
|
1520
1560
|
allowWrite = characteristic.additionalAuthorizationHandler(data.authData);
|
|
1521
1561
|
}
|
|
1522
1562
|
catch (error) {
|
|
1523
|
-
console.
|
|
1563
|
+
console.warn("[" + this.displayName + "] Additional authorization handler has thrown an error when checking authData: " + error.stack);
|
|
1524
1564
|
allowWrite = false;
|
|
1525
1565
|
}
|
|
1526
1566
|
if (!allowWrite) {
|
|
@@ -1534,7 +1574,7 @@ var Accessory = /** @class */ (function (_super) {
|
|
|
1534
1574
|
return [2 /*return*/, characteristic.handleSetRequest(data.value, connection).then(function (value) {
|
|
1535
1575
|
debug('[%s] Setting Characteristic "%s" to value %s', _this.displayName, characteristic.displayName, data.value);
|
|
1536
1576
|
return {
|
|
1537
|
-
value: data.r && value ? request_util_1.formatOutgoingCharacteristicValue(value, characteristic.props) : undefined,
|
|
1577
|
+
value: data.r && value ? (0, request_util_1.formatOutgoingCharacteristicValue)(value, characteristic.props) : undefined,
|
|
1538
1578
|
ev: evResponse,
|
|
1539
1579
|
};
|
|
1540
1580
|
}, function (status) {
|
|
@@ -1587,7 +1627,7 @@ var Accessory = /** @class */ (function (_super) {
|
|
|
1587
1627
|
this.activeCameraController.handleCloseConnection(connection.sessionID);
|
|
1588
1628
|
}
|
|
1589
1629
|
try {
|
|
1590
|
-
for (var _b = tslib_1.__values(connection.getRegisteredEvents()), _c = _b.next(); !_c.done; _c = _b.next()) {
|
|
1630
|
+
for (var _b = (0, tslib_1.__values)(connection.getRegisteredEvents()), _c = _b.next(); !_c.done; _c = _b.next()) {
|
|
1591
1631
|
var event = _c.value;
|
|
1592
1632
|
var ids = event.split(".");
|
|
1593
1633
|
var aid = parseInt(ids[0], 10);
|
|
@@ -1628,7 +1668,7 @@ var Accessory = /** @class */ (function (_super) {
|
|
|
1628
1668
|
};
|
|
1629
1669
|
Accessory.prototype.handleCharacteristicChangeEvent = function (accessory, service, change) {
|
|
1630
1670
|
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 }));
|
|
1671
|
+
this.emit("service-characteristic-change" /* SERVICE_CHARACTERISTIC_CHANGE */, (0, tslib_1.__assign)((0, tslib_1.__assign)({}, change), { service: service }));
|
|
1632
1672
|
}
|
|
1633
1673
|
else {
|
|
1634
1674
|
if (!this._server) {
|
|
@@ -1654,7 +1694,7 @@ var Accessory = /** @class */ (function (_super) {
|
|
|
1654
1694
|
var uuid_2 = change.characteristic.UUID;
|
|
1655
1695
|
var immediateDelivery = uuid_2 === Characteristic_1.Characteristic.ButtonEvent.UUID || uuid_2 === Characteristic_1.Characteristic.ProgrammableSwitchEvent.UUID
|
|
1656
1696
|
|| 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);
|
|
1697
|
+
var value = (0, request_util_1.formatOutgoingCharacteristicValue)(change.newValue, change.characteristic.props);
|
|
1658
1698
|
this._server.sendEventNotifications(accessory.aid, change.characteristic.iid, value, change.originator, immediateDelivery);
|
|
1659
1699
|
}
|
|
1660
1700
|
};
|
|
@@ -1669,7 +1709,7 @@ var Accessory = /** @class */ (function (_super) {
|
|
|
1669
1709
|
};
|
|
1670
1710
|
Accessory.prototype.handleCharacteristicWarning = function (warning) {
|
|
1671
1711
|
var _a;
|
|
1672
|
-
warning.originatorChain = tslib_1.__spreadArray([this.displayName], tslib_1.__read(warning.originatorChain));
|
|
1712
|
+
warning.originatorChain = (0, tslib_1.__spreadArray)([this.displayName], (0, tslib_1.__read)(warning.originatorChain), false);
|
|
1673
1713
|
var emitted = this.emit("characteristic-warning" /* CHARACTERISTIC_WARNING */, warning);
|
|
1674
1714
|
if (!emitted) {
|
|
1675
1715
|
var message = "[" + warning.originatorChain.join("@") + "] " + warning.message;
|
|
@@ -1692,7 +1732,7 @@ var Accessory = /** @class */ (function (_super) {
|
|
|
1692
1732
|
var e_22, _a;
|
|
1693
1733
|
var _this = this;
|
|
1694
1734
|
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()) {
|
|
1735
|
+
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
1736
|
var service = targetServices_1_1.value;
|
|
1697
1737
|
this.setupServiceEventHandlers(service);
|
|
1698
1738
|
}
|
|
@@ -1761,7 +1801,7 @@ var Accessory = /** @class */ (function (_super) {
|
|
|
1761
1801
|
});
|
|
1762
1802
|
// also save controller which didn't get initialized (could lead to service duplication if we throw that data away)
|
|
1763
1803
|
accessory.serializedControllers && Object.entries(accessory.serializedControllers).forEach(function (_a) {
|
|
1764
|
-
var _b = tslib_1.__read(_a, 2), id = _b[0], serviceMap = _b[1];
|
|
1804
|
+
var _b = (0, tslib_1.__read)(_a, 2), id = _b[0], serviceMap = _b[1];
|
|
1765
1805
|
controllers.push({
|
|
1766
1806
|
type: id,
|
|
1767
1807
|
services: Accessory.serializeServiceMap(serviceMap),
|
|
@@ -1798,8 +1838,8 @@ var Accessory = /** @class */ (function (_super) {
|
|
|
1798
1838
|
});
|
|
1799
1839
|
};
|
|
1800
1840
|
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];
|
|
1841
|
+
for (var _b = (0, tslib_1.__values)(Object.entries(json.linkedServices)), _c = _b.next(); !_c.done; _c = _b.next()) {
|
|
1842
|
+
var _d = (0, tslib_1.__read)(_c.value, 2), serviceId = _d[0], linkedServicesKeys = _d[1];
|
|
1803
1843
|
_loop_3(serviceId, linkedServicesKeys);
|
|
1804
1844
|
}
|
|
1805
1845
|
}
|
|
@@ -1828,7 +1868,7 @@ var Accessory = /** @class */ (function (_super) {
|
|
|
1828
1868
|
Accessory.serializeServiceMap = function (serviceMap) {
|
|
1829
1869
|
var serialized = {};
|
|
1830
1870
|
Object.entries(serviceMap).forEach(function (_a) {
|
|
1831
|
-
var _b = tslib_1.__read(_a, 2), name = _b[0], service = _b[1];
|
|
1871
|
+
var _b = (0, tslib_1.__read)(_a, 2), name = _b[0], service = _b[1];
|
|
1832
1872
|
if (!service) {
|
|
1833
1873
|
return;
|
|
1834
1874
|
}
|
|
@@ -1839,7 +1879,7 @@ var Accessory = /** @class */ (function (_super) {
|
|
|
1839
1879
|
Accessory.deserializeServiceMap = function (serializedServiceMap, servicesMap) {
|
|
1840
1880
|
var controllerServiceMap = {};
|
|
1841
1881
|
Object.entries(serializedServiceMap).forEach(function (_a) {
|
|
1842
|
-
var _b = tslib_1.__read(_a, 2), name = _b[0], serviceId = _b[1];
|
|
1882
|
+
var _b = (0, tslib_1.__read)(_a, 2), name = _b[0], serviceId = _b[1];
|
|
1843
1883
|
var service = servicesMap[serviceId];
|
|
1844
1884
|
if (service) {
|
|
1845
1885
|
controllerServiceMap[name] = service;
|
|
@@ -1884,7 +1924,7 @@ var Accessory = /** @class */ (function (_super) {
|
|
|
1884
1924
|
advertiserAddress = Array.from(entries);
|
|
1885
1925
|
var bindUnspecifiedIpv6 = false; // we bind on "::" if there are interface names, or we detect ipv6 addresses
|
|
1886
1926
|
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()) {
|
|
1927
|
+
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
1928
|
var entry = entries_1_1.value;
|
|
1889
1929
|
var version = net_1.default.isIP(entry);
|
|
1890
1930
|
if (version === 0 || version === 6) {
|