@homebridge/hap-nodejs 2.2.4-beta.6 → 2.3.0-beta.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +14 -17
- package/dist/accessories/AirConditioner_accessory.js +27 -29
- package/dist/accessories/AirConditioner_accessory.js.map +1 -1
- package/dist/accessories/AppleTVRemote_accessory.js +61 -71
- package/dist/accessories/AppleTVRemote_accessory.js.map +1 -1
- package/dist/accessories/Camera_accessory.js +151 -134
- package/dist/accessories/Camera_accessory.js.map +1 -1
- package/dist/accessories/Fan_accessory.js +18 -21
- package/dist/accessories/Fan_accessory.js.map +1 -1
- package/dist/accessories/GarageDoorOpener_accessory.js +33 -35
- package/dist/accessories/GarageDoorOpener_accessory.js.map +1 -1
- package/dist/accessories/Light-AdaptiveLighting_accessory.js +41 -44
- package/dist/accessories/Light-AdaptiveLighting_accessory.js.map +1 -1
- package/dist/accessories/Light_accessory.js +32 -34
- package/dist/accessories/Light_accessory.js.map +1 -1
- package/dist/accessories/Lock_accessory.js +24 -26
- package/dist/accessories/Lock_accessory.js.map +1 -1
- package/dist/accessories/MotionSensor_accessory.js +13 -15
- package/dist/accessories/MotionSensor_accessory.js.map +1 -1
- package/dist/accessories/Outlet_accessory.js +20 -22
- package/dist/accessories/Outlet_accessory.js.map +1 -1
- package/dist/accessories/SmartSpeaker_accessory.js +18 -20
- package/dist/accessories/SmartSpeaker_accessory.js.map +1 -1
- package/dist/accessories/Sprinkler_accessory.js +36 -38
- package/dist/accessories/Sprinkler_accessory.js.map +1 -1
- package/dist/accessories/TV_accessory.js +43 -45
- package/dist/accessories/TV_accessory.js.map +1 -1
- package/dist/accessories/TemperatureSensor_accessory.js +12 -14
- package/dist/accessories/TemperatureSensor_accessory.js.map +1 -1
- package/dist/accessories/Wi-FiRouter_accessory.d.ts +1 -1
- package/dist/accessories/Wi-FiRouter_accessory.d.ts.map +1 -1
- package/dist/accessories/Wi-FiRouter_accessory.js +9 -12
- package/dist/accessories/Wi-FiRouter_accessory.js.map +1 -1
- package/dist/accessories/Wi-FiSatellite_accessory.d.ts +1 -1
- package/dist/accessories/Wi-FiSatellite_accessory.d.ts.map +1 -1
- package/dist/accessories/Wi-FiSatellite_accessory.js +11 -14
- package/dist/accessories/Wi-FiSatellite_accessory.js.map +1 -1
- package/dist/accessories/gstreamer-audioProducer.d.ts +3 -3
- package/dist/accessories/gstreamer-audioProducer.d.ts.map +1 -1
- package/dist/accessories/gstreamer-audioProducer.js +35 -36
- package/dist/accessories/gstreamer-audioProducer.js.map +1 -1
- package/dist/accessories/types.d.ts +63 -63
- package/dist/accessories/types.d.ts.map +1 -1
- package/dist/accessories/types.js +83 -87
- package/dist/accessories/types.js.map +1 -1
- package/dist/hap.d.ts +50 -0
- package/dist/hap.d.ts.map +1 -0
- package/dist/hap.js +49 -0
- package/dist/hap.js.map +1 -0
- package/dist/index.d.ts +3 -49
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +5 -53
- package/dist/index.js.map +1 -1
- package/dist/internal-types.d.ts +1 -1
- package/dist/internal-types.d.ts.map +1 -1
- package/dist/internal-types.js +19 -19
- package/dist/internal-types.js.map +1 -1
- package/dist/lib/Accessory.d.ts +37 -37
- package/dist/lib/Accessory.d.ts.map +1 -1
- package/dist/lib/Accessory.js +265 -257
- package/dist/lib/Accessory.js.map +1 -1
- package/dist/lib/Advertiser.d.ts +6 -6
- package/dist/lib/Advertiser.d.ts.map +1 -1
- package/dist/lib/Advertiser.js +143 -139
- package/dist/lib/Advertiser.js.map +1 -1
- package/dist/lib/Bridge.d.ts +1 -1
- package/dist/lib/Bridge.d.ts.map +1 -1
- package/dist/lib/Bridge.js +2 -6
- package/dist/lib/Bridge.js.map +1 -1
- package/dist/lib/Characteristic.d.ts +40 -41
- package/dist/lib/Characteristic.d.ts.map +1 -1
- package/dist/lib/Characteristic.js +265 -216
- package/dist/lib/Characteristic.js.map +1 -1
- package/dist/lib/HAPServer.d.ts +30 -29
- package/dist/lib/HAPServer.d.ts.map +1 -1
- package/dist/lib/HAPServer.js +223 -224
- package/dist/lib/HAPServer.js.map +1 -1
- package/dist/lib/Service.d.ts +21 -22
- package/dist/lib/Service.d.ts.map +1 -1
- package/dist/lib/Service.js +60 -68
- package/dist/lib/Service.js.map +1 -1
- package/dist/lib/camera/RTPProxy.d.ts +2 -1
- package/dist/lib/camera/RTPProxy.d.ts.map +1 -1
- package/dist/lib/camera/RTPProxy.js +35 -37
- package/dist/lib/camera/RTPProxy.js.map +1 -1
- package/dist/lib/camera/RTPStreamManagement.d.ts +34 -33
- package/dist/lib/camera/RTPStreamManagement.d.ts.map +1 -1
- package/dist/lib/camera/RTPStreamManagement.js +178 -132
- package/dist/lib/camera/RTPStreamManagement.js.map +1 -1
- package/dist/lib/camera/RecordingManagement.d.ts +18 -17
- package/dist/lib/camera/RecordingManagement.d.ts.map +1 -1
- package/dist/lib/camera/RecordingManagement.js +182 -154
- package/dist/lib/camera/RecordingManagement.js.map +1 -1
- package/dist/lib/camera/index.d.ts +3 -3
- package/dist/lib/camera/index.d.ts.map +1 -1
- package/dist/lib/camera/index.js +3 -6
- package/dist/lib/camera/index.js.map +1 -1
- package/dist/lib/controller/AdaptiveLightingController.d.ts +8 -8
- package/dist/lib/controller/AdaptiveLightingController.d.ts.map +1 -1
- package/dist/lib/controller/AdaptiveLightingController.js +111 -99
- package/dist/lib/controller/AdaptiveLightingController.js.map +1 -1
- package/dist/lib/controller/CameraController.d.ts +21 -20
- package/dist/lib/controller/CameraController.d.ts.map +1 -1
- package/dist/lib/controller/CameraController.js +82 -80
- package/dist/lib/controller/CameraController.js.map +1 -1
- package/dist/lib/controller/Controller.d.ts +1 -1
- package/dist/lib/controller/Controller.d.ts.map +1 -1
- package/dist/lib/controller/Controller.js +5 -8
- package/dist/lib/controller/Controller.js.map +1 -1
- package/dist/lib/controller/DoorbellController.d.ts +4 -4
- package/dist/lib/controller/DoorbellController.d.ts.map +1 -1
- package/dist/lib/controller/DoorbellController.js +9 -13
- package/dist/lib/controller/DoorbellController.js.map +1 -1
- package/dist/lib/controller/RemoteController.d.ts +38 -37
- package/dist/lib/controller/RemoteController.d.ts.map +1 -1
- package/dist/lib/controller/RemoteController.js +188 -158
- package/dist/lib/controller/RemoteController.js.map +1 -1
- package/dist/lib/controller/index.d.ts +5 -5
- package/dist/lib/controller/index.d.ts.map +1 -1
- package/dist/lib/controller/index.js +5 -8
- package/dist/lib/controller/index.js.map +1 -1
- package/dist/lib/datastream/DataStreamManagement.d.ts +2 -2
- package/dist/lib/datastream/DataStreamManagement.d.ts.map +1 -1
- package/dist/lib/datastream/DataStreamManagement.js +32 -32
- package/dist/lib/datastream/DataStreamManagement.js.map +1 -1
- package/dist/lib/datastream/DataStreamParser.d.ts +1 -0
- package/dist/lib/datastream/DataStreamParser.d.ts.map +1 -1
- package/dist/lib/datastream/DataStreamParser.js +53 -69
- package/dist/lib/datastream/DataStreamParser.js.map +1 -1
- package/dist/lib/datastream/DataStreamServer.d.ts +23 -22
- package/dist/lib/datastream/DataStreamServer.d.ts.map +1 -1
- package/dist/lib/datastream/DataStreamServer.js +152 -154
- package/dist/lib/datastream/DataStreamServer.js.map +1 -1
- package/dist/lib/datastream/index.d.ts +3 -3
- package/dist/lib/datastream/index.d.ts.map +1 -1
- package/dist/lib/datastream/index.js +3 -6
- package/dist/lib/datastream/index.js.map +1 -1
- package/dist/lib/definitions/CharacteristicDefinitions.d.ts +1 -1
- package/dist/lib/definitions/CharacteristicDefinitions.d.ts.map +1 -1
- package/dist/lib/definitions/CharacteristicDefinitions.js +1103 -1288
- package/dist/lib/definitions/CharacteristicDefinitions.js.map +1 -1
- package/dist/lib/definitions/ServiceDefinitions.d.ts +1 -1
- package/dist/lib/definitions/ServiceDefinitions.d.ts.map +1 -1
- package/dist/lib/definitions/ServiceDefinitions.js +644 -722
- package/dist/lib/definitions/ServiceDefinitions.js.map +1 -1
- package/dist/lib/definitions/generate-definitions.d.ts +2 -2
- package/dist/lib/definitions/generate-definitions.d.ts.map +1 -1
- package/dist/lib/definitions/generate-definitions.js +241 -241
- package/dist/lib/definitions/generate-definitions.js.map +1 -1
- package/dist/lib/definitions/generator-configuration.d.ts +1 -1
- package/dist/lib/definitions/generator-configuration.d.ts.map +1 -1
- package/dist/lib/definitions/generator-configuration.js +572 -309
- package/dist/lib/definitions/generator-configuration.js.map +1 -1
- package/dist/lib/definitions/index.d.ts +2 -2
- package/dist/lib/definitions/index.d.ts.map +1 -1
- package/dist/lib/definitions/index.js +2 -5
- package/dist/lib/definitions/index.js.map +1 -1
- package/dist/lib/gen/HomeKit.js +1 -2
- package/dist/lib/gen/HomeKit.js.map +1 -1
- package/dist/lib/model/AccessoryInfo.d.ts +4 -3
- package/dist/lib/model/AccessoryInfo.d.ts.map +1 -1
- package/dist/lib/model/AccessoryInfo.js +53 -56
- package/dist/lib/model/AccessoryInfo.js.map +1 -1
- package/dist/lib/model/ControllerStorage.d.ts +3 -3
- package/dist/lib/model/ControllerStorage.d.ts.map +1 -1
- package/dist/lib/model/ControllerStorage.js +31 -30
- package/dist/lib/model/ControllerStorage.js.map +1 -1
- package/dist/lib/model/HAPFileStorage.d.ts.map +1 -1
- package/dist/lib/model/HAPFileStorage.js +71 -50
- package/dist/lib/model/HAPFileStorage.js.map +1 -1
- package/dist/lib/model/HAPStorage.d.ts +1 -1
- package/dist/lib/model/HAPStorage.d.ts.map +1 -1
- package/dist/lib/model/HAPStorage.js +11 -14
- package/dist/lib/model/HAPStorage.js.map +1 -1
- package/dist/lib/model/IdentifierCache.d.ts +1 -1
- package/dist/lib/model/IdentifierCache.d.ts.map +1 -1
- package/dist/lib/model/IdentifierCache.js +23 -27
- package/dist/lib/model/IdentifierCache.js.map +1 -1
- package/dist/lib/tv/AccessControlManagement.d.ts +6 -6
- package/dist/lib/tv/AccessControlManagement.d.ts.map +1 -1
- package/dist/lib/tv/AccessControlManagement.js +23 -24
- package/dist/lib/tv/AccessControlManagement.js.map +1 -1
- package/dist/lib/util/checkName.d.ts +2 -2
- package/dist/lib/util/checkName.d.ts.map +1 -1
- package/dist/lib/util/checkName.js +8 -14
- package/dist/lib/util/checkName.js.map +1 -1
- package/dist/lib/util/clone.d.ts.map +1 -1
- package/dist/lib/util/clone.js +1 -5
- package/dist/lib/util/clone.js.map +1 -1
- package/dist/lib/util/color-utils.d.ts +1 -1
- package/dist/lib/util/color-utils.d.ts.map +1 -1
- package/dist/lib/util/color-utils.js +1608 -410
- package/dist/lib/util/color-utils.js.map +1 -1
- package/dist/lib/util/eventedhttp.d.ts +23 -22
- package/dist/lib/util/eventedhttp.d.ts.map +1 -1
- package/dist/lib/util/eventedhttp.js +127 -122
- package/dist/lib/util/eventedhttp.js.map +1 -1
- package/dist/lib/util/hapCrypto.d.ts +2 -1
- package/dist/lib/util/hapCrypto.d.ts.map +1 -1
- package/dist/lib/util/hapCrypto.js +72 -59
- package/dist/lib/util/hapCrypto.js.map +1 -1
- package/dist/lib/util/hapStatusError.d.ts +1 -1
- package/dist/lib/util/hapStatusError.d.ts.map +1 -1
- package/dist/lib/util/hapStatusError.js +4 -8
- package/dist/lib/util/hapStatusError.js.map +1 -1
- package/dist/lib/util/net-utils.js +13 -19
- package/dist/lib/util/net-utils.js.map +1 -1
- package/dist/lib/util/once.js +3 -6
- package/dist/lib/util/once.js.map +1 -1
- package/dist/lib/util/promise-utils.d.ts +1 -1
- package/dist/lib/util/promise-utils.d.ts.map +1 -1
- package/dist/lib/util/promise-utils.js +9 -11
- package/dist/lib/util/promise-utils.js.map +1 -1
- package/dist/lib/util/request-util.d.ts +3 -3
- package/dist/lib/util/request-util.d.ts.map +1 -1
- package/dist/lib/util/request-util.js +13 -22
- package/dist/lib/util/request-util.js.map +1 -1
- package/dist/lib/util/time.d.ts +1 -0
- package/dist/lib/util/time.d.ts.map +1 -1
- package/dist/lib/util/time.js +6 -11
- package/dist/lib/util/time.js.map +1 -1
- package/dist/lib/util/tlv.d.ts +1 -0
- package/dist/lib/util/tlv.d.ts.map +1 -1
- package/dist/lib/util/tlv.js +38 -44
- package/dist/lib/util/tlv.js.map +1 -1
- package/dist/lib/util/uuid.d.ts +1 -0
- package/dist/lib/util/uuid.d.ts.map +1 -1
- package/dist/lib/util/uuid.js +26 -38
- package/dist/lib/util/uuid.js.map +1 -1
- package/dist/types.d.ts +24 -24
- package/dist/types.d.ts.map +1 -1
- package/dist/types.js +3 -5
- package/dist/types.js.map +1 -1
- package/package.json +50 -43
package/dist/lib/Accessory.js
CHANGED
|
@@ -1,30 +1,28 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
const net_1 = tslib_1.__importDefault(require("net"));
|
|
10
|
-
const Advertiser_1 = require("./Advertiser");
|
|
1
|
+
/* global NodeJS */
|
|
2
|
+
import assert from 'node:assert';
|
|
3
|
+
import { Buffer } from 'node:buffer';
|
|
4
|
+
import crypto from 'node:crypto';
|
|
5
|
+
import { EventEmitter } from 'node:events';
|
|
6
|
+
import net from 'node:net';
|
|
7
|
+
import createDebug from 'debug';
|
|
8
|
+
import { AvahiAdvertiser, BonjourHAPAdvertiser, CiaoAdvertiser, ResolvedAdvertiser } from './Advertiser.js';
|
|
11
9
|
// noinspection JSDeprecatedSymbols
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
const debug = (
|
|
27
|
-
const hksvDebug = (
|
|
10
|
+
import { Characteristic, describePerms, isValidPerms, } from './Characteristic.js';
|
|
11
|
+
import { CameraController, isSerializableController, } from './controller/index.js';
|
|
12
|
+
import { HAPServer, } from './HAPServer.js';
|
|
13
|
+
import { AccessoryInfo } from './model/AccessoryInfo.js';
|
|
14
|
+
import { ControllerStorage } from './model/ControllerStorage.js';
|
|
15
|
+
import { IdentifierCache } from './model/IdentifierCache.js';
|
|
16
|
+
import { Service } from './Service.js';
|
|
17
|
+
import { checkName } from './util/checkName.js';
|
|
18
|
+
import { clone } from './util/clone.js';
|
|
19
|
+
import { HapStatusError } from './util/hapStatusError.js';
|
|
20
|
+
import { once } from './util/once.js';
|
|
21
|
+
import { extractHAPStatusFromError, formatOutgoingCharacteristicValue } from './util/request-util.js';
|
|
22
|
+
import * as uuid from './util/uuid.js';
|
|
23
|
+
import { toShortForm } from './util/uuid.js';
|
|
24
|
+
const debug = createDebug('HAP-NodeJS:Accessory');
|
|
25
|
+
const hksvDebug = createDebug('HAP-NodeJS:HKSV');
|
|
28
26
|
const MAX_ACCESSORIES = 149; // Maximum number of bridged accessories per bridge.
|
|
29
27
|
const MAX_SERVICES = 100;
|
|
30
28
|
/**
|
|
@@ -32,7 +30,8 @@ const MAX_SERVICES = 100;
|
|
|
32
30
|
*
|
|
33
31
|
* @group Accessory
|
|
34
32
|
*/
|
|
35
|
-
|
|
33
|
+
// eslint-disable-next-line no-restricted-syntax
|
|
34
|
+
export var Categories;
|
|
36
35
|
(function (Categories) {
|
|
37
36
|
// noinspection JSUnusedGlobalSymbols
|
|
38
37
|
Categories[Categories["OTHER"] = 1] = "OTHER";
|
|
@@ -46,7 +45,7 @@ var Categories;
|
|
|
46
45
|
Categories[Categories["THERMOSTAT"] = 9] = "THERMOSTAT";
|
|
47
46
|
Categories[Categories["SENSOR"] = 10] = "SENSOR";
|
|
48
47
|
Categories[Categories["ALARM_SYSTEM"] = 11] = "ALARM_SYSTEM";
|
|
49
|
-
// eslint-disable-next-line
|
|
48
|
+
// eslint-disable-next-line ts/no-duplicate-enum-values
|
|
50
49
|
Categories[Categories["SECURITY_SYSTEM"] = 11] = "SECURITY_SYSTEM";
|
|
51
50
|
Categories[Categories["DOOR"] = 12] = "DOOR";
|
|
52
51
|
Categories[Categories["WINDOW"] = 13] = "WINDOW";
|
|
@@ -54,7 +53,7 @@ var Categories;
|
|
|
54
53
|
Categories[Categories["PROGRAMMABLE_SWITCH"] = 15] = "PROGRAMMABLE_SWITCH";
|
|
55
54
|
Categories[Categories["RANGE_EXTENDER"] = 16] = "RANGE_EXTENDER";
|
|
56
55
|
Categories[Categories["CAMERA"] = 17] = "CAMERA";
|
|
57
|
-
// eslint-disable-next-line
|
|
56
|
+
// eslint-disable-next-line ts/no-duplicate-enum-values
|
|
58
57
|
Categories[Categories["IP_CAMERA"] = 17] = "IP_CAMERA";
|
|
59
58
|
Categories[Categories["VIDEO_DOORBELL"] = 18] = "VIDEO_DOORBELL";
|
|
60
59
|
Categories[Categories["AIR_PURIFIER"] = 19] = "AIR_PURIFIER";
|
|
@@ -75,11 +74,12 @@ var Categories;
|
|
|
75
74
|
Categories[Categories["AUDIO_RECEIVER"] = 34] = "AUDIO_RECEIVER";
|
|
76
75
|
Categories[Categories["TV_SET_TOP_BOX"] = 35] = "TV_SET_TOP_BOX";
|
|
77
76
|
Categories[Categories["TV_STREAMING_STICK"] = 36] = "TV_STREAMING_STICK";
|
|
78
|
-
})(Categories || (
|
|
77
|
+
})(Categories || (Categories = {}));
|
|
79
78
|
/**
|
|
80
79
|
* @group Accessory
|
|
81
80
|
*/
|
|
82
|
-
|
|
81
|
+
// eslint-disable-next-line no-restricted-syntax
|
|
82
|
+
export var CharacteristicWarningType;
|
|
83
83
|
(function (CharacteristicWarningType) {
|
|
84
84
|
CharacteristicWarningType["SLOW_WRITE"] = "slow-write";
|
|
85
85
|
CharacteristicWarningType["TIMEOUT_WRITE"] = "timeout-write";
|
|
@@ -88,11 +88,12 @@ var CharacteristicWarningType;
|
|
|
88
88
|
CharacteristicWarningType["WARN_MESSAGE"] = "warn-message";
|
|
89
89
|
CharacteristicWarningType["ERROR_MESSAGE"] = "error-message";
|
|
90
90
|
CharacteristicWarningType["DEBUG_MESSAGE"] = "debug-message";
|
|
91
|
-
})(CharacteristicWarningType || (
|
|
91
|
+
})(CharacteristicWarningType || (CharacteristicWarningType = {}));
|
|
92
92
|
/**
|
|
93
93
|
* @group Accessory
|
|
94
94
|
*/
|
|
95
|
-
|
|
95
|
+
// eslint-disable-next-line no-restricted-syntax
|
|
96
|
+
export var MDNSAdvertiser;
|
|
96
97
|
(function (MDNSAdvertiser) {
|
|
97
98
|
/**
|
|
98
99
|
* Use the `@homebridge/ciao` module as advertiser.
|
|
@@ -114,7 +115,8 @@ var MDNSAdvertiser;
|
|
|
114
115
|
* Consequentially, treat this feature as an experimental feature.
|
|
115
116
|
*/
|
|
116
117
|
MDNSAdvertiser["RESOLVED"] = "resolved";
|
|
117
|
-
})(MDNSAdvertiser || (
|
|
118
|
+
})(MDNSAdvertiser || (MDNSAdvertiser = {}));
|
|
119
|
+
// eslint-disable-next-line no-restricted-syntax
|
|
118
120
|
var WriteRequestState;
|
|
119
121
|
(function (WriteRequestState) {
|
|
120
122
|
WriteRequestState[WriteRequestState["REGULAR_REQUEST"] = 0] = "REGULAR_REQUEST";
|
|
@@ -124,7 +126,8 @@ var WriteRequestState;
|
|
|
124
126
|
/**
|
|
125
127
|
* @group Accessory
|
|
126
128
|
*/
|
|
127
|
-
|
|
129
|
+
// eslint-disable-next-line no-restricted-syntax
|
|
130
|
+
export var AccessoryEventTypes;
|
|
128
131
|
(function (AccessoryEventTypes) {
|
|
129
132
|
/**
|
|
130
133
|
* Emitted when an iOS device wishes for this Accessory to identify itself. If `paired` is false, then
|
|
@@ -152,7 +155,7 @@ var AccessoryEventTypes;
|
|
|
152
155
|
AccessoryEventTypes["PAIRED"] = "paired";
|
|
153
156
|
AccessoryEventTypes["UNPAIRED"] = "unpaired";
|
|
154
157
|
AccessoryEventTypes["CHARACTERISTIC_WARNING"] = "characteristic-warning";
|
|
155
|
-
})(AccessoryEventTypes || (
|
|
158
|
+
})(AccessoryEventTypes || (AccessoryEventTypes = {}));
|
|
156
159
|
/**
|
|
157
160
|
* Accessory is a virtual HomeKit device. It can publish an associated HAP server for iOS devices to communicate
|
|
158
161
|
* with - or it can run behind another "Bridge" Accessory server.
|
|
@@ -164,8 +167,8 @@ var AccessoryEventTypes;
|
|
|
164
167
|
*
|
|
165
168
|
* @group Accessory
|
|
166
169
|
*/
|
|
167
|
-
// eslint-disable-next-line
|
|
168
|
-
class Accessory extends
|
|
170
|
+
// eslint-disable-next-line ts/no-unsafe-declaration-merging
|
|
171
|
+
export class Accessory extends EventEmitter {
|
|
169
172
|
displayName;
|
|
170
173
|
UUID;
|
|
171
174
|
// Timeout in milliseconds until a characteristic warning is issue
|
|
@@ -187,38 +190,38 @@ class Accessory extends events_1.EventEmitter {
|
|
|
187
190
|
/**
|
|
188
191
|
* Captures if initialization steps inside {@link publish} have been called.
|
|
189
192
|
* This is important when calling {@link publish} multiple times (e.g. after calling {@link unpublish}).
|
|
190
|
-
* @private
|
|
193
|
+
* @private
|
|
191
194
|
*/
|
|
192
195
|
initialized = false;
|
|
193
196
|
controllers = {};
|
|
194
197
|
serializedControllers; // store uninitialized controller data after a Accessory.deserialize call
|
|
195
198
|
activeCameraController;
|
|
196
199
|
/**
|
|
197
|
-
* @private
|
|
200
|
+
* @private
|
|
198
201
|
*/
|
|
199
202
|
_accessoryInfo;
|
|
200
203
|
/**
|
|
201
|
-
* @private
|
|
204
|
+
* @private
|
|
202
205
|
*/
|
|
203
206
|
_setupID = null;
|
|
204
207
|
/**
|
|
205
|
-
* @private
|
|
208
|
+
* @private
|
|
206
209
|
*/
|
|
207
210
|
_identifierCache;
|
|
208
211
|
/**
|
|
209
|
-
* @private
|
|
212
|
+
* @private
|
|
210
213
|
*/
|
|
211
214
|
controllerStorage;
|
|
212
215
|
/**
|
|
213
|
-
* @private
|
|
216
|
+
* @private
|
|
214
217
|
*/
|
|
215
218
|
_advertiser;
|
|
216
219
|
/**
|
|
217
|
-
* @private
|
|
220
|
+
* @private
|
|
218
221
|
*/
|
|
219
222
|
_server;
|
|
220
223
|
/**
|
|
221
|
-
* @private
|
|
224
|
+
* @private
|
|
222
225
|
*/
|
|
223
226
|
_setupURI;
|
|
224
227
|
configurationChangeDebounceTimeout;
|
|
@@ -237,25 +240,25 @@ class Accessory extends events_1.EventEmitter {
|
|
|
237
240
|
super();
|
|
238
241
|
this.displayName = displayName;
|
|
239
242
|
this.UUID = UUID;
|
|
240
|
-
(
|
|
241
|
-
(
|
|
242
|
-
(
|
|
243
|
-
|
|
244
|
-
this.controllerStorage = new
|
|
243
|
+
assert(displayName, 'Accessories must be created with a non-empty displayName.');
|
|
244
|
+
assert(UUID, 'Accessories must be created with a valid UUID.');
|
|
245
|
+
assert(uuid.isValid(UUID), `UUID '${UUID}' is not a valid UUID. Try using the provided 'generateUUID' function to create a `
|
|
246
|
+
+ 'valid UUID from any arbitrary string, like a serial number.');
|
|
247
|
+
this.controllerStorage = new ControllerStorage(this);
|
|
245
248
|
// create our initial "Accessory Information" Service that all Accessories are expected to have
|
|
246
|
-
|
|
247
|
-
this.addService(
|
|
248
|
-
.setCharacteristic(
|
|
249
|
+
checkName(this.displayName, 'Name', displayName);
|
|
250
|
+
this.addService(Service.AccessoryInformation)
|
|
251
|
+
.setCharacteristic(Characteristic.Name, displayName);
|
|
249
252
|
}
|
|
250
253
|
identificationRequest(paired, callback) {
|
|
251
|
-
debug(
|
|
254
|
+
debug('[%s] Identification request', this.displayName);
|
|
252
255
|
if (this.listeners("identify" /* AccessoryEventTypes.IDENTIFY */).length > 0) {
|
|
253
256
|
// allow implementors to identify this Accessory in whatever way is appropriate, and pass along
|
|
254
257
|
// the standard callback for completion.
|
|
255
258
|
this.emit("identify" /* AccessoryEventTypes.IDENTIFY */, paired, callback);
|
|
256
259
|
}
|
|
257
260
|
else {
|
|
258
|
-
debug(
|
|
261
|
+
debug('[%s] Identification request ignored; no listeners to \'identify\' event', this.displayName);
|
|
259
262
|
callback();
|
|
260
263
|
}
|
|
261
264
|
}
|
|
@@ -265,8 +268,8 @@ class Accessory extends events_1.EventEmitter {
|
|
|
265
268
|
* by a `set` listener on the characteristic, so a plugin's own handlers on it don't compete with ours.
|
|
266
269
|
*/
|
|
267
270
|
isIdentifyCharacteristic(characteristic) {
|
|
268
|
-
return characteristic.UUID ===
|
|
269
|
-
&& !!this.getService(
|
|
271
|
+
return characteristic.UUID === Characteristic.Identify.UUID
|
|
272
|
+
&& !!this.getService(Service.AccessoryInformation)?.characteristics.includes(characteristic);
|
|
270
273
|
}
|
|
271
274
|
/**
|
|
272
275
|
* @returns a promise resolving once the identification is done, rejecting with the {@link HAPStatus} to answer otherwise.
|
|
@@ -274,19 +277,19 @@ class Accessory extends events_1.EventEmitter {
|
|
|
274
277
|
handlePairedIdentify(characteristic) {
|
|
275
278
|
return new Promise((resolve, reject) => {
|
|
276
279
|
try {
|
|
277
|
-
this.identificationRequest(true,
|
|
280
|
+
this.identificationRequest(true, once((error) => {
|
|
278
281
|
if (!error) {
|
|
279
282
|
resolve();
|
|
280
283
|
}
|
|
281
|
-
else if (typeof error ===
|
|
282
|
-
reject(new
|
|
284
|
+
else if (typeof error === 'number') {
|
|
285
|
+
reject(new HapStatusError(error).hapStatus);
|
|
283
286
|
}
|
|
284
|
-
else if (error instanceof
|
|
287
|
+
else if (error instanceof HapStatusError) {
|
|
285
288
|
reject(error.hapStatus);
|
|
286
289
|
}
|
|
287
290
|
else {
|
|
288
|
-
debug(
|
|
289
|
-
reject(
|
|
291
|
+
debug('[%s] Received error from identify handler %s', this.displayName, error.stack);
|
|
292
|
+
reject(extractHAPStatusFromError(error));
|
|
290
293
|
}
|
|
291
294
|
}));
|
|
292
295
|
}
|
|
@@ -296,11 +299,10 @@ class Accessory extends events_1.EventEmitter {
|
|
|
296
299
|
}
|
|
297
300
|
});
|
|
298
301
|
}
|
|
299
|
-
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
300
302
|
addService(serviceParam, ...constructorArgs) {
|
|
301
303
|
// service might be a constructor like `Service.AccessoryInformation` instead of an instance
|
|
302
304
|
// of Service. Coerce if necessary.
|
|
303
|
-
const service = typeof serviceParam ===
|
|
305
|
+
const service = typeof serviceParam === 'function'
|
|
304
306
|
? new serviceParam(constructorArgs[0], constructorArgs[1], constructorArgs[2])
|
|
305
307
|
: serviceParam;
|
|
306
308
|
// check for UUID+subtype conflict
|
|
@@ -308,17 +310,15 @@ class Accessory extends events_1.EventEmitter {
|
|
|
308
310
|
if (existing.UUID === service.UUID) {
|
|
309
311
|
// OK we have two Services with the same UUID. Check that each defines a `subtype` property and that each is unique.
|
|
310
312
|
if (!service.subtype) {
|
|
311
|
-
throw new Error(
|
|
312
|
-
"' as another Service in this Accessory without also defining a unique 'subtype' property.");
|
|
313
|
+
throw new Error(`Cannot add a Service with the same UUID '${existing.UUID}' as another Service in this Accessory without also defining a unique 'subtype' property.`);
|
|
313
314
|
}
|
|
314
315
|
if (service.subtype === existing.subtype) {
|
|
315
|
-
throw new Error(
|
|
316
|
-
"' and subtype '" + existing.subtype + "' as another Service in this Accessory.");
|
|
316
|
+
throw new Error(`Cannot add a Service with the same UUID '${existing.UUID}' and subtype '${existing.subtype}' as another Service in this Accessory.`);
|
|
317
317
|
}
|
|
318
318
|
}
|
|
319
319
|
}
|
|
320
320
|
if (this.services.length >= MAX_SERVICES) {
|
|
321
|
-
throw new Error(
|
|
321
|
+
throw new Error(`Cannot add more than ${MAX_SERVICES} services to a single accessory!`);
|
|
322
322
|
}
|
|
323
323
|
this.services.push(service);
|
|
324
324
|
if (service.isPrimaryService) { // check if a primary service was added
|
|
@@ -331,7 +331,7 @@ class Accessory extends events_1.EventEmitter {
|
|
|
331
331
|
this.enqueueConfigurationUpdate();
|
|
332
332
|
}
|
|
333
333
|
else {
|
|
334
|
-
this.emit("service-configurationChange" /* AccessoryEventTypes.SERVICE_CONFIGURATION_CHANGE */, { service
|
|
334
|
+
this.emit("service-configurationChange" /* AccessoryEventTypes.SERVICE_CONFIGURATION_CHANGE */, { service });
|
|
335
335
|
}
|
|
336
336
|
this.setupServiceEventHandlers(service);
|
|
337
337
|
return service;
|
|
@@ -348,7 +348,7 @@ class Accessory extends events_1.EventEmitter {
|
|
|
348
348
|
this.enqueueConfigurationUpdate();
|
|
349
349
|
}
|
|
350
350
|
else {
|
|
351
|
-
this.emit("service-configurationChange" /* AccessoryEventTypes.SERVICE_CONFIGURATION_CHANGE */, { service
|
|
351
|
+
this.emit("service-configurationChange" /* AccessoryEventTypes.SERVICE_CONFIGURATION_CHANGE */, { service });
|
|
352
352
|
}
|
|
353
353
|
service.removeAllListeners();
|
|
354
354
|
}
|
|
@@ -360,12 +360,12 @@ class Accessory extends events_1.EventEmitter {
|
|
|
360
360
|
}
|
|
361
361
|
getService(name) {
|
|
362
362
|
for (const service of this.services) {
|
|
363
|
-
if (typeof name ===
|
|
363
|
+
if (typeof name === 'string' && (service.displayName === name || service.name === name || service.subtype === name)) {
|
|
364
364
|
return service;
|
|
365
365
|
}
|
|
366
366
|
else {
|
|
367
367
|
// @ts-expect-error ('UUID' does not exist on type 'never')
|
|
368
|
-
if (typeof name ===
|
|
368
|
+
if (typeof name === 'function' && ((service instanceof name) || (name.UUID === service.UUID))) {
|
|
369
369
|
return service;
|
|
370
370
|
}
|
|
371
371
|
}
|
|
@@ -374,12 +374,12 @@ class Accessory extends events_1.EventEmitter {
|
|
|
374
374
|
}
|
|
375
375
|
getServiceById(uuid, subType) {
|
|
376
376
|
for (const service of this.services) {
|
|
377
|
-
if (typeof uuid ===
|
|
377
|
+
if (typeof uuid === 'string' && (service.displayName === uuid || service.name === uuid) && service.subtype === subType) {
|
|
378
378
|
return service;
|
|
379
379
|
}
|
|
380
380
|
else {
|
|
381
381
|
// @ts-expect-error ('UUID' does not exist on type 'never')
|
|
382
|
-
if (typeof uuid ===
|
|
382
|
+
if (typeof uuid === 'function' && ((service instanceof uuid) || (uuid.UUID === service.UUID)) && service.subtype === subType) {
|
|
383
383
|
return service;
|
|
384
384
|
}
|
|
385
385
|
}
|
|
@@ -397,17 +397,17 @@ class Accessory extends events_1.EventEmitter {
|
|
|
397
397
|
};
|
|
398
398
|
addBridgedAccessory(accessory, deferUpdate = false) {
|
|
399
399
|
if (accessory._isBridge || accessory === this) {
|
|
400
|
-
throw new Error(
|
|
400
|
+
throw new Error('Illegal state: either trying to bridge a bridge or trying to bridge itself!');
|
|
401
401
|
}
|
|
402
402
|
if (accessory.initialized) {
|
|
403
|
-
throw new Error(
|
|
403
|
+
throw new Error('Tried to bridge an accessory which was already published once!');
|
|
404
404
|
}
|
|
405
405
|
if (accessory.bridge != null) {
|
|
406
406
|
// this also prevents that we bridge the same accessory twice!
|
|
407
|
-
throw new Error(
|
|
407
|
+
throw new Error(`Tried to bridge ${accessory.displayName} while it was already bridged by ${accessory.bridge.displayName}`);
|
|
408
408
|
}
|
|
409
409
|
if (this.bridgedAccessories.length >= MAX_ACCESSORIES) {
|
|
410
|
-
throw new Error(
|
|
410
|
+
throw new Error(`Cannot Bridge more than ${MAX_ACCESSORIES} Accessories`);
|
|
411
411
|
}
|
|
412
412
|
// listen for changes in ANY characteristics of ANY services on this Accessory
|
|
413
413
|
accessory.on("service-characteristic-change" /* AccessoryEventTypes.SERVICE_CHARACTERISTIC_CHANGE */, change => this.handleCharacteristicChangeEvent(accessory, change.service, change));
|
|
@@ -432,7 +432,7 @@ class Accessory extends events_1.EventEmitter {
|
|
|
432
432
|
// check for UUID conflict
|
|
433
433
|
const accessoryIndex = this.bridgedAccessories.indexOf(accessory);
|
|
434
434
|
if (accessoryIndex === -1) {
|
|
435
|
-
throw new Error(
|
|
435
|
+
throw new Error('Cannot find the bridged Accessory to remove.');
|
|
436
436
|
}
|
|
437
437
|
this.bridgedAccessories.splice(accessoryIndex, 1);
|
|
438
438
|
if (this._server && accessory.aid != null) {
|
|
@@ -495,7 +495,7 @@ class Accessory extends events_1.EventEmitter {
|
|
|
495
495
|
* @param controllerConstructor - The Controller instance or constructor to the Controller with no required arguments.
|
|
496
496
|
*/
|
|
497
497
|
configureController(controllerConstructor) {
|
|
498
|
-
const controller = typeof controllerConstructor ===
|
|
498
|
+
const controller = typeof controllerConstructor === 'function'
|
|
499
499
|
? new controllerConstructor() // any custom constructor arguments should be passed before using .bind(...)
|
|
500
500
|
: controllerConstructor;
|
|
501
501
|
const id = controller.controllerId();
|
|
@@ -505,7 +505,7 @@ class Accessory extends events_1.EventEmitter {
|
|
|
505
505
|
const savedServiceMap = this.serializedControllers && this.serializedControllers[id];
|
|
506
506
|
let serviceMap;
|
|
507
507
|
if (savedServiceMap) { // we found data to restore from
|
|
508
|
-
const clonedServiceMap =
|
|
508
|
+
const clonedServiceMap = clone(savedServiceMap);
|
|
509
509
|
const updatedServiceMap = controller.initWithServices(savedServiceMap); // init controller with existing services
|
|
510
510
|
serviceMap = updatedServiceMap || savedServiceMap; // initWithServices could return an updated serviceMap, otherwise just use the existing one
|
|
511
511
|
if (updatedServiceMap) { // controller returned a ServiceMap and thus signaled an updated set of services
|
|
@@ -522,7 +522,7 @@ class Accessory extends events_1.EventEmitter {
|
|
|
522
522
|
else {
|
|
523
523
|
serviceMap = controller.constructServices(); // let the controller create his services
|
|
524
524
|
controller.configureServices(); // let the controller setup all its handlers
|
|
525
|
-
Object.values(serviceMap).forEach(service => {
|
|
525
|
+
Object.values(serviceMap).forEach((service) => {
|
|
526
526
|
if (service && !this.services.includes(service)) {
|
|
527
527
|
this.addService(service);
|
|
528
528
|
}
|
|
@@ -530,14 +530,14 @@ class Accessory extends events_1.EventEmitter {
|
|
|
530
530
|
}
|
|
531
531
|
// --- init handlers and setup context ---
|
|
532
532
|
const context = {
|
|
533
|
-
controller
|
|
534
|
-
serviceMap
|
|
533
|
+
controller,
|
|
534
|
+
serviceMap,
|
|
535
535
|
};
|
|
536
|
-
if (
|
|
536
|
+
if (isSerializableController(controller)) {
|
|
537
537
|
this.controllerStorage.trackController(controller);
|
|
538
538
|
}
|
|
539
539
|
this.controllers[id] = context;
|
|
540
|
-
if (controller instanceof
|
|
540
|
+
if (controller instanceof CameraController) { // save CameraController for Snapshot handling
|
|
541
541
|
this.activeCameraController = controller;
|
|
542
542
|
}
|
|
543
543
|
}
|
|
@@ -553,10 +553,9 @@ class Accessory extends events_1.EventEmitter {
|
|
|
553
553
|
const storedController = this.controllers[id];
|
|
554
554
|
if (storedController) {
|
|
555
555
|
if (storedController.controller !== controller) {
|
|
556
|
-
throw new Error(
|
|
557
|
-
"' though provided controller isn't the same instance that is registered!");
|
|
556
|
+
throw new Error(`[${this.displayName}] tried removing a controller with the id/type '${id}' though provided controller isn't the same instance that is registered!`);
|
|
558
557
|
}
|
|
559
|
-
if (
|
|
558
|
+
if (isSerializableController(controller)) {
|
|
560
559
|
// this will reset the state change delegate before we call handleControllerRemoved()
|
|
561
560
|
this.controllerStorage.untrackController(controller);
|
|
562
561
|
}
|
|
@@ -568,7 +567,7 @@ class Accessory extends events_1.EventEmitter {
|
|
|
568
567
|
if (this.activeCameraController === controller) {
|
|
569
568
|
this.activeCameraController = undefined;
|
|
570
569
|
}
|
|
571
|
-
Object.values(storedController.serviceMap).forEach(service => {
|
|
570
|
+
Object.values(storedController.serviceMap).forEach((service) => {
|
|
572
571
|
if (service) {
|
|
573
572
|
this.removeService(service);
|
|
574
573
|
}
|
|
@@ -584,14 +583,14 @@ class Accessory extends events_1.EventEmitter {
|
|
|
584
583
|
if (controller.handleFactoryReset) { // if the controller implements handleFactoryReset, setup event handlers for this controller
|
|
585
584
|
controller.handleFactoryReset();
|
|
586
585
|
}
|
|
587
|
-
if (
|
|
586
|
+
if (isSerializableController(controller)) {
|
|
588
587
|
this.controllerStorage.purgeControllerData(controller);
|
|
589
588
|
}
|
|
590
589
|
}
|
|
591
590
|
}
|
|
592
591
|
handleUpdatedControllerServiceMap(originalServiceMap, updatedServiceMap) {
|
|
593
|
-
updatedServiceMap =
|
|
594
|
-
Object.keys(originalServiceMap).forEach(name => {
|
|
592
|
+
updatedServiceMap = clone(updatedServiceMap); // clone it so we can alter it
|
|
593
|
+
Object.keys(originalServiceMap).forEach((name) => {
|
|
595
594
|
const service = originalServiceMap[name];
|
|
596
595
|
const updatedService = updatedServiceMap[name];
|
|
597
596
|
if (service && updatedService) { // we check all names contained in both ServiceMaps for changes
|
|
@@ -604,12 +603,12 @@ class Accessory extends events_1.EventEmitter {
|
|
|
604
603
|
}
|
|
605
604
|
});
|
|
606
605
|
// now originalServiceMap contains only deleted services and updateServiceMap only added services
|
|
607
|
-
Object.values(originalServiceMap).forEach(service => {
|
|
606
|
+
Object.values(originalServiceMap).forEach((service) => {
|
|
608
607
|
if (service) {
|
|
609
608
|
this.removeService(service);
|
|
610
609
|
}
|
|
611
610
|
});
|
|
612
|
-
Object.values(updatedServiceMap).forEach(service => {
|
|
611
|
+
Object.values(updatedServiceMap).forEach((service) => {
|
|
613
612
|
if (service) {
|
|
614
613
|
this.addService(service);
|
|
615
614
|
}
|
|
@@ -619,9 +618,9 @@ class Accessory extends events_1.EventEmitter {
|
|
|
619
618
|
if (this._setupURI) {
|
|
620
619
|
return this._setupURI;
|
|
621
620
|
}
|
|
622
|
-
(
|
|
621
|
+
assert(!!this._accessoryInfo, 'Cannot generate setupURI on an accessory that isn\'t published yet!');
|
|
623
622
|
const buffer = Buffer.alloc(8);
|
|
624
|
-
let value_low = parseInt(this._accessoryInfo.pincode.replace(/-/g,
|
|
623
|
+
let value_low = parseInt(this._accessoryInfo.pincode.replace(/-/g, ''), 10);
|
|
625
624
|
const value_high = this._accessoryInfo.category >> 1;
|
|
626
625
|
value_low |= 1 << 28; // Supports IP;
|
|
627
626
|
buffer.writeUInt32BE(value_low, 4);
|
|
@@ -632,10 +631,10 @@ class Accessory extends events_1.EventEmitter {
|
|
|
632
631
|
let encodedPayload = (buffer.readUInt32BE(4) + (buffer.readUInt32BE(0) * 0x100000000)).toString(36).toUpperCase();
|
|
633
632
|
if (encodedPayload.length !== 9) {
|
|
634
633
|
for (let i = 0; i <= 9 - encodedPayload.length; i++) {
|
|
635
|
-
encodedPayload =
|
|
634
|
+
encodedPayload = `0${encodedPayload}`;
|
|
636
635
|
}
|
|
637
636
|
}
|
|
638
|
-
this._setupURI =
|
|
637
|
+
this._setupURI = `X-HM://${encodedPayload}${this._setupID}`;
|
|
639
638
|
return this._setupURI;
|
|
640
639
|
}
|
|
641
640
|
/**
|
|
@@ -648,8 +647,8 @@ class Accessory extends events_1.EventEmitter {
|
|
|
648
647
|
findPermsViolation() {
|
|
649
648
|
for (const service of this.services) {
|
|
650
649
|
for (const characteristic of service.characteristics) {
|
|
651
|
-
if (!
|
|
652
|
-
return { characteristic
|
|
650
|
+
if (!isValidPerms(characteristic.props.perms)) {
|
|
651
|
+
return { characteristic, service };
|
|
653
652
|
}
|
|
654
653
|
}
|
|
655
654
|
}
|
|
@@ -667,7 +666,7 @@ class Accessory extends events_1.EventEmitter {
|
|
|
667
666
|
const serviceName = violation.service.displayName || violation.service.constructor.name;
|
|
668
667
|
return `HAP-NodeJS: accessory '${this.displayName}' ${disposition}. Service '${serviceName}' (${violation.service.UUID}), `
|
|
669
668
|
+ `characteristic '${violation.characteristic.displayName}' (${violation.characteristic.UUID}) contains invalid permissions: `
|
|
670
|
-
+ `${
|
|
669
|
+
+ `${describePerms(violation.characteristic.props.perms)}`;
|
|
671
670
|
}
|
|
672
671
|
/**
|
|
673
672
|
* Returns the bridged accessories fit to be served, excluding any whose characteristic permissions HomeKit would reject. Both representation builders
|
|
@@ -684,7 +683,7 @@ class Accessory extends events_1.EventEmitter {
|
|
|
684
683
|
if (violation) {
|
|
685
684
|
if (!accessory.permsQuarantined) {
|
|
686
685
|
accessory.permsQuarantined = true;
|
|
687
|
-
accessory.sendCharacteristicWarning(violation.characteristic, "error-message" /* CharacteristicWarningType.ERROR_MESSAGE */, accessory.permsViolationMessage(violation,
|
|
686
|
+
accessory.sendCharacteristicWarning(violation.characteristic, "error-message" /* CharacteristicWarningType.ERROR_MESSAGE */, accessory.permsViolationMessage(violation, 'is excluded from the accessory database until its permissions are corrected'));
|
|
688
687
|
/* The configuration this accessory contributed has just disappeared from what we serve, so the configuration number has to move. Enqueueing
|
|
689
688
|
* from inside a representation build is safe and terminates: the build that observes a transition records it before returning, so the
|
|
690
689
|
* debounced pass that follows sees a settled state, hashes it, and enqueues nothing further.
|
|
@@ -707,30 +706,29 @@ class Accessory extends events_1.EventEmitter {
|
|
|
707
706
|
* If it is called on a bridge it will call this method for all bridged accessories.
|
|
708
707
|
*/
|
|
709
708
|
validateAccessory(mainAccessory) {
|
|
710
|
-
const service = this.getService(
|
|
709
|
+
const service = this.getService(Service.AccessoryInformation);
|
|
711
710
|
if (!service) {
|
|
712
|
-
console.log(
|
|
713
|
-
|
|
711
|
+
console.log(`HAP-NodeJS WARNING: The accessory '${this.displayName}' is getting published without a AccessoryInformation service. `
|
|
712
|
+
+ 'This might prevent the accessory from being added to the Home app or leading to the accessory being unresponsive!');
|
|
714
713
|
}
|
|
715
714
|
else {
|
|
716
|
-
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
717
715
|
const checkValue = (name, value) => {
|
|
718
716
|
if (!value) {
|
|
719
|
-
console.log(
|
|
720
|
-
|
|
721
|
-
|
|
717
|
+
console.log(`HAP-NodeJS WARNING: The accessory '${this.displayName}' is getting published with the characteristic '${name}'`
|
|
718
|
+
+ ' (of the AccessoryInformation service) not having a value set. '
|
|
719
|
+
+ 'This might prevent the accessory from being added to the Home App or leading to the accessory being unresponsive!');
|
|
722
720
|
}
|
|
723
721
|
};
|
|
724
|
-
|
|
725
|
-
checkValue(
|
|
726
|
-
checkValue(
|
|
727
|
-
checkValue(
|
|
728
|
-
checkValue(
|
|
729
|
-
checkValue(
|
|
722
|
+
checkName(this.displayName, 'Name', service.getCharacteristic(Characteristic.Name).value);
|
|
723
|
+
checkValue('FirmwareRevision', service.getCharacteristic(Characteristic.FirmwareRevision).value);
|
|
724
|
+
checkValue('Manufacturer', service.getCharacteristic(Characteristic.Manufacturer).value);
|
|
725
|
+
checkValue('Model', service.getCharacteristic(Characteristic.Model).value);
|
|
726
|
+
checkValue('Name', service.getCharacteristic(Characteristic.Name).value);
|
|
727
|
+
checkValue('SerialNumber', service.getCharacteristic(Characteristic.SerialNumber).value);
|
|
730
728
|
}
|
|
731
729
|
if (mainAccessory) {
|
|
732
730
|
// the main accessory which is advertised via bonjour must have a name with length <= 63 (limitation of DNS FQDN names)
|
|
733
|
-
(
|
|
731
|
+
assert(Buffer.from(this.displayName, 'utf8').length <= 63, 'Accessory displayName cannot be longer than 63 bytes!');
|
|
734
732
|
}
|
|
735
733
|
// any accessories we are bridging are validated the same way; the list is empty for anything that is not a bridge
|
|
736
734
|
this.bridgedAccessories.forEach(accessory => accessory.validateAccessory());
|
|
@@ -738,7 +736,7 @@ class Accessory extends events_1.EventEmitter {
|
|
|
738
736
|
/**
|
|
739
737
|
* Assigns aid/iid to ourselves, any Accessories we are bridging, and all associated Services+Characteristics. Uses
|
|
740
738
|
* the provided identifierCache to keep IDs stable.
|
|
741
|
-
* @private
|
|
739
|
+
* @private
|
|
742
740
|
*/
|
|
743
741
|
_assignIDs(identifierCache) {
|
|
744
742
|
// if we are responsible for our own identifierCache, start the expiration process
|
|
@@ -771,11 +769,11 @@ class Accessory extends events_1.EventEmitter {
|
|
|
771
769
|
// expire any now-unused cache keys (for Accessories, Services, or Characteristics
|
|
772
770
|
// that have been removed since the last call to assignIDs())
|
|
773
771
|
if (this._identifierCache) {
|
|
774
|
-
//Check weather we want to purge the unused ids
|
|
772
|
+
// Check weather we want to purge the unused ids
|
|
775
773
|
if (this.shouldPurgeUnusedIDs) {
|
|
776
774
|
this._identifierCache.stopTrackingUsageAndExpireUnused();
|
|
777
775
|
}
|
|
778
|
-
//Save in case we have new ones
|
|
776
|
+
// Save in case we have new ones
|
|
779
777
|
this._identifierCache.save();
|
|
780
778
|
}
|
|
781
779
|
}
|
|
@@ -790,10 +788,10 @@ class Accessory extends events_1.EventEmitter {
|
|
|
790
788
|
* when you have disabled auto purge, so you can do it manually
|
|
791
789
|
*/
|
|
792
790
|
purgeUnusedIDs() {
|
|
793
|
-
//Cache the state of the purge mechanism and set it to true
|
|
791
|
+
// Cache the state of the purge mechanism and set it to true
|
|
794
792
|
const oldValue = this.shouldPurgeUnusedIDs;
|
|
795
793
|
this.shouldPurgeUnusedIDs = true;
|
|
796
|
-
//Reassign all ids
|
|
794
|
+
// Reassign all ids
|
|
797
795
|
this._assignIDs(this._identifierCache);
|
|
798
796
|
// Revert the purge mechanism state
|
|
799
797
|
this.shouldPurgeUnusedIDs = oldValue;
|
|
@@ -802,8 +800,8 @@ class Accessory extends events_1.EventEmitter {
|
|
|
802
800
|
* Returns a JSON representation of this accessory suitable for delivering to HAP clients.
|
|
803
801
|
*/
|
|
804
802
|
async toHAP(connection, contactGetHandlers = true) {
|
|
805
|
-
(
|
|
806
|
-
(
|
|
803
|
+
assert(this.aid, `aid cannot be undefined for accessory '${this.displayName}'`);
|
|
804
|
+
assert(this.services.length, `accessory '${this.displayName}' does not have any services!`);
|
|
807
805
|
const accessory = {
|
|
808
806
|
aid: this.aid,
|
|
809
807
|
services: await Promise.all(this.services.map(service => service.toHAP(connection, contactGetHandlers))),
|
|
@@ -822,8 +820,8 @@ class Accessory extends events_1.EventEmitter {
|
|
|
822
820
|
if (assignIds) {
|
|
823
821
|
this._assignIDs(this._identifierCache); // make sure our aid/iid's are all assigned
|
|
824
822
|
}
|
|
825
|
-
(
|
|
826
|
-
(
|
|
823
|
+
assert(this.aid, `aid cannot be undefined for accessory '${this.displayName}'`);
|
|
824
|
+
assert(this.services.length, `accessory '${this.displayName}' does not have any services!`);
|
|
827
825
|
const accessory = {
|
|
828
826
|
aid: this.aid,
|
|
829
827
|
services: this.services.map(service => service.internalHAPRepresentation()),
|
|
@@ -855,43 +853,45 @@ class Accessory extends events_1.EventEmitter {
|
|
|
855
853
|
*/
|
|
856
854
|
async publish(info, allowInsecureRequest) {
|
|
857
855
|
if (this.bridged) {
|
|
858
|
-
throw new Error(
|
|
856
|
+
throw new Error(`Can't publish in accessory which is bridged by another accessory. Bridged by ${this.bridge?.displayName}`);
|
|
859
857
|
}
|
|
860
858
|
/* Bridged accessories with malformed permissions are quarantined at the serving boundary, but the accessory being published is the root of its own
|
|
861
859
|
* accessory database and has nowhere to be quarantined to. HomeKit would reject the whole database, so we refuse here instead, in the caller's stack.
|
|
862
860
|
*/
|
|
863
861
|
const violation = this.findPermsViolation();
|
|
864
862
|
if (violation) {
|
|
865
|
-
throw new Error(this.permsViolationMessage(violation,
|
|
863
|
+
throw new Error(this.permsViolationMessage(violation, 'cannot be published'));
|
|
866
864
|
}
|
|
867
|
-
let service = this.getService(
|
|
865
|
+
let service = this.getService(Service.ProtocolInformation);
|
|
868
866
|
if (!service) {
|
|
869
|
-
service = this.addService(
|
|
867
|
+
service = this.addService(Service.ProtocolInformation); // add the protocol information service to the primary accessory
|
|
870
868
|
}
|
|
871
|
-
service.setCharacteristic(
|
|
872
|
-
hksvDebug(
|
|
869
|
+
service.setCharacteristic(Characteristic.Version, CiaoAdvertiser.protocolVersionService);
|
|
870
|
+
hksvDebug('[%s] publish: UUID=%s lastKnownUsername=%s newUsername=%s', this.displayName, this.UUID, this.lastKnownUsername, info.username);
|
|
873
871
|
if (this.lastKnownUsername && this.lastKnownUsername !== info.username) { // username changed since last publish
|
|
874
|
-
hksvDebug(
|
|
872
|
+
hksvDebug('[%s] publish: wiping data for previous username %s', this.displayName, this.lastKnownUsername);
|
|
875
873
|
Accessory.cleanupAccessoryData(this.lastKnownUsername); // delete old Accessory data
|
|
876
874
|
}
|
|
877
875
|
if (!this.initialized && (info.addIdentifyingMaterial ?? true)) {
|
|
878
876
|
// adding some identifying material to our displayName if it's our first publish() call
|
|
879
|
-
this.displayName = this.displayName
|
|
880
|
-
.update(info.username,
|
|
881
|
-
.digest(
|
|
882
|
-
|
|
877
|
+
this.displayName = `${this.displayName} ${crypto.createHash('sha512')
|
|
878
|
+
.update(info.username, 'utf8')
|
|
879
|
+
.digest('hex')
|
|
880
|
+
.slice(0, 4)
|
|
881
|
+
.toUpperCase()}`;
|
|
882
|
+
this.getService(Service.AccessoryInformation).updateCharacteristic(Characteristic.Name, this.displayName);
|
|
883
883
|
}
|
|
884
884
|
// attempt to load existing AccessoryInfo from disk
|
|
885
|
-
this._accessoryInfo =
|
|
885
|
+
this._accessoryInfo = AccessoryInfo.load(info.username);
|
|
886
886
|
// if we don't have one, create a new one.
|
|
887
887
|
if (!this._accessoryInfo) {
|
|
888
|
-
debug(
|
|
889
|
-
this._accessoryInfo =
|
|
888
|
+
debug('[%s] Creating new AccessoryInfo for our HAP server', this.displayName);
|
|
889
|
+
this._accessoryInfo = AccessoryInfo.create(info.username);
|
|
890
890
|
}
|
|
891
891
|
if (info.setupID) {
|
|
892
892
|
this._setupID = info.setupID;
|
|
893
893
|
}
|
|
894
|
-
else if (this._accessoryInfo.setupID === undefined || this._accessoryInfo.setupID ===
|
|
894
|
+
else if (this._accessoryInfo.setupID === undefined || this._accessoryInfo.setupID === '') {
|
|
895
895
|
this._setupID = Accessory._generateSetupID();
|
|
896
896
|
}
|
|
897
897
|
else {
|
|
@@ -900,16 +900,16 @@ class Accessory extends events_1.EventEmitter {
|
|
|
900
900
|
this._accessoryInfo.setupID = this._setupID;
|
|
901
901
|
// make sure we have up-to-date values in AccessoryInfo, then save it in case they changed (or if we just created it)
|
|
902
902
|
this._accessoryInfo.displayName = this.displayName;
|
|
903
|
-
this._accessoryInfo.model = this.getService(
|
|
903
|
+
this._accessoryInfo.model = this.getService(Service.AccessoryInformation).getCharacteristic(Characteristic.Model).value;
|
|
904
904
|
this._accessoryInfo.category = info.category || 1 /* Categories.OTHER */;
|
|
905
905
|
this._accessoryInfo.pincode = info.pincode;
|
|
906
906
|
this._accessoryInfo.save();
|
|
907
907
|
// create our IdentifierCache, so we can provide clients with stable aid/iid's
|
|
908
|
-
this._identifierCache =
|
|
908
|
+
this._identifierCache = IdentifierCache.load(info.username);
|
|
909
909
|
// if we don't have one, create a new one.
|
|
910
910
|
if (!this._identifierCache) {
|
|
911
|
-
debug(
|
|
912
|
-
this._identifierCache = new
|
|
911
|
+
debug('[%s] Creating new IdentifierCache', this.displayName);
|
|
912
|
+
this._identifierCache = new IdentifierCache(info.username);
|
|
913
913
|
}
|
|
914
914
|
// If it's bridge and there are no accessories already assigned to the bridge
|
|
915
915
|
// probably purge is not needed since it's going to delete all the ids
|
|
@@ -935,15 +935,15 @@ class Accessory extends events_1.EventEmitter {
|
|
|
935
935
|
// create our Advertiser which broadcasts our presence over mdns
|
|
936
936
|
const parsed = Accessory.parseBindOption(info);
|
|
937
937
|
info.advertiser ??= "ciao" /* MDNSAdvertiser.CIAO */;
|
|
938
|
-
if ((info.advertiser === "avahi" /* MDNSAdvertiser.AVAHI */ && !await
|
|
939
|
-
(info.advertiser === "resolved" /* MDNSAdvertiser.RESOLVED */ && !await
|
|
940
|
-
console.error(`[${this.displayName}] The selected advertiser, "${info.advertiser}", isn't available on this platform. `
|
|
941
|
-
`Reverting to "${"ciao" /* MDNSAdvertiser.CIAO */}"`);
|
|
938
|
+
if ((info.advertiser === "avahi" /* MDNSAdvertiser.AVAHI */ && !await AvahiAdvertiser.isAvailable())
|
|
939
|
+
|| (info.advertiser === "resolved" /* MDNSAdvertiser.RESOLVED */ && !await ResolvedAdvertiser.isAvailable())) {
|
|
940
|
+
console.error(`[${this.displayName}] The selected advertiser, "${info.advertiser}", isn't available on this platform. `
|
|
941
|
+
+ `Reverting to "${"ciao" /* MDNSAdvertiser.CIAO */}"`);
|
|
942
942
|
info.advertiser = "ciao" /* MDNSAdvertiser.CIAO */;
|
|
943
943
|
}
|
|
944
944
|
switch (info.advertiser) {
|
|
945
945
|
case "ciao" /* MDNSAdvertiser.CIAO */:
|
|
946
|
-
this._advertiser = new
|
|
946
|
+
this._advertiser = new CiaoAdvertiser(this._accessoryInfo, {
|
|
947
947
|
interface: parsed.advertiserAddress,
|
|
948
948
|
}, {
|
|
949
949
|
restrictedAddresses: parsed.serviceRestrictedAddress,
|
|
@@ -951,32 +951,32 @@ class Accessory extends events_1.EventEmitter {
|
|
|
951
951
|
});
|
|
952
952
|
break;
|
|
953
953
|
case "bonjour-hap" /* MDNSAdvertiser.BONJOUR */:
|
|
954
|
-
this._advertiser = new
|
|
954
|
+
this._advertiser = new BonjourHAPAdvertiser(this._accessoryInfo, {
|
|
955
955
|
restrictedAddresses: parsed.serviceRestrictedAddress,
|
|
956
956
|
disabledIpv6: parsed.serviceDisableIpv6,
|
|
957
957
|
});
|
|
958
958
|
break;
|
|
959
959
|
case "avahi" /* MDNSAdvertiser.AVAHI */:
|
|
960
|
-
this._advertiser = new
|
|
960
|
+
this._advertiser = new AvahiAdvertiser(this._accessoryInfo);
|
|
961
961
|
break;
|
|
962
962
|
case "resolved" /* MDNSAdvertiser.RESOLVED */:
|
|
963
|
-
this._advertiser = new
|
|
963
|
+
this._advertiser = new ResolvedAdvertiser(this._accessoryInfo);
|
|
964
964
|
break;
|
|
965
965
|
default:
|
|
966
|
-
throw new Error(
|
|
966
|
+
throw new Error(`Unsupported advertiser setting: '${info.advertiser}'`);
|
|
967
967
|
}
|
|
968
|
-
this._advertiser.on("updated-name" /* AdvertiserEvent.UPDATED_NAME */, name => {
|
|
968
|
+
this._advertiser.on("updated-name" /* AdvertiserEvent.UPDATED_NAME */, (name) => {
|
|
969
969
|
this.displayName = name;
|
|
970
970
|
if (this._accessoryInfo) {
|
|
971
971
|
this._accessoryInfo.displayName = name;
|
|
972
972
|
this._accessoryInfo.save();
|
|
973
973
|
}
|
|
974
974
|
// bonjour service name MUST match the name in the accessory information service
|
|
975
|
-
this.getService(
|
|
976
|
-
.updateCharacteristic(
|
|
975
|
+
this.getService(Service.AccessoryInformation)
|
|
976
|
+
.updateCharacteristic(Characteristic.Name, name);
|
|
977
977
|
});
|
|
978
978
|
// create our HAP server which handles all communication between iOS devices and us
|
|
979
|
-
this._server = new
|
|
979
|
+
this._server = new HAPServer(this._accessoryInfo);
|
|
980
980
|
this._server.allowInsecureRequest = !!allowInsecureRequest;
|
|
981
981
|
this._server.on("listening" /* HAPServerEventTypes.LISTENING */, this.onListening.bind(this));
|
|
982
982
|
this._server.on("identify" /* HAPServerEventTypes.IDENTIFY */, this.identificationRequest.bind(this, false));
|
|
@@ -1003,7 +1003,7 @@ class Accessory extends events_1.EventEmitter {
|
|
|
1003
1003
|
Accessory.cleanupAccessoryData(this._accessoryInfo.username);
|
|
1004
1004
|
this._accessoryInfo = undefined;
|
|
1005
1005
|
this._identifierCache = undefined;
|
|
1006
|
-
this.controllerStorage = new
|
|
1006
|
+
this.controllerStorage = new ControllerStorage(this);
|
|
1007
1007
|
}
|
|
1008
1008
|
this.removeAllListeners();
|
|
1009
1009
|
return promise;
|
|
@@ -1041,21 +1041,21 @@ class Accessory extends events_1.EventEmitter {
|
|
|
1041
1041
|
// not responding or new accessories/services not yet shown
|
|
1042
1042
|
}
|
|
1043
1043
|
onListening(port, hostname) {
|
|
1044
|
-
(
|
|
1044
|
+
assert(this._advertiser, 'Advertiser wasn\'t created at onListening!');
|
|
1045
1045
|
// the HAP server is listening, so we can now start advertising our presence.
|
|
1046
1046
|
this._advertiser.initPort(port);
|
|
1047
1047
|
this._advertiser.startAdvertising()
|
|
1048
1048
|
.then(() => this.emit("advertised" /* AccessoryEventTypes.ADVERTISED */))
|
|
1049
|
-
.catch(reason => {
|
|
1050
|
-
console.error(
|
|
1049
|
+
.catch((reason) => {
|
|
1050
|
+
console.error(`Could not create mDNS advertisement. The HAP-Server won't be discoverable: ${reason}`);
|
|
1051
1051
|
if (reason.stack) {
|
|
1052
|
-
debug(
|
|
1052
|
+
debug(`Detailed error: ${reason.stack}`);
|
|
1053
1053
|
}
|
|
1054
1054
|
});
|
|
1055
1055
|
this.emit("listening" /* AccessoryEventTypes.LISTENING */, port, hostname);
|
|
1056
1056
|
}
|
|
1057
1057
|
handleInitialPairSetupFinished(username, publicKey, callback) {
|
|
1058
|
-
debug(
|
|
1058
|
+
debug('[%s] Paired with client %s', this.displayName, username);
|
|
1059
1059
|
if (this._accessoryInfo) {
|
|
1060
1060
|
this._accessoryInfo.addPairedClient(username, publicKey, 1 /* PermissionTypes.ADMIN */);
|
|
1061
1061
|
this._accessoryInfo.save();
|
|
@@ -1130,17 +1130,17 @@ class Accessory extends events_1.EventEmitter {
|
|
|
1130
1130
|
const now = Date.now();
|
|
1131
1131
|
const contactGetHandlers = now - this.lastAccessoriesRequest > 5_000; // we query the latest value if last /accessories was more than 5s ago
|
|
1132
1132
|
this.lastAccessoriesRequest = now;
|
|
1133
|
-
this.toHAP(connection, contactGetHandlers).then(value => {
|
|
1133
|
+
this.toHAP(connection, contactGetHandlers).then((value) => {
|
|
1134
1134
|
callback(undefined, {
|
|
1135
1135
|
accessories: value,
|
|
1136
1136
|
});
|
|
1137
|
-
}, reason => {
|
|
1138
|
-
console.error(
|
|
1137
|
+
}, (reason) => {
|
|
1138
|
+
console.error(`[${this.displayName}] /accessories request error with: ${reason.stack}`);
|
|
1139
1139
|
callback({ httpCode: 500 /* HAPHTTPCode.INTERNAL_SERVER_ERROR */, status: -70402 /* HAPStatus.SERVICE_COMMUNICATION_FAILURE */ });
|
|
1140
1140
|
});
|
|
1141
1141
|
}
|
|
1142
1142
|
handleGetCharacteristics(connection, request, callback) {
|
|
1143
|
-
this.handleCharacteristicRequests(request.ids,
|
|
1143
|
+
this.handleCharacteristicRequests(request.ids, 'read', id => this.handleCharacteristicRead(connection, id, request), (error, characteristics) => callback(error, characteristics && { characteristics }));
|
|
1144
1144
|
}
|
|
1145
1145
|
/**
|
|
1146
1146
|
* Runs the handler for every characteristic of a `/characteristics` read or write request, and answers once all of them settled.
|
|
@@ -1174,12 +1174,12 @@ class Accessory extends events_1.EventEmitter {
|
|
|
1174
1174
|
if (!accessory || !characteristic) {
|
|
1175
1175
|
continue;
|
|
1176
1176
|
}
|
|
1177
|
-
const type = operation ===
|
|
1177
|
+
const type = operation === 'read'
|
|
1178
1178
|
? (slow ? "slow-read" /* CharacteristicWarningType.SLOW_READ */ : "timeout-read" /* CharacteristicWarningType.TIMEOUT_READ */)
|
|
1179
1179
|
: (slow ? "slow-write" /* CharacteristicWarningType.SLOW_WRITE */ : "timeout-write" /* CharacteristicWarningType.TIMEOUT_WRITE */);
|
|
1180
1180
|
const message = slow
|
|
1181
|
-
?
|
|
1182
|
-
:
|
|
1181
|
+
? 'was slow to respond!'
|
|
1182
|
+
: 'didn\'t respond at all!. Please check that you properly call the callback!';
|
|
1183
1183
|
accessory.sendCharacteristicWarning(characteristic, type, `The ${operation} handler for the characteristic '${characteristic.displayName}' on the accessory '${accessory.displayName}' ${message}`);
|
|
1184
1184
|
if (!slow) {
|
|
1185
1185
|
characteristics.push({
|
|
@@ -1210,7 +1210,9 @@ class Accessory extends events_1.EventEmitter {
|
|
|
1210
1210
|
...value,
|
|
1211
1211
|
};
|
|
1212
1212
|
}, (reason) => {
|
|
1213
|
-
console.error(`[${this.displayName}] ${operation ===
|
|
1213
|
+
console.error(`[${this.displayName}] ${operation === 'read'
|
|
1214
|
+
? 'Read'
|
|
1215
|
+
: 'Write'} request for characteristic ${name} encountered an error: ${reason.stack}`);
|
|
1214
1216
|
return {
|
|
1215
1217
|
aid: id.aid,
|
|
1216
1218
|
iid: id.iid,
|
|
@@ -1233,27 +1235,27 @@ class Accessory extends events_1.EventEmitter {
|
|
|
1233
1235
|
async handleCharacteristicRead(connection, id, request) {
|
|
1234
1236
|
const characteristic = this.findCharacteristic(id.aid, id.iid);
|
|
1235
1237
|
if (!characteristic) {
|
|
1236
|
-
debug(
|
|
1238
|
+
debug('[%s] Could not find a Characteristic with aid of %s and iid of %s', this.displayName, id.aid, id.iid);
|
|
1237
1239
|
return { status: -70410 /* HAPStatus.INVALID_VALUE_IN_REQUEST */ };
|
|
1238
1240
|
}
|
|
1239
1241
|
if (!characteristic.props.perms.includes("pr" /* Perms.PAIRED_READ */)) { // check if read is allowed for this characteristic
|
|
1240
|
-
debug(
|
|
1242
|
+
debug('[%s] Tried reading from characteristic which does not allow reading (aid of %s and iid of %s)', this.displayName, id.aid, id.iid);
|
|
1241
1243
|
return { status: -70405 /* HAPStatus.WRITE_ONLY_CHARACTERISTIC */ };
|
|
1242
1244
|
}
|
|
1243
1245
|
if (characteristic.props.adminOnlyAccess && characteristic.props.adminOnlyAccess.includes(0 /* Access.READ */)) {
|
|
1244
1246
|
const verifiable = this._accessoryInfo && connection.username;
|
|
1245
1247
|
if (!verifiable) {
|
|
1246
|
-
debug(
|
|
1248
|
+
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);
|
|
1247
1249
|
}
|
|
1248
1250
|
if (!verifiable || !this._accessoryInfo.hasAdminPermissions(connection.username)) {
|
|
1249
1251
|
return { status: -70401 /* HAPStatus.INSUFFICIENT_PRIVILEGES */ };
|
|
1250
1252
|
}
|
|
1251
1253
|
}
|
|
1252
|
-
return characteristic.handleGetRequest(connection).then(value => {
|
|
1253
|
-
value =
|
|
1254
|
-
debug(
|
|
1254
|
+
return characteristic.handleGetRequest(connection).then((value) => {
|
|
1255
|
+
value = formatOutgoingCharacteristicValue(value, characteristic.props);
|
|
1256
|
+
debug('[%s] Got Characteristic "%s" value: "%s"', this.displayName, characteristic.displayName, value);
|
|
1255
1257
|
const data = {
|
|
1256
|
-
value: value
|
|
1258
|
+
value: value ?? null,
|
|
1257
1259
|
};
|
|
1258
1260
|
if (request.includeMeta) {
|
|
1259
1261
|
data.format = characteristic.props.format;
|
|
@@ -1267,7 +1269,7 @@ class Accessory extends events_1.EventEmitter {
|
|
|
1267
1269
|
data.perms = characteristic.props.perms;
|
|
1268
1270
|
}
|
|
1269
1271
|
if (request.includeType) {
|
|
1270
|
-
data.type =
|
|
1272
|
+
data.type = toShortForm(characteristic.UUID);
|
|
1271
1273
|
}
|
|
1272
1274
|
if (request.includeEvent) {
|
|
1273
1275
|
data.ev = connection.hasEventNotifications(id.aid, id.iid);
|
|
@@ -1275,13 +1277,13 @@ class Accessory extends events_1.EventEmitter {
|
|
|
1275
1277
|
return data;
|
|
1276
1278
|
}, (reason) => {
|
|
1277
1279
|
// @ts-expect-error: preserveConstEnums compiler option
|
|
1278
|
-
debug(
|
|
1280
|
+
debug('[%s] Error getting value for characteristic "%s": %s', this.displayName, characteristic.displayName, HAPStatus[reason]);
|
|
1279
1281
|
return { status: reason };
|
|
1280
1282
|
});
|
|
1281
1283
|
}
|
|
1282
1284
|
handleSetCharacteristics(connection, writeRequest, callback) {
|
|
1283
1285
|
if (debug.enabled) { // the request can be large, so only serialize it when it gets logged
|
|
1284
|
-
debug(
|
|
1286
|
+
debug('[%s] Processing characteristic set: %s', this.displayName, JSON.stringify(writeRequest));
|
|
1285
1287
|
}
|
|
1286
1288
|
let writeState = 0 /* WriteRequestState.REGULAR_REQUEST */;
|
|
1287
1289
|
if (writeRequest.pid !== undefined) { // check for timed writes
|
|
@@ -1290,19 +1292,19 @@ class Accessory extends events_1.EventEmitter {
|
|
|
1290
1292
|
clearTimeout(connection.timedWriteTimeout);
|
|
1291
1293
|
connection.timedWritePid = undefined;
|
|
1292
1294
|
connection.timedWriteTimeout = undefined;
|
|
1293
|
-
debug(
|
|
1295
|
+
debug('[%s] Timed write request got acknowledged for pid %d', this.displayName, writeRequest.pid);
|
|
1294
1296
|
}
|
|
1295
1297
|
else {
|
|
1296
1298
|
writeState = 2 /* WriteRequestState.TIMED_WRITE_REJECTED */;
|
|
1297
|
-
debug(
|
|
1299
|
+
debug('[%s] TTL for timed write request has probably expired for pid %d', this.displayName, writeRequest.pid);
|
|
1298
1300
|
}
|
|
1299
1301
|
}
|
|
1300
|
-
this.handleCharacteristicRequests(writeRequest.characteristics,
|
|
1302
|
+
this.handleCharacteristicRequests(writeRequest.characteristics, 'write', data => this.handleCharacteristicWrite(connection, data, writeState), (error, characteristics) => callback(error, characteristics && { characteristics }));
|
|
1301
1303
|
}
|
|
1302
1304
|
async handleCharacteristicWrite(connection, data, writeState) {
|
|
1303
1305
|
const characteristic = this.findCharacteristic(data.aid, data.iid);
|
|
1304
1306
|
if (!characteristic) {
|
|
1305
|
-
debug(
|
|
1307
|
+
debug('[%s] Could not find a Characteristic with aid of %s and iid of %s', this.displayName, data.aid, data.iid);
|
|
1306
1308
|
return { status: -70410 /* HAPStatus.INVALID_VALUE_IN_REQUEST */ };
|
|
1307
1309
|
}
|
|
1308
1310
|
if (writeState === 2 /* WriteRequestState.TIMED_WRITE_REJECTED */) {
|
|
@@ -1313,13 +1315,13 @@ class Accessory extends events_1.EventEmitter {
|
|
|
1313
1315
|
}
|
|
1314
1316
|
if (data.ev != null) { // register/unregister event notifications
|
|
1315
1317
|
if (!characteristic.props.perms.includes("ev" /* Perms.NOTIFY */)) { // check if notify is allowed for this characteristic
|
|
1316
|
-
debug(
|
|
1318
|
+
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);
|
|
1317
1319
|
return { status: -70406 /* HAPStatus.NOTIFICATION_NOT_SUPPORTED */ };
|
|
1318
1320
|
}
|
|
1319
1321
|
if (characteristic.props.adminOnlyAccess && characteristic.props.adminOnlyAccess.includes(2 /* Access.NOTIFY */)) {
|
|
1320
1322
|
const verifiable = connection.username && this._accessoryInfo;
|
|
1321
1323
|
if (!verifiable) {
|
|
1322
|
-
debug(
|
|
1324
|
+
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);
|
|
1323
1325
|
}
|
|
1324
1326
|
if (!verifiable || !this._accessoryInfo.hasAdminPermissions(connection.username)) {
|
|
1325
1327
|
return { status: -70401 /* HAPStatus.INSUFFICIENT_PRIVILEGES */ };
|
|
@@ -1329,24 +1331,24 @@ class Accessory extends events_1.EventEmitter {
|
|
|
1329
1331
|
if (data.ev && !notificationsEnabled) {
|
|
1330
1332
|
connection.enableEventNotifications(data.aid, data.iid);
|
|
1331
1333
|
characteristic.subscribe();
|
|
1332
|
-
debug(
|
|
1334
|
+
debug('[%s] Registered Characteristic "%s" on "%s" for events', connection.remoteAddress, characteristic.displayName, this.displayName);
|
|
1333
1335
|
}
|
|
1334
1336
|
else if (!data.ev && notificationsEnabled) {
|
|
1335
1337
|
characteristic.unsubscribe();
|
|
1336
1338
|
connection.disableEventNotifications(data.aid, data.iid);
|
|
1337
|
-
debug(
|
|
1339
|
+
debug('[%s] Unregistered Characteristic "%s" on "%s" for events', connection.remoteAddress, characteristic.displayName, this.displayName);
|
|
1338
1340
|
}
|
|
1339
1341
|
// response is returned below in the else block
|
|
1340
1342
|
}
|
|
1341
1343
|
if (data.value != null) {
|
|
1342
1344
|
if (!characteristic.props.perms.includes("pw" /* Perms.PAIRED_WRITE */)) { // check if write is allowed for this characteristic
|
|
1343
|
-
debug(
|
|
1345
|
+
debug('[%s] Tried writing to Characteristic which does not allow writing (aid of %s and iid of %s)', this.displayName, data.aid, data.iid);
|
|
1344
1346
|
return { status: -70404 /* HAPStatus.READ_ONLY_CHARACTERISTIC */ };
|
|
1345
1347
|
}
|
|
1346
1348
|
if (characteristic.props.adminOnlyAccess && characteristic.props.adminOnlyAccess.includes(1 /* Access.WRITE */)) {
|
|
1347
1349
|
const verifiable = connection.username && this._accessoryInfo;
|
|
1348
1350
|
if (!verifiable) {
|
|
1349
|
-
debug(
|
|
1351
|
+
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);
|
|
1350
1352
|
}
|
|
1351
1353
|
if (!verifiable || !this._accessoryInfo.hasAdminPermissions(connection.username)) {
|
|
1352
1354
|
return { status: -70401 /* HAPStatus.INSUFFICIENT_PRIVILEGES */ };
|
|
@@ -1360,7 +1362,7 @@ class Accessory extends events_1.EventEmitter {
|
|
|
1360
1362
|
allowWrite = characteristic.additionalAuthorizationHandler(data.authData);
|
|
1361
1363
|
}
|
|
1362
1364
|
catch (error) {
|
|
1363
|
-
console.warn(
|
|
1365
|
+
console.warn(`[${this.displayName}] Additional authorization handler has thrown an error when checking authData: ${error.stack}`);
|
|
1364
1366
|
allowWrite = false;
|
|
1365
1367
|
}
|
|
1366
1368
|
if (!allowWrite) {
|
|
@@ -1368,7 +1370,7 @@ class Accessory extends events_1.EventEmitter {
|
|
|
1368
1370
|
}
|
|
1369
1371
|
}
|
|
1370
1372
|
if (characteristic.props.perms.includes("tw" /* Perms.TIMED_WRITE */) && writeState !== 1 /* WriteRequestState.TIMED_WRITE_AUTHENTICATED */) {
|
|
1371
|
-
debug(
|
|
1373
|
+
debug('[%s] Tried writing to a timed write only Characteristic without properly preparing (iid of %s and aid of %s)', this.displayName, data.aid, data.iid);
|
|
1372
1374
|
return { status: -70410 /* HAPStatus.INVALID_VALUE_IN_REQUEST */ };
|
|
1373
1375
|
}
|
|
1374
1376
|
const accessory = this.getAccessoryByAID(data.aid);
|
|
@@ -1378,25 +1380,27 @@ class Accessory extends events_1.EventEmitter {
|
|
|
1378
1380
|
}
|
|
1379
1381
|
return value;
|
|
1380
1382
|
}).then((value) => {
|
|
1381
|
-
debug(
|
|
1383
|
+
debug('[%s] Setting Characteristic "%s" to value %s', this.displayName, characteristic.displayName, data.value);
|
|
1382
1384
|
return {
|
|
1383
1385
|
// if write response is requests and value is provided, return that
|
|
1384
|
-
value: data.r && value
|
|
1386
|
+
value: data.r && value
|
|
1387
|
+
? formatOutgoingCharacteristicValue(value, characteristic.props)
|
|
1388
|
+
: undefined,
|
|
1385
1389
|
status: 0 /* HAPStatus.SUCCESS */,
|
|
1386
1390
|
};
|
|
1387
1391
|
}, (status) => {
|
|
1388
1392
|
// @ts-expect-error: forceConsistentCasingInFileNames compiler option
|
|
1389
|
-
debug(
|
|
1390
|
-
return { status
|
|
1393
|
+
debug('[%s] Error setting Characteristic "%s" to value %s: ', this.displayName, characteristic.displayName, data.value, HAPStatus[status]);
|
|
1394
|
+
return { status };
|
|
1391
1395
|
});
|
|
1392
1396
|
}
|
|
1393
1397
|
return { status: 0 /* HAPStatus.SUCCESS */ };
|
|
1394
1398
|
}
|
|
1395
1399
|
handleResource(data, callback) {
|
|
1396
|
-
if (data[
|
|
1400
|
+
if (data['resource-type'] === "image" /* ResourceRequestType.IMAGE */) {
|
|
1397
1401
|
const aid = data.aid; // aid is optionally supplied by HomeKit (for example when camera is bridged, multiple cams, etc)
|
|
1398
|
-
let accessory
|
|
1399
|
-
let controller
|
|
1402
|
+
let accessory;
|
|
1403
|
+
let controller;
|
|
1400
1404
|
if (aid) {
|
|
1401
1405
|
accessory = this.getAccessoryByAID(aid);
|
|
1402
1406
|
if (accessory && accessory.activeCameraController) {
|
|
@@ -1404,29 +1408,29 @@ class Accessory extends events_1.EventEmitter {
|
|
|
1404
1408
|
}
|
|
1405
1409
|
}
|
|
1406
1410
|
else if (this.activeCameraController) { // aid was not supplied, check if this accessory is a camera
|
|
1407
|
-
// eslint-disable-next-line
|
|
1411
|
+
// eslint-disable-next-line ts/no-this-alias
|
|
1408
1412
|
accessory = this;
|
|
1409
1413
|
controller = this.activeCameraController;
|
|
1410
1414
|
}
|
|
1411
1415
|
if (!controller) {
|
|
1412
|
-
debug(
|
|
1416
|
+
debug('[%s] received snapshot request though no camera controller was associated!');
|
|
1413
1417
|
callback({ httpCode: 404 /* HAPHTTPCode.NOT_FOUND */, status: -70409 /* HAPStatus.RESOURCE_DOES_NOT_EXIST */ });
|
|
1414
1418
|
return;
|
|
1415
1419
|
}
|
|
1416
|
-
controller.handleSnapshotRequest(data[
|
|
1417
|
-
.then(buffer => {
|
|
1420
|
+
controller.handleSnapshotRequest(data['image-height'], data['image-width'], accessory?.displayName, data.reason)
|
|
1421
|
+
.then((buffer) => {
|
|
1418
1422
|
callback(undefined, buffer);
|
|
1419
1423
|
}, (status) => {
|
|
1420
|
-
callback({ httpCode: 207 /* HAPHTTPCode.MULTI_STATUS */, status
|
|
1424
|
+
callback({ httpCode: 207 /* HAPHTTPCode.MULTI_STATUS */, status });
|
|
1421
1425
|
});
|
|
1422
1426
|
return;
|
|
1423
1427
|
}
|
|
1424
|
-
debug(
|
|
1428
|
+
debug(`[%s] received request for unsupported image type: ${data['resource-type']}`, this._accessoryInfo?.username);
|
|
1425
1429
|
callback({ httpCode: 404 /* HAPHTTPCode.NOT_FOUND */, status: -70409 /* HAPStatus.RESOURCE_DOES_NOT_EXIST */ });
|
|
1426
1430
|
}
|
|
1427
1431
|
handleHAPConnectionClosed(connection) {
|
|
1428
1432
|
for (const event of connection.getRegisteredEvents()) {
|
|
1429
|
-
const ids = event.split(
|
|
1433
|
+
const ids = event.split('.');
|
|
1430
1434
|
if (ids.length < 2) {
|
|
1431
1435
|
continue;
|
|
1432
1436
|
}
|
|
@@ -1452,7 +1456,7 @@ class Accessory extends events_1.EventEmitter {
|
|
|
1452
1456
|
this.primaryService = service;
|
|
1453
1457
|
}
|
|
1454
1458
|
if (this.bridged) {
|
|
1455
|
-
this.emit("service-configurationChange" /* AccessoryEventTypes.SERVICE_CONFIGURATION_CHANGE */, { service
|
|
1459
|
+
this.emit("service-configurationChange" /* AccessoryEventTypes.SERVICE_CONFIGURATION_CHANGE */, { service });
|
|
1456
1460
|
}
|
|
1457
1461
|
else {
|
|
1458
1462
|
this.enqueueConfigurationUpdate();
|
|
@@ -1460,23 +1464,23 @@ class Accessory extends events_1.EventEmitter {
|
|
|
1460
1464
|
}
|
|
1461
1465
|
handleCharacteristicChangeEvent(accessory, service, change) {
|
|
1462
1466
|
if (this.bridged) { // forward this to our main accessory
|
|
1463
|
-
this.emit("service-characteristic-change" /* AccessoryEventTypes.SERVICE_CHARACTERISTIC_CHANGE */, { ...change, service
|
|
1467
|
+
this.emit("service-characteristic-change" /* AccessoryEventTypes.SERVICE_CHARACTERISTIC_CHANGE */, { ...change, service });
|
|
1464
1468
|
}
|
|
1465
1469
|
else {
|
|
1466
1470
|
if (!this._server) {
|
|
1467
1471
|
return; // we're not running a HAPServer, so there's no one to notify about this event
|
|
1468
1472
|
}
|
|
1469
1473
|
if (accessory.aid == null || change.characteristic.iid == null) {
|
|
1470
|
-
debug(
|
|
1474
|
+
debug('[%s] Muting event notification for %s as ids aren\'t yet assigned!', accessory.displayName, change.characteristic.displayName);
|
|
1471
1475
|
return;
|
|
1472
1476
|
}
|
|
1473
|
-
if (change.context != null && typeof change.context ===
|
|
1474
|
-
debug(
|
|
1477
|
+
if (change.context != null && typeof change.context === 'object' && change.context.omitEventUpdate) {
|
|
1478
|
+
debug('[%s] Omitting event updates for %s as specified in the context object!', accessory.displayName, change.characteristic.displayName);
|
|
1475
1479
|
return;
|
|
1476
1480
|
}
|
|
1477
1481
|
if (!(change.reason === "event" /* ChangeReason.EVENT */ || change.oldValue !== change.newValue
|
|
1478
|
-
|| change.characteristic.UUID ===
|
|
1479
|
-
|| change.characteristic.UUID ===
|
|
1482
|
+
|| change.characteristic.UUID === Characteristic.ProgrammableSwitchEvent.UUID // those specific checks are out of backwards compatibility
|
|
1483
|
+
|| change.characteristic.UUID === Characteristic.ButtonEvent.UUID // new characteristics should use sendEventNotification call
|
|
1480
1484
|
)) {
|
|
1481
1485
|
// we only emit a change event if the reason was a call to sendEventNotification, if the value changed
|
|
1482
1486
|
// as of a write request or a read request or if the change happened on dedicated event characteristics
|
|
@@ -1484,18 +1488,19 @@ class Accessory extends events_1.EventEmitter {
|
|
|
1484
1488
|
return;
|
|
1485
1489
|
}
|
|
1486
1490
|
const uuid = change.characteristic.UUID;
|
|
1487
|
-
const immediateDelivery = uuid ===
|
|
1488
|
-
|| uuid ===
|
|
1489
|
-
const value =
|
|
1491
|
+
const immediateDelivery = uuid === Characteristic.ButtonEvent.UUID || uuid === Characteristic.ProgrammableSwitchEvent.UUID
|
|
1492
|
+
|| uuid === Characteristic.MotionDetected.UUID || uuid === Characteristic.ContactSensorState.UUID;
|
|
1493
|
+
const value = formatOutgoingCharacteristicValue(change.newValue, change.characteristic.props);
|
|
1490
1494
|
this._server.sendEventNotifications(accessory.aid, change.characteristic.iid, value, change.originator, immediateDelivery);
|
|
1491
1495
|
}
|
|
1492
1496
|
}
|
|
1493
1497
|
sendCharacteristicWarning(characteristic, type, message) {
|
|
1494
1498
|
this.handleCharacteristicWarning({
|
|
1495
|
-
characteristic
|
|
1496
|
-
type
|
|
1497
|
-
message
|
|
1499
|
+
characteristic,
|
|
1500
|
+
type,
|
|
1501
|
+
message,
|
|
1498
1502
|
originatorChain: [characteristic.displayName], // we are missing the service displayName, but that's okay
|
|
1503
|
+
// eslint-disable-next-line unicorn/error-message -- only here to capture the stack
|
|
1499
1504
|
stack: new Error().stack,
|
|
1500
1505
|
});
|
|
1501
1506
|
}
|
|
@@ -1503,7 +1508,7 @@ class Accessory extends events_1.EventEmitter {
|
|
|
1503
1508
|
warning.originatorChain = [this.displayName, ...warning.originatorChain];
|
|
1504
1509
|
const emitted = this.emit("characteristic-warning" /* AccessoryEventTypes.CHARACTERISTIC_WARNING */, warning);
|
|
1505
1510
|
if (!emitted) {
|
|
1506
|
-
const message = `[${warning.originatorChain.join(
|
|
1511
|
+
const message = `[${warning.originatorChain.join('@')}] ${warning.message}`;
|
|
1507
1512
|
if (warning.type === "error-message" /* CharacteristicWarningType.ERROR_MESSAGE */
|
|
1508
1513
|
|| warning.type === "timeout-read" /* CharacteristicWarningType.TIMEOUT_READ */ || warning.type === "timeout-write" /* CharacteristicWarningType.TIMEOUT_WRITE */) {
|
|
1509
1514
|
console.error(message);
|
|
@@ -1511,7 +1516,7 @@ class Accessory extends events_1.EventEmitter {
|
|
|
1511
1516
|
else {
|
|
1512
1517
|
console.warn(message);
|
|
1513
1518
|
}
|
|
1514
|
-
debug(
|
|
1519
|
+
debug('[%s] Above characteristic warning was thrown at: %s', this.displayName, warning.stack ?? 'unknown');
|
|
1515
1520
|
}
|
|
1516
1521
|
}
|
|
1517
1522
|
setupServiceEventHandlers(service) {
|
|
@@ -1538,9 +1543,9 @@ class Accessory extends events_1.EventEmitter {
|
|
|
1538
1543
|
}
|
|
1539
1544
|
}
|
|
1540
1545
|
static _generateSetupID() {
|
|
1541
|
-
const chars =
|
|
1546
|
+
const chars = '0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ';
|
|
1542
1547
|
const max = chars.length;
|
|
1543
|
-
let setupID =
|
|
1548
|
+
let setupID = '';
|
|
1544
1549
|
for (let i = 0; i < 4; i++) {
|
|
1545
1550
|
const index = Math.floor(Math.random() * max);
|
|
1546
1551
|
setupID += chars.charAt(index);
|
|
@@ -1558,10 +1563,10 @@ class Accessory extends events_1.EventEmitter {
|
|
|
1558
1563
|
};
|
|
1559
1564
|
const linkedServices = {};
|
|
1560
1565
|
let hasLinkedServices = false;
|
|
1561
|
-
accessory.services.forEach(service => {
|
|
1562
|
-
json.services.push(
|
|
1566
|
+
accessory.services.forEach((service) => {
|
|
1567
|
+
json.services.push(Service.serialize(service));
|
|
1563
1568
|
const linkedServicesPresentation = [];
|
|
1564
|
-
service.linkedServices.forEach(linkedService => {
|
|
1569
|
+
service.linkedServices.forEach((linkedService) => {
|
|
1565
1570
|
linkedServicesPresentation.push(linkedService.getServiceId());
|
|
1566
1571
|
});
|
|
1567
1572
|
if (linkedServicesPresentation.length > 0) {
|
|
@@ -1600,8 +1605,8 @@ class Accessory extends events_1.EventEmitter {
|
|
|
1600
1605
|
accessory.category = json.category;
|
|
1601
1606
|
const services = [];
|
|
1602
1607
|
const servicesMap = {};
|
|
1603
|
-
json.services.forEach(serialized => {
|
|
1604
|
-
const service =
|
|
1608
|
+
json.services.forEach((serialized) => {
|
|
1609
|
+
const service = Service.deserialize(serialized);
|
|
1605
1610
|
services.push(service);
|
|
1606
1611
|
servicesMap[service.getServiceId()] = service;
|
|
1607
1612
|
});
|
|
@@ -1611,7 +1616,7 @@ class Accessory extends events_1.EventEmitter {
|
|
|
1611
1616
|
if (!primaryService) {
|
|
1612
1617
|
continue;
|
|
1613
1618
|
}
|
|
1614
|
-
linkedServicesKeys.forEach(linkedServiceKey => {
|
|
1619
|
+
linkedServicesKeys.forEach((linkedServiceKey) => {
|
|
1615
1620
|
const linkedService = servicesMap[linkedServiceKey];
|
|
1616
1621
|
if (linkedService) {
|
|
1617
1622
|
primaryService.addLinkedService(linkedService);
|
|
@@ -1621,7 +1626,7 @@ class Accessory extends events_1.EventEmitter {
|
|
|
1621
1626
|
}
|
|
1622
1627
|
if (json.controllers) { // just save it for later if it exists {@see configureController}
|
|
1623
1628
|
accessory.serializedControllers = {};
|
|
1624
|
-
json.controllers.forEach(serializedController => {
|
|
1629
|
+
json.controllers.forEach((serializedController) => {
|
|
1625
1630
|
accessory.serializedControllers[serializedController.type] = Accessory.deserializeServiceMap(serializedController.services, servicesMap);
|
|
1626
1631
|
});
|
|
1627
1632
|
}
|
|
@@ -1629,9 +1634,9 @@ class Accessory extends events_1.EventEmitter {
|
|
|
1629
1634
|
return accessory;
|
|
1630
1635
|
}
|
|
1631
1636
|
static cleanupAccessoryData(username) {
|
|
1632
|
-
|
|
1633
|
-
|
|
1634
|
-
|
|
1637
|
+
IdentifierCache.remove(username);
|
|
1638
|
+
AccessoryInfo.remove(username);
|
|
1639
|
+
ControllerStorage.remove(username);
|
|
1635
1640
|
}
|
|
1636
1641
|
static serializeServiceMap(serviceMap) {
|
|
1637
1642
|
const serialized = {};
|
|
@@ -1654,22 +1659,24 @@ class Accessory extends events_1.EventEmitter {
|
|
|
1654
1659
|
return controllerServiceMap;
|
|
1655
1660
|
}
|
|
1656
1661
|
static parseBindOption(info) {
|
|
1657
|
-
let advertiserAddress
|
|
1658
|
-
let disableIpv6
|
|
1659
|
-
let serverAddress
|
|
1662
|
+
let advertiserAddress;
|
|
1663
|
+
let disableIpv6;
|
|
1664
|
+
let serverAddress;
|
|
1660
1665
|
if (info.bind) {
|
|
1661
|
-
const entries = new Set(Array.isArray(info.bind)
|
|
1662
|
-
|
|
1663
|
-
|
|
1664
|
-
|
|
1666
|
+
const entries = new Set(Array.isArray(info.bind)
|
|
1667
|
+
? info.bind
|
|
1668
|
+
: [info.bind]);
|
|
1669
|
+
if (entries.has('::')) {
|
|
1670
|
+
serverAddress = '::';
|
|
1671
|
+
entries.delete('::');
|
|
1665
1672
|
if (entries.size) {
|
|
1666
1673
|
advertiserAddress = Array.from(entries);
|
|
1667
1674
|
}
|
|
1668
1675
|
}
|
|
1669
|
-
else if (entries.has(
|
|
1676
|
+
else if (entries.has('0.0.0.0')) {
|
|
1670
1677
|
disableIpv6 = true;
|
|
1671
|
-
serverAddress =
|
|
1672
|
-
entries.delete(
|
|
1678
|
+
serverAddress = '0.0.0.0';
|
|
1679
|
+
entries.delete('0.0.0.0');
|
|
1673
1680
|
if (entries.size) {
|
|
1674
1681
|
advertiserAddress = Array.from(entries);
|
|
1675
1682
|
}
|
|
@@ -1677,39 +1684,40 @@ class Accessory extends events_1.EventEmitter {
|
|
|
1677
1684
|
else if (entries.size === 1) {
|
|
1678
1685
|
advertiserAddress = Array.from(entries);
|
|
1679
1686
|
const entry = entries.values().next().value; // grab the first one
|
|
1680
|
-
const version =
|
|
1687
|
+
const version = net.isIP(entry); // check if ip address was specified or an interface name
|
|
1681
1688
|
if (version) {
|
|
1682
|
-
serverAddress = version === 4
|
|
1689
|
+
serverAddress = version === 4
|
|
1690
|
+
? '0.0.0.0'
|
|
1691
|
+
: '::'; // we currently bind to unspecified addresses so config-ui always has a connection via loopback
|
|
1683
1692
|
}
|
|
1684
1693
|
else {
|
|
1685
|
-
serverAddress =
|
|
1694
|
+
serverAddress = '::'; // the interface could have both ipv4 and ipv6 addresses
|
|
1686
1695
|
}
|
|
1687
1696
|
}
|
|
1688
1697
|
else if (entries.size > 1) {
|
|
1689
1698
|
advertiserAddress = Array.from(entries);
|
|
1690
1699
|
let bindUnspecifiedIpv6 = false; // we bind on "::" if there are interface names, or we detect ipv6 addresses
|
|
1691
1700
|
for (const entry of entries) {
|
|
1692
|
-
const version =
|
|
1701
|
+
const version = net.isIP(entry);
|
|
1693
1702
|
if (version === 0 || version === 6) {
|
|
1694
1703
|
bindUnspecifiedIpv6 = true;
|
|
1695
1704
|
break;
|
|
1696
1705
|
}
|
|
1697
1706
|
}
|
|
1698
1707
|
if (bindUnspecifiedIpv6) {
|
|
1699
|
-
serverAddress =
|
|
1708
|
+
serverAddress = '::';
|
|
1700
1709
|
}
|
|
1701
1710
|
else {
|
|
1702
|
-
serverAddress =
|
|
1711
|
+
serverAddress = '0.0.0.0';
|
|
1703
1712
|
}
|
|
1704
1713
|
}
|
|
1705
1714
|
}
|
|
1706
1715
|
return {
|
|
1707
|
-
advertiserAddress
|
|
1716
|
+
advertiserAddress,
|
|
1708
1717
|
serviceRestrictedAddress: advertiserAddress,
|
|
1709
1718
|
serviceDisableIpv6: disableIpv6,
|
|
1710
|
-
serverAddress
|
|
1719
|
+
serverAddress,
|
|
1711
1720
|
};
|
|
1712
1721
|
}
|
|
1713
1722
|
}
|
|
1714
|
-
exports.Accessory = Accessory;
|
|
1715
1723
|
//# sourceMappingURL=Accessory.js.map
|