@homebridge/hap-nodejs 2.0.0-beta.3

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.
Files changed (265) hide show
  1. package/@types/bonjour-hap.d.ts +66 -0
  2. package/@types/simple-plist.d.ts +4 -0
  3. package/LICENSE +176 -0
  4. package/README.md +86 -0
  5. package/dist/accessories/AirConditioner_accessory.d.ts +2 -0
  6. package/dist/accessories/AirConditioner_accessory.d.ts.map +1 -0
  7. package/dist/accessories/AirConditioner_accessory.js +128 -0
  8. package/dist/accessories/AirConditioner_accessory.js.map +1 -0
  9. package/dist/accessories/AppleTVRemote_accessory.d.ts +2 -0
  10. package/dist/accessories/AppleTVRemote_accessory.d.ts.map +1 -0
  11. package/dist/accessories/AppleTVRemote_accessory.js +159 -0
  12. package/dist/accessories/AppleTVRemote_accessory.js.map +1 -0
  13. package/dist/accessories/Camera_accessory.d.ts +2 -0
  14. package/dist/accessories/Camera_accessory.d.ts.map +1 -0
  15. package/dist/accessories/Camera_accessory.js +545 -0
  16. package/dist/accessories/Camera_accessory.js.map +1 -0
  17. package/dist/accessories/Fan_accessory.d.ts +2 -0
  18. package/dist/accessories/Fan_accessory.d.ts.map +1 -0
  19. package/dist/accessories/Fan_accessory.js +74 -0
  20. package/dist/accessories/Fan_accessory.js.map +1 -0
  21. package/dist/accessories/GarageDoorOpener_accessory.d.ts +2 -0
  22. package/dist/accessories/GarageDoorOpener_accessory.d.ts.map +1 -0
  23. package/dist/accessories/GarageDoorOpener_accessory.js +78 -0
  24. package/dist/accessories/GarageDoorOpener_accessory.js.map +1 -0
  25. package/dist/accessories/Light-AdaptiveLighting_accessory.d.ts +2 -0
  26. package/dist/accessories/Light-AdaptiveLighting_accessory.d.ts.map +1 -0
  27. package/dist/accessories/Light-AdaptiveLighting_accessory.js +106 -0
  28. package/dist/accessories/Light-AdaptiveLighting_accessory.js.map +1 -0
  29. package/dist/accessories/Light_accessory.d.ts +2 -0
  30. package/dist/accessories/Light_accessory.d.ts.map +1 -0
  31. package/dist/accessories/Light_accessory.js +145 -0
  32. package/dist/accessories/Light_accessory.js.map +1 -0
  33. package/dist/accessories/Lock_accessory.d.ts +2 -0
  34. package/dist/accessories/Lock_accessory.d.ts.map +1 -0
  35. package/dist/accessories/Lock_accessory.js +76 -0
  36. package/dist/accessories/Lock_accessory.js.map +1 -0
  37. package/dist/accessories/MotionSensor_accessory.d.ts +2 -0
  38. package/dist/accessories/MotionSensor_accessory.d.ts.map +1 -0
  39. package/dist/accessories/MotionSensor_accessory.js +45 -0
  40. package/dist/accessories/MotionSensor_accessory.js.map +1 -0
  41. package/dist/accessories/Outlet_accessory.d.ts +2 -0
  42. package/dist/accessories/Outlet_accessory.d.ts.map +1 -0
  43. package/dist/accessories/Outlet_accessory.js +79 -0
  44. package/dist/accessories/Outlet_accessory.js.map +1 -0
  45. package/dist/accessories/SmartSpeaker_accessory.d.ts +2 -0
  46. package/dist/accessories/SmartSpeaker_accessory.d.ts.map +1 -0
  47. package/dist/accessories/SmartSpeaker_accessory.js +44 -0
  48. package/dist/accessories/SmartSpeaker_accessory.js.map +1 -0
  49. package/dist/accessories/Sprinkler_accessory.d.ts +2 -0
  50. package/dist/accessories/Sprinkler_accessory.d.ts.map +1 -0
  51. package/dist/accessories/Sprinkler_accessory.js +128 -0
  52. package/dist/accessories/Sprinkler_accessory.js.map +1 -0
  53. package/dist/accessories/TV_accessory.d.ts +2 -0
  54. package/dist/accessories/TV_accessory.d.ts.map +1 -0
  55. package/dist/accessories/TV_accessory.js +101 -0
  56. package/dist/accessories/TV_accessory.js.map +1 -0
  57. package/dist/accessories/TemperatureSensor_accessory.d.ts +2 -0
  58. package/dist/accessories/TemperatureSensor_accessory.d.ts.map +1 -0
  59. package/dist/accessories/TemperatureSensor_accessory.js +44 -0
  60. package/dist/accessories/TemperatureSensor_accessory.js.map +1 -0
  61. package/dist/accessories/Wi-FiRouter_accessory.d.ts +3 -0
  62. package/dist/accessories/Wi-FiRouter_accessory.d.ts.map +1 -0
  63. package/dist/accessories/Wi-FiRouter_accessory.js +17 -0
  64. package/dist/accessories/Wi-FiRouter_accessory.js.map +1 -0
  65. package/dist/accessories/Wi-FiSatellite_accessory.d.ts +3 -0
  66. package/dist/accessories/Wi-FiSatellite_accessory.d.ts.map +1 -0
  67. package/dist/accessories/Wi-FiSatellite_accessory.js +19 -0
  68. package/dist/accessories/Wi-FiSatellite_accessory.js.map +1 -0
  69. package/dist/accessories/gstreamer-audioProducer.d.ts +25 -0
  70. package/dist/accessories/gstreamer-audioProducer.d.ts.map +1 -0
  71. package/dist/accessories/gstreamer-audioProducer.js +145 -0
  72. package/dist/accessories/gstreamer-audioProducer.js.map +1 -0
  73. package/dist/accessories/types.d.ts +78 -0
  74. package/dist/accessories/types.d.ts.map +1 -0
  75. package/dist/accessories/types.js +88 -0
  76. package/dist/accessories/types.js.map +1 -0
  77. package/dist/index.d.ts +49 -0
  78. package/dist/index.d.ts.map +1 -0
  79. package/dist/index.js +53 -0
  80. package/dist/index.js.map +1 -0
  81. package/dist/internal-types.d.ts +76 -0
  82. package/dist/internal-types.d.ts.map +1 -0
  83. package/dist/internal-types.js +80 -0
  84. package/dist/internal-types.js.map +1 -0
  85. package/dist/lib/Accessory.d.ts +492 -0
  86. package/dist/lib/Accessory.d.ts.map +1 -0
  87. package/dist/lib/Accessory.js +1642 -0
  88. package/dist/lib/Accessory.js.map +1 -0
  89. package/dist/lib/Advertiser.d.ts +190 -0
  90. package/dist/lib/Advertiser.d.ts.map +1 -0
  91. package/dist/lib/Advertiser.js +594 -0
  92. package/dist/lib/Advertiser.js.map +1 -0
  93. package/dist/lib/Bridge.d.ts +12 -0
  94. package/dist/lib/Bridge.d.ts.map +1 -0
  95. package/dist/lib/Bridge.js +19 -0
  96. package/dist/lib/Bridge.js.map +1 -0
  97. package/dist/lib/Characteristic.d.ts +1604 -0
  98. package/dist/lib/Characteristic.d.ts.map +1 -0
  99. package/dist/lib/Characteristic.js +2318 -0
  100. package/dist/lib/Characteristic.js.map +1 -0
  101. package/dist/lib/HAPServer.d.ts +302 -0
  102. package/dist/lib/HAPServer.d.ts.map +1 -0
  103. package/dist/lib/HAPServer.js +849 -0
  104. package/dist/lib/HAPServer.js.map +1 -0
  105. package/dist/lib/Service.d.ts +568 -0
  106. package/dist/lib/Service.d.ts.map +1 -0
  107. package/dist/lib/Service.js +764 -0
  108. package/dist/lib/Service.js.map +1 -0
  109. package/dist/lib/camera/RTPProxy.d.ts +59 -0
  110. package/dist/lib/camera/RTPProxy.d.ts.map +1 -0
  111. package/dist/lib/camera/RTPProxy.js +267 -0
  112. package/dist/lib/camera/RTPProxy.js.map +1 -0
  113. package/dist/lib/camera/RTPStreamManagement.d.ts +378 -0
  114. package/dist/lib/camera/RTPStreamManagement.d.ts.map +1 -0
  115. package/dist/lib/camera/RTPStreamManagement.js +1007 -0
  116. package/dist/lib/camera/RTPStreamManagement.js.map +1 -0
  117. package/dist/lib/camera/RecordingManagement.d.ts +325 -0
  118. package/dist/lib/camera/RecordingManagement.d.ts.map +1 -0
  119. package/dist/lib/camera/RecordingManagement.js +766 -0
  120. package/dist/lib/camera/RecordingManagement.js.map +1 -0
  121. package/dist/lib/camera/index.d.ts +4 -0
  122. package/dist/lib/camera/index.d.ts.map +1 -0
  123. package/dist/lib/camera/index.js +7 -0
  124. package/dist/lib/camera/index.js.map +1 -0
  125. package/dist/lib/controller/AdaptiveLightingController.d.ts +455 -0
  126. package/dist/lib/controller/AdaptiveLightingController.d.ts.map +1 -0
  127. package/dist/lib/controller/AdaptiveLightingController.js +868 -0
  128. package/dist/lib/controller/AdaptiveLightingController.js.map +1 -0
  129. package/dist/lib/controller/CameraController.d.ts +411 -0
  130. package/dist/lib/controller/CameraController.d.ts.map +1 -0
  131. package/dist/lib/controller/CameraController.js +658 -0
  132. package/dist/lib/controller/CameraController.js.map +1 -0
  133. package/dist/lib/controller/Controller.d.ts +175 -0
  134. package/dist/lib/controller/Controller.d.ts.map +1 -0
  135. package/dist/lib/controller/Controller.js +24 -0
  136. package/dist/lib/controller/Controller.js.map +1 -0
  137. package/dist/lib/controller/DoorbellController.d.ts +59 -0
  138. package/dist/lib/controller/DoorbellController.d.ts.map +1 -0
  139. package/dist/lib/controller/DoorbellController.js +102 -0
  140. package/dist/lib/controller/DoorbellController.js.map +1 -0
  141. package/dist/lib/controller/RemoteController.d.ts +440 -0
  142. package/dist/lib/controller/RemoteController.d.ts.map +1 -0
  143. package/dist/lib/controller/RemoteController.js +1178 -0
  144. package/dist/lib/controller/RemoteController.js.map +1 -0
  145. package/dist/lib/controller/index.d.ts +6 -0
  146. package/dist/lib/controller/index.d.ts.map +1 -0
  147. package/dist/lib/controller/index.js +9 -0
  148. package/dist/lib/controller/index.js.map +1 -0
  149. package/dist/lib/datastream/DataStreamManagement.d.ts +73 -0
  150. package/dist/lib/datastream/DataStreamManagement.d.ts.map +1 -0
  151. package/dist/lib/datastream/DataStreamManagement.js +205 -0
  152. package/dist/lib/datastream/DataStreamManagement.js.map +1 -0
  153. package/dist/lib/datastream/DataStreamParser.d.ts +186 -0
  154. package/dist/lib/datastream/DataStreamParser.d.ts.map +1 -0
  155. package/dist/lib/datastream/DataStreamParser.js +879 -0
  156. package/dist/lib/datastream/DataStreamParser.js.map +1 -0
  157. package/dist/lib/datastream/DataStreamServer.d.ts +357 -0
  158. package/dist/lib/datastream/DataStreamServer.d.ts.map +1 -0
  159. package/dist/lib/datastream/DataStreamServer.js +878 -0
  160. package/dist/lib/datastream/DataStreamServer.js.map +1 -0
  161. package/dist/lib/datastream/index.d.ts +4 -0
  162. package/dist/lib/datastream/index.d.ts.map +1 -0
  163. package/dist/lib/datastream/index.js +7 -0
  164. package/dist/lib/datastream/index.js.map +1 -0
  165. package/dist/lib/definitions/CharacteristicDefinitions.d.ts +1984 -0
  166. package/dist/lib/definitions/CharacteristicDefinitions.d.ts.map +1 -0
  167. package/dist/lib/definitions/CharacteristicDefinitions.js +4422 -0
  168. package/dist/lib/definitions/CharacteristicDefinitions.js.map +1 -0
  169. package/dist/lib/definitions/ServiceDefinitions.d.ts +519 -0
  170. package/dist/lib/definitions/ServiceDefinitions.d.ts.map +1 -0
  171. package/dist/lib/definitions/ServiceDefinitions.js +1361 -0
  172. package/dist/lib/definitions/ServiceDefinitions.js.map +1 -0
  173. package/dist/lib/definitions/generate-definitions.d.ts +34 -0
  174. package/dist/lib/definitions/generate-definitions.d.ts.map +1 -0
  175. package/dist/lib/definitions/generate-definitions.js +624 -0
  176. package/dist/lib/definitions/generate-definitions.js.map +1 -0
  177. package/dist/lib/definitions/generator-configuration.d.ts +22 -0
  178. package/dist/lib/definitions/generator-configuration.d.ts.map +1 -0
  179. package/dist/lib/definitions/generator-configuration.js +371 -0
  180. package/dist/lib/definitions/generator-configuration.js.map +1 -0
  181. package/dist/lib/definitions/index.d.ts +3 -0
  182. package/dist/lib/definitions/index.d.ts.map +1 -0
  183. package/dist/lib/definitions/index.js +6 -0
  184. package/dist/lib/definitions/index.js.map +1 -0
  185. package/dist/lib/gen/HomeKit.d.ts +7 -0
  186. package/dist/lib/gen/HomeKit.d.ts.map +1 -0
  187. package/dist/lib/gen/HomeKit.js +8 -0
  188. package/dist/lib/gen/HomeKit.js.map +1 -0
  189. package/dist/lib/model/AccessoryInfo.d.ts +82 -0
  190. package/dist/lib/model/AccessoryInfo.d.ts.map +1 -0
  191. package/dist/lib/model/AccessoryInfo.js +277 -0
  192. package/dist/lib/model/AccessoryInfo.js.map +1 -0
  193. package/dist/lib/model/ControllerStorage.d.ts +45 -0
  194. package/dist/lib/model/ControllerStorage.d.ts.map +1 -0
  195. package/dist/lib/model/ControllerStorage.js +245 -0
  196. package/dist/lib/model/ControllerStorage.js.map +1 -0
  197. package/dist/lib/model/HAPStorage.d.ts +15 -0
  198. package/dist/lib/model/HAPStorage.d.ts.map +1 -0
  199. package/dist/lib/model/HAPStorage.js +43 -0
  200. package/dist/lib/model/HAPStorage.js.map +1 -0
  201. package/dist/lib/model/IdentifierCache.d.ts +33 -0
  202. package/dist/lib/model/IdentifierCache.d.ts.map +1 -0
  203. package/dist/lib/model/IdentifierCache.js +114 -0
  204. package/dist/lib/model/IdentifierCache.js.map +1 -0
  205. package/dist/lib/tv/AccessControlManagement.d.ts +86 -0
  206. package/dist/lib/tv/AccessControlManagement.d.ts.map +1 -0
  207. package/dist/lib/tv/AccessControlManagement.js +127 -0
  208. package/dist/lib/tv/AccessControlManagement.js.map +1 -0
  209. package/dist/lib/util/checkName.d.ts +8 -0
  210. package/dist/lib/util/checkName.d.ts.map +1 -0
  211. package/dist/lib/util/checkName.js +17 -0
  212. package/dist/lib/util/checkName.js.map +1 -0
  213. package/dist/lib/util/clone.d.ts +7 -0
  214. package/dist/lib/util/clone.d.ts.map +1 -0
  215. package/dist/lib/util/clone.js +22 -0
  216. package/dist/lib/util/clone.js.map +1 -0
  217. package/dist/lib/util/color-utils.d.ts +18 -0
  218. package/dist/lib/util/color-utils.d.ts.map +1 -0
  219. package/dist/lib/util/color-utils.js +442 -0
  220. package/dist/lib/util/color-utils.js.map +1 -0
  221. package/dist/lib/util/eventedhttp.d.ts +251 -0
  222. package/dist/lib/util/eventedhttp.d.ts.map +1 -0
  223. package/dist/lib/util/eventedhttp.js +706 -0
  224. package/dist/lib/util/eventedhttp.js.map +1 -0
  225. package/dist/lib/util/hapCrypto.d.ts +42 -0
  226. package/dist/lib/util/hapCrypto.d.ts.map +1 -0
  227. package/dist/lib/util/hapCrypto.js +144 -0
  228. package/dist/lib/util/hapCrypto.js.map +1 -0
  229. package/dist/lib/util/hapStatusError.d.ts +16 -0
  230. package/dist/lib/util/hapStatusError.d.ts.map +1 -0
  231. package/dist/lib/util/hapStatusError.js +29 -0
  232. package/dist/lib/util/hapStatusError.js.map +1 -0
  233. package/dist/lib/util/net-utils.d.ts +21 -0
  234. package/dist/lib/util/net-utils.d.ts.map +1 -0
  235. package/dist/lib/util/net-utils.js +79 -0
  236. package/dist/lib/util/net-utils.js.map +1 -0
  237. package/dist/lib/util/once.d.ts +7 -0
  238. package/dist/lib/util/once.d.ts.map +1 -0
  239. package/dist/lib/util/once.js +22 -0
  240. package/dist/lib/util/once.js.map +1 -0
  241. package/dist/lib/util/promise-utils.d.ts +14 -0
  242. package/dist/lib/util/promise-utils.d.ts.map +1 -0
  243. package/dist/lib/util/promise-utils.js +29 -0
  244. package/dist/lib/util/promise-utils.js.map +1 -0
  245. package/dist/lib/util/request-util.d.ts +36 -0
  246. package/dist/lib/util/request-util.d.ts.map +1 -0
  247. package/dist/lib/util/request-util.js +108 -0
  248. package/dist/lib/util/request-util.js.map +1 -0
  249. package/dist/lib/util/time.d.ts +9 -0
  250. package/dist/lib/util/time.d.ts.map +1 -0
  251. package/dist/lib/util/time.js +23 -0
  252. package/dist/lib/util/time.js.map +1 -0
  253. package/dist/lib/util/tlv.d.ts +90 -0
  254. package/dist/lib/util/tlv.d.ts.map +1 -0
  255. package/dist/lib/util/tlv.js +312 -0
  256. package/dist/lib/util/tlv.js.map +1 -0
  257. package/dist/lib/util/uuid.d.ts +23 -0
  258. package/dist/lib/util/uuid.d.ts.map +1 -0
  259. package/dist/lib/util/uuid.js +78 -0
  260. package/dist/lib/util/uuid.js.map +1 -0
  261. package/dist/types.d.ts +276 -0
  262. package/dist/types.d.ts.map +1 -0
  263. package/dist/types.js +11 -0
  264. package/dist/types.js.map +1 -0
  265. package/package.json +91 -0
