hap-nodejs 0.11.0-beta.11 → 0.11.0-beta.13
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +1 -0
- package/dist/accessories/Light_accessory.js +1 -1
- package/dist/accessories/Light_accessory.js.map +1 -1
- package/dist/internal-types.d.ts +47 -3
- package/dist/internal-types.d.ts.map +1 -1
- package/dist/internal-types.js +52 -1
- package/dist/internal-types.js.map +1 -1
- package/dist/lib/Accessory.d.ts +27 -12
- package/dist/lib/Accessory.d.ts.map +1 -1
- package/dist/lib/Accessory.js +159 -191
- package/dist/lib/Accessory.js.map +1 -1
- package/dist/lib/Characteristic.d.ts +2 -1
- package/dist/lib/Characteristic.d.ts.map +1 -1
- package/dist/lib/Characteristic.js +5 -2
- package/dist/lib/Characteristic.js.map +1 -1
- package/dist/lib/HAPServer.d.ts +43 -4
- package/dist/lib/HAPServer.d.ts.map +1 -1
- package/dist/lib/HAPServer.js +78 -101
- package/dist/lib/HAPServer.js.map +1 -1
- package/dist/lib/Service.d.ts +2 -1
- package/dist/lib/Service.d.ts.map +1 -1
- package/dist/lib/Service.js +4 -0
- package/dist/lib/Service.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 +14 -11
- package/dist/lib/camera/RTPStreamManagement.js.map +1 -1
- package/dist/lib/controller/AdaptiveLightingController.d.ts.map +1 -1
- package/dist/lib/controller/AdaptiveLightingController.js +9 -7
- package/dist/lib/controller/AdaptiveLightingController.js.map +1 -1
- package/dist/lib/controller/CameraController.d.ts.map +1 -1
- package/dist/lib/controller/CameraController.js +1 -0
- package/dist/lib/controller/CameraController.js.map +1 -1
- package/dist/lib/controller/RemoteController.js +2 -2
- package/dist/lib/controller/RemoteController.js.map +1 -1
- package/dist/lib/util/HAPHTTPError.d.ts +16 -0
- package/dist/lib/util/HAPHTTPError.d.ts.map +1 -0
- package/dist/lib/util/HAPHTTPError.js +26 -0
- package/dist/lib/util/HAPHTTPError.js.map +1 -0
- package/dist/lib/util/color-utils.d.ts +1 -1
- package/dist/lib/util/color-utils.js +1 -1
- package/dist/lib/util/eventedhttp.d.ts +18 -4
- package/dist/lib/util/eventedhttp.d.ts.map +1 -1
- package/dist/lib/util/eventedhttp.js +83 -88
- package/dist/lib/util/eventedhttp.js.map +1 -1
- package/dist/lib/util/hapCrypto.d.ts +3 -2
- package/dist/lib/util/hapCrypto.d.ts.map +1 -1
- package/dist/lib/util/hapCrypto.js.map +1 -1
- package/dist/lib/util/promise-utils.d.ts +4 -0
- package/dist/lib/util/promise-utils.d.ts.map +1 -1
- package/dist/lib/util/promise-utils.js +24 -1
- package/dist/lib/util/promise-utils.js.map +1 -1
- package/dist/lib/util/time.js +1 -1
- package/dist/lib/util/tlv.d.ts +63 -4
- package/dist/lib/util/tlv.d.ts.map +1 -1
- package/dist/lib/util/tlv.js +61 -16
- package/dist/lib/util/tlv.js.map +1 -1
- package/dist/lib/util/tlvError.d.ts +14 -0
- package/dist/lib/util/tlvError.d.ts.map +1 -0
- package/dist/lib/util/tlvError.js +24 -0
- package/dist/lib/util/tlvError.js.map +1 -0
- package/dist/types.d.ts +4 -0
- package/dist/types.d.ts.map +1 -1
- package/package.json +6 -4
package/dist/lib/Accessory.js
CHANGED
|
@@ -176,7 +176,7 @@ var Accessory = /** @class */ (function (_super) {
|
|
|
176
176
|
_this.lastAccessoriesRequest = 0;
|
|
177
177
|
/**
|
|
178
178
|
* Returns the bridging accessory if this accessory is bridged.
|
|
179
|
-
* Otherwise returns itself.
|
|
179
|
+
* Otherwise, returns itself.
|
|
180
180
|
*
|
|
181
181
|
* @returns the primary accessory
|
|
182
182
|
*/
|
|
@@ -365,27 +365,17 @@ var Accessory = /** @class */ (function (_super) {
|
|
|
365
365
|
debug("Reachability update is no longer being supported.");
|
|
366
366
|
};
|
|
367
367
|
Accessory.prototype.addBridgedAccessory = function (accessory, deferUpdate) {
|
|
368
|
-
var e_5, _a;
|
|
369
368
|
var _this = this;
|
|
370
369
|
if (deferUpdate === void 0) { deferUpdate = false; }
|
|
371
|
-
if (accessory._isBridge) {
|
|
372
|
-
throw new Error("
|
|
370
|
+
if (accessory._isBridge || accessory === this) {
|
|
371
|
+
throw new Error("Illegal state: either trying to bridge a bridge or trying to bridge itself!");
|
|
373
372
|
}
|
|
374
|
-
|
|
375
|
-
|
|
376
|
-
for (var _b = (0, tslib_1.__values)(this.bridgedAccessories), _c = _b.next(); !_c.done; _c = _b.next()) {
|
|
377
|
-
var existing = _c.value;
|
|
378
|
-
if (existing.UUID === accessory.UUID) {
|
|
379
|
-
throw new Error("Cannot add a bridged Accessory with the same UUID as another bridged Accessory: " + existing.UUID);
|
|
380
|
-
}
|
|
381
|
-
}
|
|
373
|
+
if (accessory.initialized) {
|
|
374
|
+
throw new Error("Tried to bridge an accessory which was already published once!");
|
|
382
375
|
}
|
|
383
|
-
|
|
384
|
-
|
|
385
|
-
|
|
386
|
-
if (_c && !_c.done && (_a = _b.return)) _a.call(_b);
|
|
387
|
-
}
|
|
388
|
-
finally { if (e_5) throw e_5.error; }
|
|
376
|
+
if (accessory.bridge != null) {
|
|
377
|
+
// this also prevents that we bridge the same accessory twice!
|
|
378
|
+
throw new Error("Tried to bridge " + accessory.displayName + " while it was already bridged by " + accessory.bridge.displayName);
|
|
389
379
|
}
|
|
390
380
|
if (this.bridgedAccessories.length >= MAX_ACCESSORIES) {
|
|
391
381
|
throw new Error("Cannot Bridge more than " + MAX_ACCESSORIES + " Accessories");
|
|
@@ -404,53 +394,51 @@ var Accessory = /** @class */ (function (_super) {
|
|
|
404
394
|
return accessory;
|
|
405
395
|
};
|
|
406
396
|
Accessory.prototype.addBridgedAccessories = function (accessories) {
|
|
407
|
-
var
|
|
397
|
+
var e_5, _a;
|
|
408
398
|
try {
|
|
409
399
|
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()) {
|
|
410
400
|
var accessory = accessories_1_1.value;
|
|
411
401
|
this.addBridgedAccessory(accessory, true);
|
|
412
402
|
}
|
|
413
403
|
}
|
|
414
|
-
catch (
|
|
404
|
+
catch (e_5_1) { e_5 = { error: e_5_1 }; }
|
|
415
405
|
finally {
|
|
416
406
|
try {
|
|
417
407
|
if (accessories_1_1 && !accessories_1_1.done && (_a = accessories_1.return)) _a.call(accessories_1);
|
|
418
408
|
}
|
|
419
|
-
finally { if (
|
|
409
|
+
finally { if (e_5) throw e_5.error; }
|
|
420
410
|
}
|
|
421
411
|
this.enqueueConfigurationUpdate();
|
|
422
412
|
};
|
|
423
413
|
Accessory.prototype.removeBridgedAccessory = function (accessory, deferUpdate) {
|
|
424
|
-
if (
|
|
425
|
-
throw new Error("Cannot Bridge another Bridge!");
|
|
426
|
-
}
|
|
414
|
+
if (deferUpdate === void 0) { deferUpdate = false; }
|
|
427
415
|
// check for UUID conflict
|
|
428
|
-
var
|
|
429
|
-
|
|
430
|
-
});
|
|
431
|
-
if (foundMatchAccessory === -1) {
|
|
416
|
+
var accessoryIndex = this.bridgedAccessories.indexOf(accessory);
|
|
417
|
+
if (accessoryIndex === -1) {
|
|
432
418
|
throw new Error("Cannot find the bridged Accessory to remove.");
|
|
433
419
|
}
|
|
434
|
-
this.bridgedAccessories.splice(
|
|
420
|
+
this.bridgedAccessories.splice(accessoryIndex, 1);
|
|
421
|
+
accessory.bridged = false;
|
|
422
|
+
accessory.bridge = undefined;
|
|
435
423
|
accessory.removeAllListeners();
|
|
436
424
|
if (!deferUpdate) {
|
|
437
425
|
this.enqueueConfigurationUpdate();
|
|
438
426
|
}
|
|
439
427
|
};
|
|
440
428
|
Accessory.prototype.removeBridgedAccessories = function (accessories) {
|
|
441
|
-
var
|
|
429
|
+
var e_6, _a;
|
|
442
430
|
try {
|
|
443
431
|
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()) {
|
|
444
432
|
var accessory = accessories_2_1.value;
|
|
445
433
|
this.removeBridgedAccessory(accessory, true);
|
|
446
434
|
}
|
|
447
435
|
}
|
|
448
|
-
catch (
|
|
436
|
+
catch (e_6_1) { e_6 = { error: e_6_1 }; }
|
|
449
437
|
finally {
|
|
450
438
|
try {
|
|
451
439
|
if (accessories_2_1 && !accessories_2_1.done && (_a = accessories_2.return)) _a.call(accessories_2);
|
|
452
440
|
}
|
|
453
|
-
finally { if (
|
|
441
|
+
finally { if (e_6) throw e_6.error; }
|
|
454
442
|
}
|
|
455
443
|
this.enqueueConfigurationUpdate();
|
|
456
444
|
};
|
|
@@ -461,7 +449,7 @@ var Accessory = /** @class */ (function (_super) {
|
|
|
461
449
|
this.enqueueConfigurationUpdate();
|
|
462
450
|
};
|
|
463
451
|
Accessory.prototype.getCharacteristicByIID = function (iid) {
|
|
464
|
-
var
|
|
452
|
+
var e_7, _a;
|
|
465
453
|
try {
|
|
466
454
|
for (var _b = (0, tslib_1.__values)(this.services), _c = _b.next(); !_c.done; _c = _b.next()) {
|
|
467
455
|
var service = _c.value;
|
|
@@ -471,35 +459,19 @@ var Accessory = /** @class */ (function (_super) {
|
|
|
471
459
|
}
|
|
472
460
|
}
|
|
473
461
|
}
|
|
474
|
-
catch (
|
|
462
|
+
catch (e_7_1) { e_7 = { error: e_7_1 }; }
|
|
475
463
|
finally {
|
|
476
464
|
try {
|
|
477
465
|
if (_c && !_c.done && (_a = _b.return)) _a.call(_b);
|
|
478
466
|
}
|
|
479
|
-
finally { if (
|
|
467
|
+
finally { if (e_7) throw e_7.error; }
|
|
480
468
|
}
|
|
481
469
|
};
|
|
482
470
|
Accessory.prototype.getAccessoryByAID = function (aid) {
|
|
483
|
-
|
|
484
|
-
if (aid === 1) {
|
|
471
|
+
if (this.aid === aid) {
|
|
485
472
|
return this;
|
|
486
473
|
}
|
|
487
|
-
|
|
488
|
-
for (var _b = (0, tslib_1.__values)(this.bridgedAccessories), _c = _b.next(); !_c.done; _c = _b.next()) {
|
|
489
|
-
var accessory = _c.value;
|
|
490
|
-
if (accessory.aid === aid) {
|
|
491
|
-
return accessory;
|
|
492
|
-
}
|
|
493
|
-
}
|
|
494
|
-
}
|
|
495
|
-
catch (e_9_1) { e_9 = { error: e_9_1 }; }
|
|
496
|
-
finally {
|
|
497
|
-
try {
|
|
498
|
-
if (_c && !_c.done && (_a = _b.return)) _a.call(_b);
|
|
499
|
-
}
|
|
500
|
-
finally { if (e_9) throw e_9.error; }
|
|
501
|
-
}
|
|
502
|
-
return undefined;
|
|
474
|
+
return this.bridgedAccessories.find(function (value) { return value.aid === aid; });
|
|
503
475
|
};
|
|
504
476
|
Accessory.prototype.findCharacteristic = function (aid, iid) {
|
|
505
477
|
var accessory = this.getAccessoryByAID(aid);
|
|
@@ -557,7 +529,7 @@ var Accessory = /** @class */ (function (_super) {
|
|
|
557
529
|
return cameraController; // return the reference for the controller (maybe this could be useful?)
|
|
558
530
|
};
|
|
559
531
|
/**
|
|
560
|
-
* This method is used to
|
|
532
|
+
* This method is used to set up a new Controller for this accessory. See {@see Controller} for a more detailed
|
|
561
533
|
* explanation what a Controller is and what it is capable of.
|
|
562
534
|
*
|
|
563
535
|
* The controller can be passed as an instance of the class or as a constructor (without any necessary parameters)
|
|
@@ -565,7 +537,7 @@ var Accessory = /** @class */ (function (_super) {
|
|
|
565
537
|
* Only one Controller of a given {@link ControllerIdentifier} can be configured for a given Accessory.
|
|
566
538
|
*
|
|
567
539
|
* When called, it will be checked if there are any services and persistent data the Controller (for the given
|
|
568
|
-
* {@link ControllerIdentifier}) can be restored from. Otherwise the Controller will be created with new services.
|
|
540
|
+
* {@link ControllerIdentifier}) can be restored from. Otherwise, the Controller will be created with new services.
|
|
569
541
|
*
|
|
570
542
|
*
|
|
571
543
|
* @param controllerConstructor {Controller | ControllerConstructor}
|
|
@@ -632,7 +604,7 @@ var Accessory = /** @class */ (function (_super) {
|
|
|
632
604
|
if (storedController) {
|
|
633
605
|
if (storedController.controller !== controller) {
|
|
634
606
|
throw new Error("[" + this.displayName + "] tried removing a controller with the id/type '" + id +
|
|
635
|
-
"' though provided controller isn't the same
|
|
607
|
+
"' though provided controller isn't the same instance that is registered!");
|
|
636
608
|
}
|
|
637
609
|
if ((0, controller_1.isSerializableController)(controller)) {
|
|
638
610
|
// this will reset the state change delegate before we call handleControllerRemoved()
|
|
@@ -657,7 +629,7 @@ var Accessory = /** @class */ (function (_super) {
|
|
|
657
629
|
}
|
|
658
630
|
};
|
|
659
631
|
Accessory.prototype.handleAccessoryUnpairedForControllers = function () {
|
|
660
|
-
var
|
|
632
|
+
var e_8, _a;
|
|
661
633
|
try {
|
|
662
634
|
for (var _b = (0, tslib_1.__values)(Object.values(this.controllers)), _c = _b.next(); !_c.done; _c = _b.next()) {
|
|
663
635
|
var context = _c.value;
|
|
@@ -670,12 +642,12 @@ var Accessory = /** @class */ (function (_super) {
|
|
|
670
642
|
}
|
|
671
643
|
}
|
|
672
644
|
}
|
|
673
|
-
catch (
|
|
645
|
+
catch (e_8_1) { e_8 = { error: e_8_1 }; }
|
|
674
646
|
finally {
|
|
675
647
|
try {
|
|
676
648
|
if (_c && !_c.done && (_a = _b.return)) _a.call(_b);
|
|
677
649
|
}
|
|
678
|
-
finally { if (
|
|
650
|
+
finally { if (e_8) throw e_8.error; }
|
|
679
651
|
}
|
|
680
652
|
};
|
|
681
653
|
Accessory.prototype.handleUpdatedControllerServiceMap = function (originalServiceMap, updatedServiceMap) {
|
|
@@ -685,8 +657,8 @@ var Accessory = /** @class */ (function (_super) {
|
|
|
685
657
|
var service = originalServiceMap[name];
|
|
686
658
|
var updatedService = updatedServiceMap[name];
|
|
687
659
|
if (service && updatedService) { // we check all names contained in both ServiceMaps for changes
|
|
688
|
-
delete originalServiceMap[name]; // delete from original ServiceMap so it will only contain deleted services at the end
|
|
689
|
-
delete updatedServiceMap[name]; // delete from updated ServiceMap so it will only contain added services at the end
|
|
660
|
+
delete originalServiceMap[name]; // delete from original ServiceMap, so it will only contain deleted services at the end
|
|
661
|
+
delete updatedServiceMap[name]; // delete from updated ServiceMap, so it will only contain added services at the end
|
|
690
662
|
if (service !== updatedService) {
|
|
691
663
|
_this.removeService(service);
|
|
692
664
|
_this.addService(updatedService);
|
|
@@ -709,17 +681,17 @@ var Accessory = /** @class */ (function (_super) {
|
|
|
709
681
|
if (this._setupURI) {
|
|
710
682
|
return this._setupURI;
|
|
711
683
|
}
|
|
684
|
+
(0, assert_1.default)(!!this._accessoryInfo, "Cannot generate setupURI on an accessory that isn't published yet!");
|
|
712
685
|
var buffer = Buffer.alloc(8);
|
|
713
|
-
var
|
|
714
|
-
var
|
|
715
|
-
var value_high = this._accessoryInfo && this._accessoryInfo.category >> 1;
|
|
686
|
+
var value_low = parseInt(this._accessoryInfo.pincode.replace(/-/g, ""), 10);
|
|
687
|
+
var value_high = this._accessoryInfo.category >> 1;
|
|
716
688
|
value_low |= 1 << 28; // Supports IP;
|
|
717
689
|
buffer.writeUInt32BE(value_low, 4);
|
|
718
|
-
if (this._accessoryInfo
|
|
690
|
+
if (this._accessoryInfo.category & 1) {
|
|
719
691
|
buffer[4] = buffer[4] | 1 << 7;
|
|
720
692
|
}
|
|
721
693
|
buffer.writeUInt32BE(value_high, 0);
|
|
722
|
-
var encodedPayload = (buffer.readUInt32BE(4) + (buffer.readUInt32BE(0) *
|
|
694
|
+
var encodedPayload = (buffer.readUInt32BE(4) + (buffer.readUInt32BE(0) * 0x100000000)).toString(36).toUpperCase();
|
|
723
695
|
if (encodedPayload.length !== 9) {
|
|
724
696
|
for (var i = 0; i <= 9 - encodedPayload.length; i++) {
|
|
725
697
|
encodedPayload = "0" + encodedPayload;
|
|
@@ -771,7 +743,7 @@ var Accessory = /** @class */ (function (_super) {
|
|
|
771
743
|
* the provided identifierCache to keep IDs stable.
|
|
772
744
|
*/
|
|
773
745
|
Accessory.prototype._assignIDs = function (identifierCache) {
|
|
774
|
-
var
|
|
746
|
+
var e_9, _a, e_10, _b;
|
|
775
747
|
// if we are responsible for our own identifierCache, start the expiration process
|
|
776
748
|
// also check weather we want to have an expiration process
|
|
777
749
|
if (this._identifierCache && this.shouldPurgeUnusedIDs) {
|
|
@@ -798,12 +770,12 @@ var Accessory = /** @class */ (function (_super) {
|
|
|
798
770
|
}
|
|
799
771
|
}
|
|
800
772
|
}
|
|
801
|
-
catch (
|
|
773
|
+
catch (e_9_1) { e_9 = { error: e_9_1 }; }
|
|
802
774
|
finally {
|
|
803
775
|
try {
|
|
804
776
|
if (_d && !_d.done && (_a = _c.return)) _a.call(_c);
|
|
805
777
|
}
|
|
806
|
-
finally { if (
|
|
778
|
+
finally { if (e_9) throw e_9.error; }
|
|
807
779
|
}
|
|
808
780
|
try {
|
|
809
781
|
// now assign IDs for any Accessories we are bridging
|
|
@@ -812,12 +784,12 @@ var Accessory = /** @class */ (function (_super) {
|
|
|
812
784
|
accessory._assignIDs(identifierCache);
|
|
813
785
|
}
|
|
814
786
|
}
|
|
815
|
-
catch (
|
|
787
|
+
catch (e_10_1) { e_10 = { error: e_10_1 }; }
|
|
816
788
|
finally {
|
|
817
789
|
try {
|
|
818
790
|
if (_f && !_f.done && (_b = _e.return)) _b.call(_e);
|
|
819
791
|
}
|
|
820
|
-
finally { if (
|
|
792
|
+
finally { if (e_10) throw e_10.error; }
|
|
821
793
|
}
|
|
822
794
|
// expire any now-unused cache keys (for Accessories, Services, or Characteristics
|
|
823
795
|
// that have been removed since the last call to assignIDs())
|
|
@@ -838,7 +810,7 @@ var Accessory = /** @class */ (function (_super) {
|
|
|
838
810
|
};
|
|
839
811
|
/**
|
|
840
812
|
* Manually purge the unused ids if you like, comes handy
|
|
841
|
-
* when you have disabled auto purge so you can do it manually
|
|
813
|
+
* when you have disabled auto purge, so you can do it manually
|
|
842
814
|
*/
|
|
843
815
|
Accessory.prototype.purgeUnusedIDs = function () {
|
|
844
816
|
//Cache the state of the purge mechanism and set it to true
|
|
@@ -888,7 +860,7 @@ var Accessory = /** @class */ (function (_super) {
|
|
|
888
860
|
* Returns a JSON representation of this accessory without characteristic values.
|
|
889
861
|
*/
|
|
890
862
|
Accessory.prototype.internalHAPRepresentation = function (assignIds) {
|
|
891
|
-
var
|
|
863
|
+
var e_11, _a;
|
|
892
864
|
if (assignIds === void 0) { assignIds = true; }
|
|
893
865
|
if (assignIds) {
|
|
894
866
|
this._assignIDs(this._identifierCache); // make sure our aid/iid's are all assigned
|
|
@@ -907,12 +879,12 @@ var Accessory = /** @class */ (function (_super) {
|
|
|
907
879
|
accessories.push(accessory_1.internalHAPRepresentation(false)[0]);
|
|
908
880
|
}
|
|
909
881
|
}
|
|
910
|
-
catch (
|
|
882
|
+
catch (e_11_1) { e_11 = { error: e_11_1 }; }
|
|
911
883
|
finally {
|
|
912
884
|
try {
|
|
913
885
|
if (_c && !_c.done && (_a = _b.return)) _a.call(_b);
|
|
914
886
|
}
|
|
915
|
-
finally { if (
|
|
887
|
+
finally { if (e_11) throw e_11.error; }
|
|
916
888
|
}
|
|
917
889
|
}
|
|
918
890
|
return accessories;
|
|
@@ -932,13 +904,16 @@ var Accessory = /** @class */ (function (_super) {
|
|
|
932
904
|
* new Accessory.
|
|
933
905
|
*/
|
|
934
906
|
Accessory.prototype.publish = function (info, allowInsecureRequest) {
|
|
935
|
-
var _a, _b;
|
|
907
|
+
var _a, _b, _c;
|
|
936
908
|
return (0, tslib_1.__awaiter)(this, void 0, void 0, function () {
|
|
937
|
-
var service, config, parsed, selectedAdvertiser,
|
|
909
|
+
var service, config, parsed, selectedAdvertiser, _d, _e, _f;
|
|
938
910
|
var _this = this;
|
|
939
|
-
return (0, tslib_1.__generator)(this, function (
|
|
940
|
-
switch (
|
|
911
|
+
return (0, tslib_1.__generator)(this, function (_g) {
|
|
912
|
+
switch (_g.label) {
|
|
941
913
|
case 0:
|
|
914
|
+
if (this.bridged) {
|
|
915
|
+
throw new Error("Can't publish in accessory which is bridged by another accessory. Bridged by " + ((_a = this.bridge) === null || _a === void 0 ? void 0 : _a.displayName));
|
|
916
|
+
}
|
|
942
917
|
// noinspection JSDeprecatedSymbols
|
|
943
918
|
if (!info.advertiser && info.useLegacyAdvertiser != null) {
|
|
944
919
|
// noinspection JSDeprecatedSymbols
|
|
@@ -960,8 +935,8 @@ var Accessory = /** @class */ (function (_super) {
|
|
|
960
935
|
if (this.lastKnownUsername && this.lastKnownUsername !== info.username) { // username changed since last publish
|
|
961
936
|
Accessory.cleanupAccessoryData(this.lastKnownUsername); // delete old Accessory data
|
|
962
937
|
}
|
|
963
|
-
if (!this.initialized && ((
|
|
964
|
-
// adding some identifying material to our displayName if
|
|
938
|
+
if (!this.initialized && ((_b = info.addIdentifyingMaterial) !== null && _b !== void 0 ? _b : true)) {
|
|
939
|
+
// adding some identifying material to our displayName if it's our first publish() call
|
|
965
940
|
this.displayName = this.displayName + " " + crypto_1.default.createHash("sha512")
|
|
966
941
|
.update(info.username, "utf8")
|
|
967
942
|
.digest("hex").slice(0, 4).toUpperCase();
|
|
@@ -990,17 +965,17 @@ var Accessory = /** @class */ (function (_super) {
|
|
|
990
965
|
this._accessoryInfo.category = info.category || 1 /* OTHER */;
|
|
991
966
|
this._accessoryInfo.pincode = info.pincode;
|
|
992
967
|
this._accessoryInfo.save();
|
|
993
|
-
// create our IdentifierCache so we can provide clients with stable aid/iid's
|
|
968
|
+
// create our IdentifierCache, so we can provide clients with stable aid/iid's
|
|
994
969
|
this._identifierCache = IdentifierCache_1.IdentifierCache.load(info.username);
|
|
995
970
|
// if we don't have one, create a new one.
|
|
996
971
|
if (!this._identifierCache) {
|
|
997
972
|
debug("[%s] Creating new IdentifierCache", this.displayName);
|
|
998
973
|
this._identifierCache = new IdentifierCache_1.IdentifierCache(info.username);
|
|
999
974
|
}
|
|
1000
|
-
//If it's bridge and there are
|
|
1001
|
-
//probably purge is not needed since it's going to delete all the ids
|
|
1002
|
-
//of accessories that might be added later. Useful when dynamically adding
|
|
1003
|
-
//accessories.
|
|
975
|
+
// If it's bridge and there are no accessories already assigned to the bridge
|
|
976
|
+
// probably purge is not needed since it's going to delete all the ids
|
|
977
|
+
// of accessories that might be added later. Useful when dynamically adding
|
|
978
|
+
// accessories.
|
|
1004
979
|
if (this._isBridge && this.bridgedAccessories.length === 0) {
|
|
1005
980
|
this.disableUnusedIDPurge();
|
|
1006
981
|
this.controllerStorage.purgeUnidentifiedAccessoryData = false;
|
|
@@ -1016,27 +991,27 @@ var Accessory = /** @class */ (function (_super) {
|
|
|
1016
991
|
this._accessoryInfo.checkForCurrentConfigurationNumberIncrement(config, true);
|
|
1017
992
|
this.validateAccessory(true);
|
|
1018
993
|
parsed = Accessory.parseBindOption(info);
|
|
1019
|
-
selectedAdvertiser = (
|
|
1020
|
-
|
|
1021
|
-
if (!
|
|
994
|
+
selectedAdvertiser = (_c = info.advertiser) !== null && _c !== void 0 ? _c : "bonjour-hap" /* BONJOUR */;
|
|
995
|
+
_e = info.advertiser === "avahi" /* AVAHI */;
|
|
996
|
+
if (!_e) return [3 /*break*/, 2];
|
|
1022
997
|
return [4 /*yield*/, Advertiser_1.AvahiAdvertiser.isAvailable()];
|
|
1023
998
|
case 1:
|
|
1024
|
-
|
|
1025
|
-
|
|
999
|
+
_e = !(_g.sent());
|
|
1000
|
+
_g.label = 2;
|
|
1026
1001
|
case 2:
|
|
1027
|
-
|
|
1028
|
-
if (
|
|
1029
|
-
|
|
1030
|
-
if (!
|
|
1002
|
+
_d = (_e);
|
|
1003
|
+
if (_d) return [3 /*break*/, 5];
|
|
1004
|
+
_f = info.advertiser === "resolved" /* RESOLVED */;
|
|
1005
|
+
if (!_f) return [3 /*break*/, 4];
|
|
1031
1006
|
return [4 /*yield*/, Advertiser_1.ResolvedAdvertiser.isAvailable()];
|
|
1032
1007
|
case 3:
|
|
1033
|
-
|
|
1034
|
-
|
|
1008
|
+
_f = !(_g.sent());
|
|
1009
|
+
_g.label = 4;
|
|
1035
1010
|
case 4:
|
|
1036
|
-
|
|
1037
|
-
|
|
1011
|
+
_d = (_f);
|
|
1012
|
+
_g.label = 5;
|
|
1038
1013
|
case 5:
|
|
1039
|
-
if (
|
|
1014
|
+
if (_d) {
|
|
1040
1015
|
console.error("[".concat(this.displayName, "] The selected advertiser, \"").concat(info.advertiser, "\", isn't available on this platform. ") +
|
|
1041
1016
|
"Reverting to \"".concat("bonjour-hap" /* BONJOUR */, "\""));
|
|
1042
1017
|
selectedAdvertiser = "bonjour-hap" /* BONJOUR */;
|
|
@@ -1154,8 +1129,8 @@ var Accessory = /** @class */ (function (_super) {
|
|
|
1154
1129
|
}
|
|
1155
1130
|
}, 1000);
|
|
1156
1131
|
this.configurationChangeDebounceTimeout.unref();
|
|
1157
|
-
//
|
|
1158
|
-
// Thus the only thing happening when the txt update arrives late is already removed accessories/services
|
|
1132
|
+
// 1s is fine, HomeKit is built that with configuration updates no iid or aid conflicts occur.
|
|
1133
|
+
// Thus, the only thing happening when the txt update arrives late is already removed accessories/services
|
|
1159
1134
|
// not responding or new accessories/services not yet shown
|
|
1160
1135
|
};
|
|
1161
1136
|
Accessory.prototype.onListening = function (port, hostname) {
|
|
@@ -1172,7 +1147,7 @@ var Accessory = /** @class */ (function (_super) {
|
|
|
1172
1147
|
debug("[%s] Paired with client %s", this.displayName, username);
|
|
1173
1148
|
this._accessoryInfo && this._accessoryInfo.addPairedClient(username, publicKey, 1 /* ADMIN */);
|
|
1174
1149
|
this._accessoryInfo && this._accessoryInfo.save();
|
|
1175
|
-
// update our advertisement so it can pick up on the paired status of AccessoryInfo
|
|
1150
|
+
// update our advertisement, so it can pick up on the paired status of AccessoryInfo
|
|
1176
1151
|
this._advertiser && this._advertiser.updateAdvertisement();
|
|
1177
1152
|
callback();
|
|
1178
1153
|
this.emit("paired" /* PAIRED */);
|
|
@@ -1202,7 +1177,7 @@ var Accessory = /** @class */ (function (_super) {
|
|
|
1202
1177
|
callback(0);
|
|
1203
1178
|
};
|
|
1204
1179
|
Accessory.prototype.handleRemovePairing = function (connection, username, callback) {
|
|
1205
|
-
var
|
|
1180
|
+
var e_12, _a;
|
|
1206
1181
|
if (!this._accessoryInfo) {
|
|
1207
1182
|
callback(6 /* UNAVAILABLE */);
|
|
1208
1183
|
return;
|
|
@@ -1224,12 +1199,12 @@ var Accessory = /** @class */ (function (_super) {
|
|
|
1224
1199
|
accessory.handleAccessoryUnpairedForControllers();
|
|
1225
1200
|
}
|
|
1226
1201
|
}
|
|
1227
|
-
catch (
|
|
1202
|
+
catch (e_12_1) { e_12 = { error: e_12_1 }; }
|
|
1228
1203
|
finally {
|
|
1229
1204
|
try {
|
|
1230
1205
|
if (_c && !_c.done && (_a = _b.return)) _a.call(_b);
|
|
1231
1206
|
}
|
|
1232
|
-
finally { if (
|
|
1207
|
+
finally { if (e_12) throw e_12.error; }
|
|
1233
1208
|
}
|
|
1234
1209
|
}
|
|
1235
1210
|
};
|
|
@@ -1248,7 +1223,7 @@ var Accessory = /** @class */ (function (_super) {
|
|
|
1248
1223
|
var _this = this;
|
|
1249
1224
|
this._assignIDs(this._identifierCache); // make sure our aid/iid's are all assigned
|
|
1250
1225
|
var now = Date.now();
|
|
1251
|
-
var contactGetHandlers = now - this.lastAccessoriesRequest > 5000; // we query latest value if last /accessories was more than 5s ago
|
|
1226
|
+
var contactGetHandlers = now - this.lastAccessoriesRequest > 5000; // we query the latest value if last /accessories was more than 5s ago
|
|
1252
1227
|
this.lastAccessoriesRequest = now;
|
|
1253
1228
|
this.toHAP(connection, contactGetHandlers).then(function (value) {
|
|
1254
1229
|
callback(undefined, {
|
|
@@ -1260,7 +1235,7 @@ var Accessory = /** @class */ (function (_super) {
|
|
|
1260
1235
|
});
|
|
1261
1236
|
};
|
|
1262
1237
|
Accessory.prototype.handleGetCharacteristics = function (connection, request, callback) {
|
|
1263
|
-
var
|
|
1238
|
+
var e_13, _a;
|
|
1264
1239
|
var _this = this;
|
|
1265
1240
|
var characteristics = [];
|
|
1266
1241
|
var response = { characteristics: characteristics };
|
|
@@ -1271,7 +1246,7 @@ var Accessory = /** @class */ (function (_super) {
|
|
|
1271
1246
|
return;
|
|
1272
1247
|
}
|
|
1273
1248
|
var timeout = setTimeout(function () {
|
|
1274
|
-
var
|
|
1249
|
+
var e_14, _a;
|
|
1275
1250
|
try {
|
|
1276
1251
|
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()) {
|
|
1277
1252
|
var id = missingCharacteristics_1_1.value;
|
|
@@ -1284,16 +1259,16 @@ var Accessory = /** @class */ (function (_super) {
|
|
|
1284
1259
|
characteristic.displayName + "' on the accessory '" + accessory.displayName + "' was slow to respond!");
|
|
1285
1260
|
}
|
|
1286
1261
|
}
|
|
1287
|
-
catch (
|
|
1262
|
+
catch (e_14_1) { e_14 = { error: e_14_1 }; }
|
|
1288
1263
|
finally {
|
|
1289
1264
|
try {
|
|
1290
1265
|
if (missingCharacteristics_1_1 && !missingCharacteristics_1_1.done && (_a = missingCharacteristics_1.return)) _a.call(missingCharacteristics_1);
|
|
1291
1266
|
}
|
|
1292
|
-
finally { if (
|
|
1267
|
+
finally { if (e_14) throw e_14.error; }
|
|
1293
1268
|
}
|
|
1294
|
-
// after a total of 10s we do
|
|
1269
|
+
// after a total of 10s we do no longer wait for a request to appear and just return status code timeout
|
|
1295
1270
|
timeout = setTimeout(function () {
|
|
1296
|
-
var
|
|
1271
|
+
var e_15, _a;
|
|
1297
1272
|
timeout = undefined;
|
|
1298
1273
|
try {
|
|
1299
1274
|
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()) {
|
|
@@ -1313,18 +1288,18 @@ var Accessory = /** @class */ (function (_super) {
|
|
|
1313
1288
|
});
|
|
1314
1289
|
}
|
|
1315
1290
|
}
|
|
1316
|
-
catch (
|
|
1291
|
+
catch (e_15_1) { e_15 = { error: e_15_1 }; }
|
|
1317
1292
|
finally {
|
|
1318
1293
|
try {
|
|
1319
1294
|
if (missingCharacteristics_2_1 && !missingCharacteristics_2_1.done && (_a = missingCharacteristics_2.return)) _a.call(missingCharacteristics_2);
|
|
1320
1295
|
}
|
|
1321
|
-
finally { if (
|
|
1296
|
+
finally { if (e_15) throw e_15.error; }
|
|
1322
1297
|
}
|
|
1323
1298
|
missingCharacteristics.clear();
|
|
1324
1299
|
callback(undefined, response);
|
|
1325
|
-
},
|
|
1300
|
+
}, Accessory.TIMEOUT_AFTER_WARNING);
|
|
1326
1301
|
timeout.unref();
|
|
1327
|
-
},
|
|
1302
|
+
}, Accessory.TIMEOUT_WARNING);
|
|
1328
1303
|
timeout.unref();
|
|
1329
1304
|
var _loop_1 = function (id) {
|
|
1330
1305
|
var name = id.aid + "." + id.iid;
|
|
@@ -1359,12 +1334,12 @@ var Accessory = /** @class */ (function (_super) {
|
|
|
1359
1334
|
_loop_1(id);
|
|
1360
1335
|
}
|
|
1361
1336
|
}
|
|
1362
|
-
catch (
|
|
1337
|
+
catch (e_13_1) { e_13 = { error: e_13_1 }; }
|
|
1363
1338
|
finally {
|
|
1364
1339
|
try {
|
|
1365
1340
|
if (_c && !_c.done && (_a = _b.return)) _a.call(_b);
|
|
1366
1341
|
}
|
|
1367
|
-
finally { if (
|
|
1342
|
+
finally { if (e_13) throw e_13.error; }
|
|
1368
1343
|
}
|
|
1369
1344
|
};
|
|
1370
1345
|
Accessory.prototype.handleCharacteristicRead = function (connection, id, request) {
|
|
@@ -1382,9 +1357,8 @@ var Accessory = /** @class */ (function (_super) {
|
|
|
1382
1357
|
return [2 /*return*/, { status: -70405 /* WRITE_ONLY_CHARACTERISTIC */ }];
|
|
1383
1358
|
}
|
|
1384
1359
|
if (characteristic.props.adminOnlyAccess && characteristic.props.adminOnlyAccess.includes(0 /* READ */)) {
|
|
1385
|
-
verifiable =
|
|
1386
|
-
if (!
|
|
1387
|
-
verifiable = false;
|
|
1360
|
+
verifiable = this._accessoryInfo && connection.username;
|
|
1361
|
+
if (!verifiable) {
|
|
1388
1362
|
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);
|
|
1389
1363
|
}
|
|
1390
1364
|
if (!verifiable || !this._accessoryInfo.hasAdminPermissions(connection.username)) {
|
|
@@ -1409,14 +1383,14 @@ var Accessory = /** @class */ (function (_super) {
|
|
|
1409
1383
|
data.perms = characteristic.props.perms;
|
|
1410
1384
|
}
|
|
1411
1385
|
if (request.includeType) {
|
|
1412
|
-
data.type = (0, uuid_1.toShortForm)(
|
|
1386
|
+
data.type = (0, uuid_1.toShortForm)(characteristic.UUID);
|
|
1413
1387
|
}
|
|
1414
1388
|
if (request.includeEvent) {
|
|
1415
1389
|
data.ev = connection.hasEventNotifications(id.aid, id.iid);
|
|
1416
1390
|
}
|
|
1417
1391
|
return data;
|
|
1418
1392
|
}, function (reason) {
|
|
1419
|
-
// @ts-expect-error:
|
|
1393
|
+
// @ts-expect-error: preserveConstEnums compiler option
|
|
1420
1394
|
debug("[%s] Error getting value for characteristic \"%s\": %s", _this.displayName, characteristic.displayName, HAPServer_1.HAPStatus[reason]);
|
|
1421
1395
|
return { status: reason };
|
|
1422
1396
|
})];
|
|
@@ -1424,7 +1398,7 @@ var Accessory = /** @class */ (function (_super) {
|
|
|
1424
1398
|
});
|
|
1425
1399
|
};
|
|
1426
1400
|
Accessory.prototype.handleSetCharacteristics = function (connection, writeRequest, callback) {
|
|
1427
|
-
var
|
|
1401
|
+
var e_16, _a;
|
|
1428
1402
|
var _this = this;
|
|
1429
1403
|
debug("[%s] Processing characteristic set: %s", this.displayName, JSON.stringify(writeRequest));
|
|
1430
1404
|
var writeState = 0 /* REGULAR_REQUEST */;
|
|
@@ -1451,7 +1425,7 @@ var Accessory = /** @class */ (function (_super) {
|
|
|
1451
1425
|
return;
|
|
1452
1426
|
}
|
|
1453
1427
|
var timeout = setTimeout(function () {
|
|
1454
|
-
var
|
|
1428
|
+
var e_17, _a;
|
|
1455
1429
|
try {
|
|
1456
1430
|
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()) {
|
|
1457
1431
|
var id = missingCharacteristics_3_1.value;
|
|
@@ -1464,16 +1438,16 @@ var Accessory = /** @class */ (function (_super) {
|
|
|
1464
1438
|
characteristic.displayName + "' on the accessory '" + accessory.displayName + "' was slow to respond!");
|
|
1465
1439
|
}
|
|
1466
1440
|
}
|
|
1467
|
-
catch (
|
|
1441
|
+
catch (e_17_1) { e_17 = { error: e_17_1 }; }
|
|
1468
1442
|
finally {
|
|
1469
1443
|
try {
|
|
1470
1444
|
if (missingCharacteristics_3_1 && !missingCharacteristics_3_1.done && (_a = missingCharacteristics_3.return)) _a.call(missingCharacteristics_3);
|
|
1471
1445
|
}
|
|
1472
|
-
finally { if (
|
|
1446
|
+
finally { if (e_17) throw e_17.error; }
|
|
1473
1447
|
}
|
|
1474
|
-
// after a total of 10s we do
|
|
1448
|
+
// after a total of 10s we do no longer wait for a request to appear and just return status code timeout
|
|
1475
1449
|
timeout = setTimeout(function () {
|
|
1476
|
-
var
|
|
1450
|
+
var e_18, _a;
|
|
1477
1451
|
timeout = undefined;
|
|
1478
1452
|
try {
|
|
1479
1453
|
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()) {
|
|
@@ -1493,18 +1467,18 @@ var Accessory = /** @class */ (function (_super) {
|
|
|
1493
1467
|
});
|
|
1494
1468
|
}
|
|
1495
1469
|
}
|
|
1496
|
-
catch (
|
|
1470
|
+
catch (e_18_1) { e_18 = { error: e_18_1 }; }
|
|
1497
1471
|
finally {
|
|
1498
1472
|
try {
|
|
1499
1473
|
if (missingCharacteristics_4_1 && !missingCharacteristics_4_1.done && (_a = missingCharacteristics_4.return)) _a.call(missingCharacteristics_4);
|
|
1500
1474
|
}
|
|
1501
|
-
finally { if (
|
|
1475
|
+
finally { if (e_18) throw e_18.error; }
|
|
1502
1476
|
}
|
|
1503
1477
|
missingCharacteristics.clear();
|
|
1504
1478
|
callback(undefined, response);
|
|
1505
|
-
},
|
|
1479
|
+
}, Accessory.TIMEOUT_AFTER_WARNING);
|
|
1506
1480
|
timeout.unref();
|
|
1507
|
-
},
|
|
1481
|
+
}, Accessory.TIMEOUT_WARNING);
|
|
1508
1482
|
timeout.unref();
|
|
1509
1483
|
var _loop_2 = function (data) {
|
|
1510
1484
|
var name = data.aid + "." + data.iid;
|
|
@@ -1539,21 +1513,20 @@ var Accessory = /** @class */ (function (_super) {
|
|
|
1539
1513
|
_loop_2(data);
|
|
1540
1514
|
}
|
|
1541
1515
|
}
|
|
1542
|
-
catch (
|
|
1516
|
+
catch (e_16_1) { e_16 = { error: e_16_1 }; }
|
|
1543
1517
|
finally {
|
|
1544
1518
|
try {
|
|
1545
1519
|
if (_c && !_c.done && (_a = _b.return)) _a.call(_b);
|
|
1546
1520
|
}
|
|
1547
|
-
finally { if (
|
|
1521
|
+
finally { if (e_16) throw e_16.error; }
|
|
1548
1522
|
}
|
|
1549
1523
|
};
|
|
1550
1524
|
Accessory.prototype.handleCharacteristicWrite = function (connection, data, writeState) {
|
|
1551
1525
|
return (0, tslib_1.__awaiter)(this, void 0, void 0, function () {
|
|
1552
|
-
var characteristic,
|
|
1526
|
+
var characteristic, verifiable, notificationsEnabled, verifiable, allowWrite;
|
|
1553
1527
|
var _this = this;
|
|
1554
1528
|
return (0, tslib_1.__generator)(this, function (_a) {
|
|
1555
1529
|
characteristic = this.findCharacteristic(data.aid, data.iid);
|
|
1556
|
-
evResponse = undefined;
|
|
1557
1530
|
if (!characteristic) {
|
|
1558
1531
|
debug("[%s] Could not find a Characteristic with aid of %s and iid of %s", this.displayName, data.aid, data.iid);
|
|
1559
1532
|
return [2 /*return*/, { status: -70410 /* INVALID_VALUE_IN_REQUEST */ }];
|
|
@@ -1561,39 +1534,34 @@ var Accessory = /** @class */ (function (_super) {
|
|
|
1561
1534
|
if (writeState === 2 /* TIMED_WRITE_REJECTED */) {
|
|
1562
1535
|
return [2 /*return*/, { status: -70410 /* INVALID_VALUE_IN_REQUEST */ }];
|
|
1563
1536
|
}
|
|
1537
|
+
if (data.ev == null && data.value == null) {
|
|
1538
|
+
return [2 /*return*/, { status: -70410 /* INVALID_VALUE_IN_REQUEST */ }];
|
|
1539
|
+
}
|
|
1564
1540
|
if (data.ev != null) { // register/unregister event notifications
|
|
1565
|
-
|
|
1566
|
-
|
|
1567
|
-
|
|
1568
|
-
|
|
1569
|
-
|
|
1570
|
-
|
|
1571
|
-
|
|
1572
|
-
|
|
1573
|
-
if (characteristic.props.adminOnlyAccess && characteristic.props.adminOnlyAccess.includes(2 /* NOTIFY */)) {
|
|
1574
|
-
verifiable = true;
|
|
1575
|
-
if (!connection.username || !this._accessoryInfo) {
|
|
1576
|
-
verifiable = false;
|
|
1577
|
-
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);
|
|
1578
|
-
}
|
|
1579
|
-
if (!verifiable || !this._accessoryInfo.hasAdminPermissions(connection.username)) {
|
|
1580
|
-
return [2 /*return*/, { status: -70401 /* INSUFFICIENT_PRIVILEGES */ }];
|
|
1581
|
-
}
|
|
1582
|
-
}
|
|
1583
|
-
// we already checked that data.ev != notificationsEnabled, thus just do whatever the connection asks for
|
|
1584
|
-
if (data.ev) {
|
|
1585
|
-
connection.enableEventNotifications(data.aid, data.iid);
|
|
1586
|
-
characteristic.subscribe();
|
|
1587
|
-
evResponse = true;
|
|
1588
|
-
debug("[%s] Registered Characteristic \"%s\" on \"%s\" for events", connection.remoteAddress, characteristic.displayName, this.displayName);
|
|
1541
|
+
if (!characteristic.props.perms.includes("ev" /* NOTIFY */)) { // check if notify is allowed for this characteristic
|
|
1542
|
+
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);
|
|
1543
|
+
return [2 /*return*/, { status: -70406 /* NOTIFICATION_NOT_SUPPORTED */ }];
|
|
1544
|
+
}
|
|
1545
|
+
if (characteristic.props.adminOnlyAccess && characteristic.props.adminOnlyAccess.includes(2 /* NOTIFY */)) {
|
|
1546
|
+
verifiable = connection.username && this._accessoryInfo;
|
|
1547
|
+
if (!verifiable) {
|
|
1548
|
+
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);
|
|
1589
1549
|
}
|
|
1590
|
-
|
|
1591
|
-
|
|
1592
|
-
connection.disableEventNotifications(data.aid, data.iid);
|
|
1593
|
-
evResponse = false;
|
|
1594
|
-
debug("[%s] Unregistered Characteristic \"%s\" on \"%s\" for events", connection.remoteAddress, characteristic.displayName, this.displayName);
|
|
1550
|
+
if (!verifiable || !this._accessoryInfo.hasAdminPermissions(connection.username)) {
|
|
1551
|
+
return [2 /*return*/, { status: -70401 /* INSUFFICIENT_PRIVILEGES */ }];
|
|
1595
1552
|
}
|
|
1596
1553
|
}
|
|
1554
|
+
notificationsEnabled = connection.hasEventNotifications(data.aid, data.iid);
|
|
1555
|
+
if (data.ev && !notificationsEnabled) {
|
|
1556
|
+
connection.enableEventNotifications(data.aid, data.iid);
|
|
1557
|
+
characteristic.subscribe();
|
|
1558
|
+
debug("[%s] Registered Characteristic \"%s\" on \"%s\" for events", connection.remoteAddress, characteristic.displayName, this.displayName);
|
|
1559
|
+
}
|
|
1560
|
+
else if (!data.ev && notificationsEnabled) {
|
|
1561
|
+
characteristic.unsubscribe();
|
|
1562
|
+
connection.disableEventNotifications(data.aid, data.iid);
|
|
1563
|
+
debug("[%s] Unregistered Characteristic \"%s\" on \"%s\" for events", connection.remoteAddress, characteristic.displayName, this.displayName);
|
|
1564
|
+
}
|
|
1597
1565
|
// response is returned below in the else block
|
|
1598
1566
|
}
|
|
1599
1567
|
if (data.value != null) {
|
|
@@ -1602,9 +1570,8 @@ var Accessory = /** @class */ (function (_super) {
|
|
|
1602
1570
|
return [2 /*return*/, { status: -70404 /* READ_ONLY_CHARACTERISTIC */ }];
|
|
1603
1571
|
}
|
|
1604
1572
|
if (characteristic.props.adminOnlyAccess && characteristic.props.adminOnlyAccess.includes(1 /* WRITE */)) {
|
|
1605
|
-
verifiable =
|
|
1606
|
-
if (!
|
|
1607
|
-
verifiable = false;
|
|
1573
|
+
verifiable = connection.username && this._accessoryInfo;
|
|
1574
|
+
if (!verifiable) {
|
|
1608
1575
|
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);
|
|
1609
1576
|
}
|
|
1610
1577
|
if (!verifiable || !this._accessoryInfo.hasAdminPermissions(connection.username)) {
|
|
@@ -1633,7 +1600,7 @@ var Accessory = /** @class */ (function (_super) {
|
|
|
1633
1600
|
return {
|
|
1634
1601
|
// if write response is requests and value is provided, return that
|
|
1635
1602
|
value: data.r && value ? (0, request_util_1.formatOutgoingCharacteristicValue)(value, characteristic.props) : undefined,
|
|
1636
|
-
|
|
1603
|
+
status: 0 /* SUCCESS */,
|
|
1637
1604
|
};
|
|
1638
1605
|
}, function (status) {
|
|
1639
1606
|
// @ts-expect-error: forceConsistentCasingInFileNames compiler option
|
|
@@ -1641,10 +1608,7 @@ var Accessory = /** @class */ (function (_super) {
|
|
|
1641
1608
|
return { status: status };
|
|
1642
1609
|
})];
|
|
1643
1610
|
}
|
|
1644
|
-
|
|
1645
|
-
return [2 /*return*/, { ev: evResponse }];
|
|
1646
|
-
}
|
|
1647
|
-
return [2 /*return*/];
|
|
1611
|
+
return [2 /*return*/, { status: 0 /* SUCCESS */ }];
|
|
1648
1612
|
});
|
|
1649
1613
|
});
|
|
1650
1614
|
};
|
|
@@ -1682,7 +1646,7 @@ var Accessory = /** @class */ (function (_super) {
|
|
|
1682
1646
|
callback({ httpCode: 404 /* NOT_FOUND */, status: -70409 /* RESOURCE_DOES_NOT_EXIST */ });
|
|
1683
1647
|
};
|
|
1684
1648
|
Accessory.prototype.handleHAPConnectionClosed = function (connection) {
|
|
1685
|
-
var
|
|
1649
|
+
var e_19, _a;
|
|
1686
1650
|
if (this.activeCameraController) {
|
|
1687
1651
|
this.activeCameraController.handleCloseConnection(connection.sessionID);
|
|
1688
1652
|
}
|
|
@@ -1698,22 +1662,22 @@ var Accessory = /** @class */ (function (_super) {
|
|
|
1698
1662
|
}
|
|
1699
1663
|
}
|
|
1700
1664
|
}
|
|
1701
|
-
catch (
|
|
1665
|
+
catch (e_19_1) { e_19 = { error: e_19_1 }; }
|
|
1702
1666
|
finally {
|
|
1703
1667
|
try {
|
|
1704
1668
|
if (_c && !_c.done && (_a = _b.return)) _a.call(_b);
|
|
1705
1669
|
}
|
|
1706
|
-
finally { if (
|
|
1670
|
+
finally { if (e_19) throw e_19.error; }
|
|
1707
1671
|
}
|
|
1708
1672
|
connection.clearRegisteredEvents();
|
|
1709
1673
|
};
|
|
1710
1674
|
Accessory.prototype.handleServiceConfigurationChangeEvent = function (service) {
|
|
1711
1675
|
if (!service.isPrimaryService && service === this.primaryService) {
|
|
1712
|
-
// service changed form primary to non
|
|
1676
|
+
// service changed form primary to non-primary service
|
|
1713
1677
|
this.primaryService = undefined;
|
|
1714
1678
|
}
|
|
1715
1679
|
else if (service.isPrimaryService && service !== this.primaryService) {
|
|
1716
|
-
// service changed from non
|
|
1680
|
+
// service changed from non-primary to primary service
|
|
1717
1681
|
if (this.primaryService !== undefined) {
|
|
1718
1682
|
this.primaryService.isPrimaryService = false;
|
|
1719
1683
|
}
|
|
@@ -1789,7 +1753,7 @@ var Accessory = /** @class */ (function (_super) {
|
|
|
1789
1753
|
service.on("characteristic-warning" /* CHARACTERISTIC_WARNING */, this.handleCharacteristicWarning.bind(this));
|
|
1790
1754
|
};
|
|
1791
1755
|
Accessory.prototype._sideloadServices = function (targetServices) {
|
|
1792
|
-
var
|
|
1756
|
+
var e_20, _a;
|
|
1793
1757
|
var _this = this;
|
|
1794
1758
|
try {
|
|
1795
1759
|
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()) {
|
|
@@ -1797,12 +1761,12 @@ var Accessory = /** @class */ (function (_super) {
|
|
|
1797
1761
|
this.setupServiceEventHandlers(service);
|
|
1798
1762
|
}
|
|
1799
1763
|
}
|
|
1800
|
-
catch (
|
|
1764
|
+
catch (e_20_1) { e_20 = { error: e_20_1 }; }
|
|
1801
1765
|
finally {
|
|
1802
1766
|
try {
|
|
1803
1767
|
if (targetServices_1_1 && !targetServices_1_1.done && (_a = targetServices_1.return)) _a.call(targetServices_1);
|
|
1804
1768
|
}
|
|
1805
|
-
finally { if (
|
|
1769
|
+
finally { if (e_20) throw e_20.error; }
|
|
1806
1770
|
}
|
|
1807
1771
|
this.services = targetServices.slice();
|
|
1808
1772
|
// Fix Identify
|
|
@@ -1873,7 +1837,7 @@ var Accessory = /** @class */ (function (_super) {
|
|
|
1873
1837
|
return json;
|
|
1874
1838
|
};
|
|
1875
1839
|
Accessory.deserialize = function (json) {
|
|
1876
|
-
var
|
|
1840
|
+
var e_21, _a;
|
|
1877
1841
|
var accessory = new Accessory(json.displayName, json.UUID);
|
|
1878
1842
|
accessory.lastKnownUsername = json.lastKnownUsername;
|
|
1879
1843
|
accessory.category = json.category;
|
|
@@ -1903,12 +1867,12 @@ var Accessory = /** @class */ (function (_super) {
|
|
|
1903
1867
|
_loop_3(serviceId, linkedServicesKeys);
|
|
1904
1868
|
}
|
|
1905
1869
|
}
|
|
1906
|
-
catch (
|
|
1870
|
+
catch (e_21_1) { e_21 = { error: e_21_1 }; }
|
|
1907
1871
|
finally {
|
|
1908
1872
|
try {
|
|
1909
1873
|
if (_c && !_c.done && (_a = _b.return)) _a.call(_b);
|
|
1910
1874
|
}
|
|
1911
|
-
finally { if (
|
|
1875
|
+
finally { if (e_21) throw e_21.error; }
|
|
1912
1876
|
}
|
|
1913
1877
|
}
|
|
1914
1878
|
if (json.controllers) { // just save it for later if it exists {@see configureController}
|
|
@@ -1948,9 +1912,9 @@ var Accessory = /** @class */ (function (_super) {
|
|
|
1948
1912
|
return controllerServiceMap;
|
|
1949
1913
|
};
|
|
1950
1914
|
Accessory.parseBindOption = function (info) {
|
|
1951
|
-
var
|
|
1915
|
+
var e_22, _a;
|
|
1952
1916
|
var advertiserAddress = undefined;
|
|
1953
|
-
var disableIpv6 =
|
|
1917
|
+
var disableIpv6 = undefined;
|
|
1954
1918
|
var serverAddress = undefined;
|
|
1955
1919
|
if (info.bind) {
|
|
1956
1920
|
var entries = new Set(Array.isArray(info.bind) ? info.bind : [info.bind]);
|
|
@@ -1972,7 +1936,7 @@ var Accessory = /** @class */ (function (_super) {
|
|
|
1972
1936
|
else if (entries.size === 1) {
|
|
1973
1937
|
advertiserAddress = Array.from(entries);
|
|
1974
1938
|
var entry = entries.values().next().value; // grab the first one
|
|
1975
|
-
var version = net_1.default.isIP(entry); // check if ip address was specified or
|
|
1939
|
+
var version = net_1.default.isIP(entry); // check if ip address was specified or an interface name
|
|
1976
1940
|
if (version) {
|
|
1977
1941
|
serverAddress = version === 4 ? "0.0.0.0" : "::"; // we currently bind to unspecified addresses so config-ui always has a connection via loopback
|
|
1978
1942
|
}
|
|
@@ -1993,12 +1957,12 @@ var Accessory = /** @class */ (function (_super) {
|
|
|
1993
1957
|
}
|
|
1994
1958
|
}
|
|
1995
1959
|
}
|
|
1996
|
-
catch (
|
|
1960
|
+
catch (e_22_1) { e_22 = { error: e_22_1 }; }
|
|
1997
1961
|
finally {
|
|
1998
1962
|
try {
|
|
1999
1963
|
if (entries_1_1 && !entries_1_1.done && (_a = entries_1.return)) _a.call(entries_1);
|
|
2000
1964
|
}
|
|
2001
|
-
finally { if (
|
|
1965
|
+
finally { if (e_22) throw e_22.error; }
|
|
2002
1966
|
}
|
|
2003
1967
|
if (bindUnspecifiedIpv6) {
|
|
2004
1968
|
serverAddress = "::";
|
|
@@ -2020,6 +1984,10 @@ var Accessory = /** @class */ (function (_super) {
|
|
|
2020
1984
|
*/
|
|
2021
1985
|
// @ts-expect-error: forceConsistentCasingInFileNames compiler option
|
|
2022
1986
|
Accessory.Categories = Categories;
|
|
1987
|
+
/// Timeout in milliseconds until a characteristic warning is issue
|
|
1988
|
+
Accessory.TIMEOUT_WARNING = 3000;
|
|
1989
|
+
/// Timeout in milliseconds after `TIMEOUT_WARNING` until the operation on the characteristic is considered timed out.
|
|
1990
|
+
Accessory.TIMEOUT_AFTER_WARNING = 6000;
|
|
2023
1991
|
return Accessory;
|
|
2024
1992
|
}(events_1.EventEmitter));
|
|
2025
1993
|
exports.Accessory = Accessory;
|