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