@@ -0,0 +1,658 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.CameraController = exports.CameraControllerEvents = exports.ResourceRequestReason = void 0;
4
+ const tslib_1 = require("tslib");
5
+ const crypto_1 = tslib_1.__importDefault(require("crypto"));
6
+ const debug_1 = tslib_1.__importDefault(require("debug"));
7
+ const events_1 = require("events");
8
+ const camera_1 = require("../camera");
9
+ const Characteristic_1 = require("../Characteristic");
10
+ const datastream_1 = require("../datastream");
11
+ const Service_1 = require("../Service");
12
+ const hapStatusError_1 = require("../util/hapStatusError");
13
+ const debug = (0, debug_1.default)("HAP-NodeJS:Camera:Controller");
14
+ /**
15
+ * @group Camera
16
+ */
17
+ var ResourceRequestReason;
18
+ (function (ResourceRequestReason) {
19
+ /**
20
+ * The reason describes periodic resource requests.
21
+ * In the example of camera image snapshots those are the typical preview images every 10 seconds.
22
+ */
23
+ ResourceRequestReason[ResourceRequestReason["PERIODIC"] = 0] = "PERIODIC";
24
+ /**
25
+ * The resource request is the result of some event.
26
+ * In the example of camera image snapshots, requests are made due to e.g. a motion event or similar.
27
+ */
28
+ ResourceRequestReason[ResourceRequestReason["EVENT"] = 1] = "EVENT";
29
+ })(ResourceRequestReason || (exports.ResourceRequestReason = ResourceRequestReason = {}));
30
+ /**
31
+ * @group Camera
32
+ */
33
+ var CameraControllerEvents;
34
+ (function (CameraControllerEvents) {
35
+ /**
36
+ * Emitted when the mute state or the volume changed. The Apple Home App typically does not set those values
37
+ * except the mute state. When you adjust the volume in the Camera view it will reset the muted state if it was set previously.
38
+ * The value of volume has nothing to do with the volume slider in the Camera view of the Home app.
39
+ */
40
+ CameraControllerEvents["MICROPHONE_PROPERTIES_CHANGED"] = "microphone-change";
41
+ /**
42
+ * Emitted when the mute state or the volume changed. The Apple Home App typically does not set those values
43
+ * except the mute state. When you unmute the device microphone it will reset the mute state if it was set previously.
44
+ */
45
+ CameraControllerEvents["SPEAKER_PROPERTIES_CHANGED"] = "speaker-change";
46
+ })(CameraControllerEvents || (exports.CameraControllerEvents = CameraControllerEvents = {}));
47
+ /**
48
+ * Everything needed to expose a HomeKit Camera.
49
+ *
50
+ * @group Camera
51
+ */
52
+ // eslint-disable-next-line @typescript-eslint/no-unsafe-declaration-merging
53
+ class CameraController extends events_1.EventEmitter {
54
+ static STREAM_MANAGEMENT = "streamManagement"; // key to index all RTPStreamManagement services
55
+ stateChangeDelegate;
56
+ streamCount;
57
+ delegate;
58
+ streamingOptions;
59
+ /**
60
+ * **Temporary** storage for {@link CameraRecordingOptions} and {@link CameraRecordingDelegate}.
61
+ * This property is reset to `undefined` after the CameraController was fully initialized.
62
+ * You can still access those values via the {@link CameraController.recordingManagement}.
63
+ */
64
+ recording;
65
+ /**
66
+ * Temporary storage for the sensor option.
67
+ */
68
+ sensorOptions;
69
+ legacyMode = false;
70
+ /**
71
+ * @private
72
+ */
73
+ streamManagements = [];
74
+ /**
75
+ * The {@link RecordingManagement} which is responsible for handling HomeKit Secure Video.
76
+ * This property is only present if recording was configured.
77
+ */
78
+ recordingManagement;
79
+ microphoneService;
80
+ speakerService;
81
+ microphoneMuted = false;
82
+ microphoneVolume = 100;
83
+ speakerMuted = false;
84
+ speakerVolume = 100;
85
+ motionService;
86
+ motionServiceExternallySupplied = false;
87
+ occupancyService;
88
+ occupancyServiceExternallySupplied = false;
89
+ constructor(options, legacyMode = false) {
90
+ super();
91
+ this.streamCount = Math.max(1, options.cameraStreamCount || 1);
92
+ this.delegate = options.delegate;
93
+ this.streamingOptions = options.streamingOptions;
94
+ this.recording = options.recording;
95
+ this.sensorOptions = options.sensors;
96
+ this.legacyMode = legacyMode; // legacy mode will prevent from Microphone and Speaker services to get created to avoid collisions
97
+ }
98
+ /**
99
+ * @private
100
+ */
101
+ controllerId() {
102
+ return "camera" /* DefaultControllerType.CAMERA */;
103
+ }
104
+ // ----------------------------------- STREAM API ------------------------------------
105
+ /**
106
+ * Call this method if you want to forcefully suspend an ongoing streaming session.
107
+ * This would be adequate if the rtp server or media encoding encountered an unexpected error.
108
+ *
109
+ * @param sessionId - id of the current ongoing streaming session
110
+ */
111
+ forceStopStreamingSession(sessionId) {
112
+ this.streamManagements.forEach(management => {
113
+ if (management.sessionIdentifier === sessionId) {
114
+ management.forceStop();
115
+ }
116
+ });
117
+ }
118
+ static generateSynchronisationSource() {
119
+ const ssrc = crypto_1.default.randomBytes(4); // range [-2.14748e+09 - 2.14748e+09]
120
+ ssrc[0] = 0;
121
+ return ssrc.readInt32BE(0);
122
+ }
123
+ // ----------------------------- MICROPHONE/SPEAKER API ------------------------------
124
+ setMicrophoneMuted(muted = true) {
125
+ if (!this.microphoneService) {
126
+ return;
127
+ }
128
+ this.microphoneMuted = muted;
129
+ this.microphoneService.updateCharacteristic(Characteristic_1.Characteristic.Mute, muted);
130
+ }
131
+ setMicrophoneVolume(volume) {
132
+ if (!this.microphoneService) {
133
+ return;
134
+ }
135
+ this.microphoneVolume = volume;
136
+ this.microphoneService.updateCharacteristic(Characteristic_1.Characteristic.Volume, volume);
137
+ }
138
+ setSpeakerMuted(muted = true) {
139
+ if (!this.speakerService) {
140
+ return;
141
+ }
142
+ this.speakerMuted = muted;
143
+ this.speakerService.updateCharacteristic(Characteristic_1.Characteristic.Mute, muted);
144
+ }
145
+ setSpeakerVolume(volume) {
146
+ if (!this.speakerService) {
147
+ return;
148
+ }
149
+ this.speakerVolume = volume;
150
+ this.speakerService.updateCharacteristic(Characteristic_1.Characteristic.Volume, volume);
151
+ }
152
+ emitMicrophoneChange() {
153
+ this.emit("microphone-change" /* CameraControllerEvents.MICROPHONE_PROPERTIES_CHANGED */, this.microphoneMuted, this.microphoneVolume);
154
+ }
155
+ emitSpeakerChange() {
156
+ this.emit("speaker-change" /* CameraControllerEvents.SPEAKER_PROPERTIES_CHANGED */, this.speakerMuted, this.speakerVolume);
157
+ }
158
+ // -----------------------------------------------------------------------------------
159
+ /**
160
+ * @private
161
+ */
162
+ constructServices() {
163
+ for (let i = 0; i < this.streamCount; i++) {
164
+ const rtp = new camera_1.RTPStreamManagement(i, this.streamingOptions, this.delegate, undefined, this.rtpStreamManagementDisabledThroughOperatingMode.bind(this));
165
+ this.streamManagements.push(rtp);
166
+ }
167
+ if (!this.legacyMode && this.streamingOptions.audio) {
168
+ // In theory the Microphone Service is a necessity. In practice, it's not. lol.
169
+ // So we just add it if the user wants to support audio
170
+ this.microphoneService = new Service_1.Service.Microphone("", "");
171
+ this.microphoneService.setCharacteristic(Characteristic_1.Characteristic.Volume, this.microphoneVolume);
172
+ if (this.streamingOptions.audio.twoWayAudio) {
173
+ this.speakerService = new Service_1.Service.Speaker("", "");
174
+ this.speakerService.setCharacteristic(Characteristic_1.Characteristic.Volume, this.speakerVolume);
175
+ }
176
+ }
177
+ if (this.recording) {
178
+ this.recordingManagement = new camera_1.RecordingManagement(this.recording.options, this.recording.delegate, this.retrieveEventTriggerOptions());
179
+ }
180
+ if (this.sensorOptions?.motion) {
181
+ if (typeof this.sensorOptions.motion === "boolean") {
182
+ this.motionService = new Service_1.Service.MotionSensor("", "");
183
+ }
184
+ else {
185
+ this.motionService = this.sensorOptions.motion;
186
+ this.motionServiceExternallySupplied = true;
187
+ }
188
+ this.motionService.setCharacteristic(Characteristic_1.Characteristic.StatusActive, true);
189
+ this.recordingManagement?.recordingManagementService.addLinkedService(this.motionService);
190
+ }
191
+ if (this.sensorOptions?.occupancy) {
192
+ if (typeof this.sensorOptions.occupancy === "boolean") {
193
+ this.occupancyService = new Service_1.Service.OccupancySensor("", "");
194
+ }
195
+ else {
196
+ this.occupancyService = this.sensorOptions.occupancy;
197
+ this.occupancyServiceExternallySupplied = true;
198
+ }
199
+ this.occupancyService.setCharacteristic(Characteristic_1.Characteristic.StatusActive, true);
200
+ this.recordingManagement?.recordingManagementService.addLinkedService(this.occupancyService);
201
+ }
202
+ const serviceMap = {
203
+ microphone: this.microphoneService,
204
+ speaker: this.speakerService,
205
+ motionService: !this.motionServiceExternallySupplied ? this.motionService : undefined,
206
+ occupancyService: !this.occupancyServiceExternallySupplied ? this.occupancyService : undefined,
207
+ };
208
+ if (this.recordingManagement) {
209
+ serviceMap.cameraEventRecordingManagement = this.recordingManagement.recordingManagementService;
210
+ serviceMap.cameraOperatingMode = this.recordingManagement.operatingModeService;
211
+ serviceMap.dataStreamTransportManagement = this.recordingManagement.dataStreamManagement.getService();
212
+ }
213
+ this.streamManagements.forEach((management, index) => {
214
+ serviceMap[CameraController.STREAM_MANAGEMENT + index] = management.getService();
215
+ });
216
+ this.recording = undefined;
217
+ this.sensorOptions = undefined;
218
+ return serviceMap;
219
+ }
220
+ /**
221
+ * @private
222
+ */
223
+ initWithServices(serviceMap) {
224
+ const result = this._initWithServices(serviceMap);
225
+ if (result.updated) { // serviceMap must only be returned if anything actually changed
226
+ return result.serviceMap;
227
+ }
228
+ }
229
+ _initWithServices(serviceMap) {
230
+ let modifiedServiceMap = false;
231
+ // eslint-disable-next-line no-constant-condition
232
+ for (let i = 0; true; i++) {
233
+ const streamManagementService = serviceMap[CameraController.STREAM_MANAGEMENT + i];
234
+ if (i < this.streamCount) {
235
+ const operatingModeClosure = this.rtpStreamManagementDisabledThroughOperatingMode.bind(this);
236
+ if (streamManagementService) { // normal init
237
+ this.streamManagements.push(new camera_1.RTPStreamManagement(i, this.streamingOptions, this.delegate, streamManagementService, operatingModeClosure));
238
+ }
239
+ else { // stream count got bigger, we need to create a new service
240
+ const management = new camera_1.RTPStreamManagement(i, this.streamingOptions, this.delegate, undefined, operatingModeClosure);
241
+ this.streamManagements.push(management);
242
+ serviceMap[CameraController.STREAM_MANAGEMENT + i] = management.getService();
243
+ modifiedServiceMap = true;
244
+ }
245
+ }
246
+ else {
247
+ if (streamManagementService) { // stream count got reduced, we need to remove old service
248
+ delete serviceMap[CameraController.STREAM_MANAGEMENT + i];
249
+ modifiedServiceMap = true;
250
+ }
251
+ else {
252
+ break; // we finished counting, and we got no saved service; we are finished
253
+ }
254
+ }
255
+ }
256
+ // MICROPHONE
257
+ if (!this.legacyMode && this.streamingOptions.audio) { // microphone should be present
258
+ if (serviceMap.microphone) {
259
+ this.microphoneService = serviceMap.microphone;
260
+ }
261
+ else {
262
+ // microphone wasn't created yet => create a new one
263
+ this.microphoneService = new Service_1.Service.Microphone("", "");
264
+ this.microphoneService.setCharacteristic(Characteristic_1.Characteristic.Volume, this.microphoneVolume);
265
+ serviceMap.microphone = this.microphoneService;
266
+ modifiedServiceMap = true;
267
+ }
268
+ }
269
+ else if (serviceMap.microphone) { // microphone service supplied, though settings seemed to have changed
270
+ // we need to remove it
271
+ delete serviceMap.microphone;
272
+ modifiedServiceMap = true;
273
+ }
274
+ // SPEAKER
275
+ if (!this.legacyMode && this.streamingOptions.audio?.twoWayAudio) { // speaker should be present
276
+ if (serviceMap.speaker) {
277
+ this.speakerService = serviceMap.speaker;
278
+ }
279
+ else {
280
+ // speaker wasn't created yet => create a new one
281
+ this.speakerService = new Service_1.Service.Speaker("", "");
282
+ this.speakerService.setCharacteristic(Characteristic_1.Characteristic.Volume, this.speakerVolume);
283
+ serviceMap.speaker = this.speakerService;
284
+ modifiedServiceMap = true;
285
+ }
286
+ }
287
+ else if (serviceMap.speaker) { // speaker service supplied, though settings seemed to have changed
288
+ // we need to remove it
289
+ delete serviceMap.speaker;
290
+ modifiedServiceMap = true;
291
+ }
292
+ // RECORDING
293
+ if (this.recording) {
294
+ const eventTriggers = this.retrieveEventTriggerOptions();
295
+ // RECORDING MANAGEMENT
296
+ if (serviceMap.cameraEventRecordingManagement && serviceMap.cameraOperatingMode && serviceMap.dataStreamTransportManagement) {
297
+ this.recordingManagement = new camera_1.RecordingManagement(this.recording.options, this.recording.delegate, eventTriggers, {
298
+ recordingManagement: serviceMap.cameraEventRecordingManagement,
299
+ operatingMode: serviceMap.cameraOperatingMode,
300
+ dataStreamManagement: new datastream_1.DataStreamManagement(serviceMap.dataStreamTransportManagement),
301
+ });
302
+ }
303
+ else {
304
+ this.recordingManagement = new camera_1.RecordingManagement(this.recording.options, this.recording.delegate, eventTriggers);
305
+ serviceMap.cameraEventRecordingManagement = this.recordingManagement.recordingManagementService;
306
+ serviceMap.cameraOperatingMode = this.recordingManagement.operatingModeService;
307
+ serviceMap.dataStreamTransportManagement = this.recordingManagement.dataStreamManagement.getService();
308
+ modifiedServiceMap = true;
309
+ }
310
+ }
311
+ else {
312
+ if (serviceMap.cameraEventRecordingManagement) {
313
+ delete serviceMap.cameraEventRecordingManagement;
314
+ modifiedServiceMap = true;
315
+ }
316
+ if (serviceMap.cameraOperatingMode) {
317
+ delete serviceMap.cameraOperatingMode;
318
+ modifiedServiceMap = true;
319
+ }
320
+ if (serviceMap.dataStreamTransportManagement) {
321
+ delete serviceMap.dataStreamTransportManagement;
322
+ modifiedServiceMap = true;
323
+ }
324
+ }
325
+ // MOTION SENSOR
326
+ if (this.sensorOptions?.motion) {
327
+ if (typeof this.sensorOptions.motion === "boolean") {
328
+ if (serviceMap.motionService) {
329
+ this.motionService = serviceMap.motionService;
330
+ }
331
+ else {
332
+ // it could be the case that we previously had a manually supplied motion service
333
+ // at this point we can't remove the iid from the list of linked services from the recording management!
334
+ this.motionService = new Service_1.Service.MotionSensor("", "");
335
+ }
336
+ }
337
+ else {
338
+ this.motionService = this.sensorOptions.motion;
339
+ this.motionServiceExternallySupplied = true;
340
+ if (serviceMap.motionService) { // motion service previously supplied as bool option
341
+ this.recordingManagement?.recordingManagementService.removeLinkedService(serviceMap.motionService);
342
+ delete serviceMap.motionService;
343
+ modifiedServiceMap = true;
344
+ }
345
+ }
346
+ this.motionService.setCharacteristic(Characteristic_1.Characteristic.StatusActive, true);
347
+ this.recordingManagement?.recordingManagementService.addLinkedService(this.motionService);
348
+ }
349
+ else {
350
+ if (serviceMap.motionService) {
351
+ this.recordingManagement?.recordingManagementService.removeLinkedService(serviceMap.motionService);
352
+ delete serviceMap.motionService;
353
+ modifiedServiceMap = true;
354
+ }
355
+ }
356
+ // OCCUPANCY SENSOR
357
+ if (this.sensorOptions?.occupancy) {
358
+ if (typeof this.sensorOptions.occupancy === "boolean") {
359
+ if (serviceMap.occupancyService) {
360
+ this.occupancyService = serviceMap.occupancyService;
361
+ }
362
+ else {
363
+ // it could be the case that we previously had a manually supplied occupancy service
364
+ // at this point we can't remove the iid from the list of linked services from the recording management!
365
+ this.occupancyService = new Service_1.Service.OccupancySensor("", "");
366
+ }
367
+ }
368
+ else {
369
+ this.occupancyService = this.sensorOptions.occupancy;
370
+ this.occupancyServiceExternallySupplied = true;
371
+ if (serviceMap.occupancyService) { // occupancy service previously supplied as bool option
372
+ this.recordingManagement?.recordingManagementService.removeLinkedService(serviceMap.occupancyService);
373
+ delete serviceMap.occupancyService;
374
+ modifiedServiceMap = true;
375
+ }
376
+ }
377
+ this.occupancyService.setCharacteristic(Characteristic_1.Characteristic.StatusActive, true);
378
+ this.recordingManagement?.recordingManagementService.addLinkedService(this.occupancyService);
379
+ }
380
+ else {
381
+ if (serviceMap.occupancyService) {
382
+ this.recordingManagement?.recordingManagementService.removeLinkedService(serviceMap.occupancyService);
383
+ delete serviceMap.occupancyService;
384
+ modifiedServiceMap = true;
385
+ }
386
+ }
387
+ if (this.migrateFromDoorbell(serviceMap)) {
388
+ modifiedServiceMap = true;
389
+ }
390
+ this.recording = undefined;
391
+ this.sensorOptions = undefined;
392
+ return {
393
+ serviceMap: serviceMap,
394
+ updated: modifiedServiceMap,
395
+ };
396
+ }
397
+ // overwritten in DoorbellController (to avoid cyclic dependencies, I hate typescript for that)
398
+ migrateFromDoorbell(serviceMap) {
399
+ if (serviceMap.doorbell) { // See NOTICE in DoorbellController
400
+ delete serviceMap.doorbell;
401
+ return true;
402
+ }
403
+ return false;
404
+ }
405
+ retrieveEventTriggerOptions() {
406
+ if (!this.recording) {
407
+ return new Set();
408
+ }
409
+ const triggerOptions = new Set();
410
+ if (this.recording.options.overrideEventTriggerOptions) {
411
+ for (const option of this.recording.options.overrideEventTriggerOptions) {
412
+ triggerOptions.add(option);
413
+ }
414
+ }
415
+ if (this.sensorOptions?.motion) {
416
+ triggerOptions.add(1 /* EventTriggerOption.MOTION */);
417
+ }
418
+ // this method is overwritten by the `DoorbellController` to automatically configure EventTriggerOption.DOORBELL
419
+ return triggerOptions;
420
+ }
421
+ /**
422
+ * @private
423
+ */
424
+ configureServices() {
425
+ if (this.microphoneService) {
426
+ this.microphoneService.getCharacteristic(Characteristic_1.Characteristic.Mute)
427
+ .on("get" /* CharacteristicEventTypes.GET */, (callback) => {
428
+ callback(undefined, this.microphoneMuted);
429
+ })
430
+ .on("set" /* CharacteristicEventTypes.SET */, (value, callback) => {
431
+ this.microphoneMuted = value;
432
+ callback();
433
+ this.emitMicrophoneChange();
434
+ });
435
+ this.microphoneService.getCharacteristic(Characteristic_1.Characteristic.Volume)
436
+ .on("get" /* CharacteristicEventTypes.GET */, (callback) => {
437
+ callback(undefined, this.microphoneVolume);
438
+ })
439
+ .on("set" /* CharacteristicEventTypes.SET */, (value, callback) => {
440
+ this.microphoneVolume = value;
441
+ callback();
442
+ this.emitMicrophoneChange();
443
+ });
444
+ }
445
+ if (this.speakerService) {
446
+ this.speakerService.getCharacteristic(Characteristic_1.Characteristic.Mute)
447
+ .on("get" /* CharacteristicEventTypes.GET */, (callback) => {
448
+ callback(undefined, this.speakerMuted);
449
+ })
450
+ .on("set" /* CharacteristicEventTypes.SET */, (value, callback) => {
451
+ this.speakerMuted = value;
452
+ callback();
453
+ this.emitSpeakerChange();
454
+ });
455
+ this.speakerService.getCharacteristic(Characteristic_1.Characteristic.Volume)
456
+ .on("get" /* CharacteristicEventTypes.GET */, (callback) => {
457
+ callback(undefined, this.speakerVolume);
458
+ })
459
+ .on("set" /* CharacteristicEventTypes.SET */, (value, callback) => {
460
+ this.speakerVolume = value;
461
+ callback();
462
+ this.emitSpeakerChange();
463
+ });
464
+ }
465
+ // make the sensor services available to the RecordingManagement.
466
+ if (this.motionService) {
467
+ this.recordingManagement?.sensorServices.push(this.motionService);
468
+ }
469
+ if (this.occupancyService) {
470
+ this.recordingManagement?.sensorServices.push(this.occupancyService);
471
+ }
472
+ }
473
+ rtpStreamManagementDisabledThroughOperatingMode() {
474
+ return this.recordingManagement
475
+ ? !this.recordingManagement.operatingModeService.getCharacteristic(Characteristic_1.Characteristic.HomeKitCameraActive).value
476
+ : false;
477
+ }
478
+ /**
479
+ * @private
480
+ */
481
+ handleControllerRemoved() {
482
+ this.handleFactoryReset();
483
+ for (const management of this.streamManagements) {
484
+ management.destroy();
485
+ }
486
+ this.streamManagements.splice(0, this.streamManagements.length);
487
+ this.microphoneService = undefined;
488
+ this.speakerService = undefined;
489
+ this.recordingManagement?.destroy();
490
+ this.recordingManagement = undefined;
491
+ this.removeAllListeners();
492
+ }
493
+ /**
494
+ * @private
495
+ */
496
+ handleFactoryReset() {
497
+ this.streamManagements.forEach(management => management.handleFactoryReset());
498
+ this.recordingManagement?.handleFactoryReset();
499
+ this.microphoneMuted = false;
500
+ this.microphoneVolume = 100;
501
+ this.speakerMuted = false;
502
+ this.speakerVolume = 100;
503
+ }
504
+ /**
505
+ * @private
506
+ */
507
+ serialize() {
508
+ const streamManagementStates = [];
509
+ for (const management of this.streamManagements) {
510
+ const serializedState = management.serialize();
511
+ if (serializedState) {
512
+ streamManagementStates.push(serializedState);
513
+ }
514
+ }
515
+ return {
516
+ streamManagements: streamManagementStates,
517
+ recordingManagement: this.recordingManagement?.serialize(),
518
+ };
519
+ }
520
+ /**
521
+ * @private
522
+ */
523
+ deserialize(serialized) {
524
+ for (const streamManagementState of serialized.streamManagements) {
525
+ const streamManagement = this.streamManagements[streamManagementState.id];
526
+ if (streamManagement) {
527
+ streamManagement.deserialize(streamManagementState);
528
+ }
529
+ }
530
+ if (serialized.recordingManagement) {
531
+ if (this.recordingManagement) {
532
+ this.recordingManagement.deserialize(serialized.recordingManagement);
533
+ }
534
+ else {
535
+ // Active characteristic cannot be controlled if removing HSV, ensure they are all active!
536
+ for (const streamManagement of this.streamManagements) {
537
+ streamManagement.service.updateCharacteristic(Characteristic_1.Characteristic.Active, true);
538
+ }
539
+ this.stateChangeDelegate?.();
540
+ }
541
+ }
542
+ }
543
+ /**
544
+ * @private
545
+ */
546
+ setupStateChangeDelegate(delegate) {
547
+ this.stateChangeDelegate = delegate;
548
+ for (const streamManagement of this.streamManagements) {
549
+ streamManagement.setupStateChangeDelegate(delegate);
550
+ }
551
+ this.recordingManagement?.setupStateChangeDelegate(delegate);
552
+ }
553
+ /**
554
+ * @private
555
+ */
556
+ handleSnapshotRequest(height, width, accessoryName, reason) {
557
+ // first step is to verify that the reason is applicable to our current policy
558
+ const streamingDisabled = this.streamManagements
559
+ .map(management => !management.getService().getCharacteristic(Characteristic_1.Characteristic.Active).value)
560
+ .reduce((previousValue, currentValue) => previousValue && currentValue);
561
+ if (streamingDisabled) {
562
+ debug("[%s] Rejecting snapshot as streaming is disabled.", accessoryName);
563
+ return Promise.reject(-70412 /* HAPStatus.NOT_ALLOWED_IN_CURRENT_STATE */);
564
+ }
565
+ if (this.recordingManagement) {
566
+ const operatingModeService = this.recordingManagement.operatingModeService;
567
+ if (!operatingModeService.getCharacteristic(Characteristic_1.Characteristic.HomeKitCameraActive).value) {
568
+ debug("[%s] Rejecting snapshot as HomeKit camera is disabled.", accessoryName);
569
+ return Promise.reject(-70412 /* HAPStatus.NOT_ALLOWED_IN_CURRENT_STATE */);
570
+ }
571
+ const eventSnapshotsActive = operatingModeService
572
+ .getCharacteristic(Characteristic_1.Characteristic.EventSnapshotsActive)
573
+ .value;
574
+ if (!eventSnapshotsActive) {
575
+ if (reason == null) {
576
+ debug("[%s] Rejecting snapshot as reason is required due to disabled event snapshots.", accessoryName);
577
+ return Promise.reject(-70401 /* HAPStatus.INSUFFICIENT_PRIVILEGES */);
578
+ }
579
+ else if (reason === 1 /* ResourceRequestReason.EVENT */) {
580
+ debug("[%s] Rejecting snapshot as even snapshots are disabled.", accessoryName);
581
+ return Promise.reject(-70412 /* HAPStatus.NOT_ALLOWED_IN_CURRENT_STATE */);
582
+ }
583
+ }
584
+ const periodicSnapshotsActive = operatingModeService
585
+ .getCharacteristic(Characteristic_1.Characteristic.PeriodicSnapshotsActive)
586
+ .value;
587
+ if (!periodicSnapshotsActive) {
588
+ if (reason == null) {
589
+ debug("[%s] Rejecting snapshot as reason is required due to disabled periodic snapshots.", accessoryName);
590
+ return Promise.reject(-70401 /* HAPStatus.INSUFFICIENT_PRIVILEGES */);
591
+ }
592
+ else if (reason === 0 /* ResourceRequestReason.PERIODIC */) {
593
+ debug("[%s] Rejecting snapshot as periodic snapshots are disabled.", accessoryName);
594
+ return Promise.reject(-70412 /* HAPStatus.NOT_ALLOWED_IN_CURRENT_STATE */);
595
+ }
596
+ }
597
+ }
598
+ // now do the actual snapshot request.
599
+ return new Promise((resolve, reject) => {
600
+ // TODO test and make timeouts configurable!
601
+ let timeout = setTimeout(() => {
602
+ console.warn(`[${accessoryName}] The image snapshot handler for the given accessory is slow to respond! See https://homebridge.io/w/JtMGR for more info.`);
603
+ timeout = setTimeout(() => {
604
+ timeout = undefined;
605
+ console.warn(`[${accessoryName}] The image snapshot handler for the given accessory didn't respond at all! See https://homebridge.io/w/JtMGR for more info.`);
606
+ reject(-70408 /* HAPStatus.OPERATION_TIMED_OUT */);
607
+ }, 17000);
608
+ timeout.unref();
609
+ }, 8000);
610
+ timeout.unref();
611
+ try {
612
+ this.delegate.handleSnapshotRequest({
613
+ height: height,
614
+ width: width,
615
+ reason: reason,
616
+ }, (error, buffer) => {
617
+ if (!timeout) {
618
+ return;
619
+ }
620
+ else {
621
+ clearTimeout(timeout);
622
+ timeout = undefined;
623
+ }
624
+ if (error) {
625
+ if (typeof error === "number") {
626
+ reject(error);
627
+ }
628
+ else {
629
+ debug("[%s] Error getting snapshot: %s", accessoryName, error.stack);
630
+ reject(-70402 /* HAPStatus.SERVICE_COMMUNICATION_FAILURE */);
631
+ }
632
+ return;
633
+ }
634
+ if (!buffer || buffer.length === 0) {
635
+ console.warn(`[${accessoryName}] Snapshot request handler provided empty image buffer!`);
636
+ reject(-70402 /* HAPStatus.SERVICE_COMMUNICATION_FAILURE */);
637
+ }
638
+ else {
639
+ resolve(buffer);
640
+ }
641
+ });
642
+ }
643
+ catch (error) {
644
+ if (!timeout) {
645
+ return;
646
+ }
647
+ else {
648
+ clearTimeout(timeout);
649
+ timeout = undefined;
650
+ }
651
+ console.warn(`[${accessoryName}] Unhandled error thrown inside snapshot request handler: ${error.stack}`);
652
+ reject(error instanceof hapStatusError_1.HapStatusError ? error.hapStatus : -70402 /* HAPStatus.SERVICE_COMMUNICATION_FAILURE */);
653
+ }
654
+ });
655
+ }
656
+ }
657
+ exports.CameraController = CameraController;
658
+ //# sourceMappingURL=CameraController.js.map