hap-nodejs 1.0.0-beta.8 → 1.0.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.
Files changed (195) hide show
  1. package/README.md +7 -3
  2. package/dist/accessories/AirConditioner_accessory.js +24 -24
  3. package/dist/accessories/AirConditioner_accessory.js.map +1 -1
  4. package/dist/accessories/AppleTVRemote_accessory.js +23 -23
  5. package/dist/accessories/AppleTVRemote_accessory.js.map +1 -1
  6. package/dist/accessories/Camera_accessory.js +295 -380
  7. package/dist/accessories/Camera_accessory.js.map +1 -1
  8. package/dist/accessories/Fan_accessory.js +15 -21
  9. package/dist/accessories/Fan_accessory.js.map +1 -1
  10. package/dist/accessories/GarageDoorOpener_accessory.js +12 -12
  11. package/dist/accessories/GarageDoorOpener_accessory.js.map +1 -1
  12. package/dist/accessories/Light-AdaptiveLighting_accessory.js +31 -21
  13. package/dist/accessories/Light-AdaptiveLighting_accessory.js.map +1 -1
  14. package/dist/accessories/Light_accessory.js +45 -48
  15. package/dist/accessories/Light_accessory.js.map +1 -1
  16. package/dist/accessories/Lock_accessory.js +11 -11
  17. package/dist/accessories/Lock_accessory.js.map +1 -1
  18. package/dist/accessories/MotionSensor_accessory.js +8 -8
  19. package/dist/accessories/MotionSensor_accessory.js.map +1 -1
  20. package/dist/accessories/Outlet_accessory.js +10 -10
  21. package/dist/accessories/Outlet_accessory.js.map +1 -1
  22. package/dist/accessories/SmartSpeaker_accessory.js +11 -11
  23. package/dist/accessories/SmartSpeaker_accessory.js.map +1 -1
  24. package/dist/accessories/Sprinkler_accessory.js +19 -19
  25. package/dist/accessories/Sprinkler_accessory.js.map +1 -1
  26. package/dist/accessories/TV_accessory.js +17 -17
  27. package/dist/accessories/TV_accessory.js.map +1 -1
  28. package/dist/accessories/TemperatureSensor_accessory.js +6 -6
  29. package/dist/accessories/TemperatureSensor_accessory.js.map +1 -1
  30. package/dist/accessories/Wi-FiRouter_accessory.js +3 -3
  31. package/dist/accessories/Wi-FiRouter_accessory.js.map +1 -1
  32. package/dist/accessories/Wi-FiSatellite_accessory.js +4 -4
  33. package/dist/accessories/Wi-FiSatellite_accessory.js.map +1 -1
  34. package/dist/accessories/gstreamer-audioProducer.js +45 -55
  35. package/dist/accessories/gstreamer-audioProducer.js.map +1 -1
  36. package/dist/accessories/types.js +2 -2
  37. package/dist/accessories/types.js.map +1 -1
  38. package/dist/index.d.ts +0 -14
  39. package/dist/index.d.ts.map +1 -1
  40. package/dist/index.js +6 -31
  41. package/dist/index.js.map +1 -1
  42. package/dist/internal-types.d.ts +4 -4
  43. package/dist/internal-types.d.ts.map +1 -1
  44. package/dist/internal-types.js +10 -6
  45. package/dist/internal-types.js.map +1 -1
  46. package/dist/lib/Accessory.d.ts +19 -74
  47. package/dist/lib/Accessory.d.ts.map +1 -1
  48. package/dist/lib/Accessory.js +775 -1155
  49. package/dist/lib/Accessory.js.map +1 -1
  50. package/dist/lib/Advertiser.d.ts +5 -6
  51. package/dist/lib/Advertiser.d.ts.map +1 -1
  52. package/dist/lib/Advertiser.js +402 -521
  53. package/dist/lib/Advertiser.js.map +1 -1
  54. package/dist/lib/Bridge.js +6 -10
  55. package/dist/lib/Bridge.js.map +1 -1
  56. package/dist/lib/Characteristic.d.ts +31 -93
  57. package/dist/lib/Characteristic.d.ts.map +1 -1
  58. package/dist/lib/Characteristic.js +1474 -668
  59. package/dist/lib/Characteristic.js.map +1 -1
  60. package/dist/lib/HAPServer.d.ts +10 -22
  61. package/dist/lib/HAPServer.d.ts.map +1 -1
  62. package/dist/lib/HAPServer.js +224 -286
  63. package/dist/lib/HAPServer.js.map +1 -1
  64. package/dist/lib/Service.d.ts +9 -27
  65. package/dist/lib/Service.d.ts.map +1 -1
  66. package/dist/lib/Service.js +476 -314
  67. package/dist/lib/Service.js.map +1 -1
  68. package/dist/lib/camera/RTPProxy.d.ts +0 -2
  69. package/dist/lib/camera/RTPProxy.d.ts.map +1 -1
  70. package/dist/lib/camera/RTPProxy.js +112 -104
  71. package/dist/lib/camera/RTPProxy.js.map +1 -1
  72. package/dist/lib/camera/RTPStreamManagement.d.ts +2 -67
  73. package/dist/lib/camera/RTPStreamManagement.d.ts.map +1 -1
  74. package/dist/lib/camera/RTPStreamManagement.js +272 -292
  75. package/dist/lib/camera/RTPStreamManagement.js.map +1 -1
  76. package/dist/lib/camera/RecordingManagement.d.ts +0 -1
  77. package/dist/lib/camera/RecordingManagement.d.ts.map +1 -1
  78. package/dist/lib/camera/RecordingManagement.js +325 -392
  79. package/dist/lib/camera/RecordingManagement.js.map +1 -1
  80. package/dist/lib/camera/index.d.ts +0 -1
  81. package/dist/lib/camera/index.d.ts.map +1 -1
  82. package/dist/lib/camera/index.js +1 -2
  83. package/dist/lib/camera/index.js.map +1 -1
  84. package/dist/lib/controller/AdaptiveLightingController.d.ts +19 -4
  85. package/dist/lib/controller/AdaptiveLightingController.d.ts.map +1 -1
  86. package/dist/lib/controller/AdaptiveLightingController.js +220 -221
  87. package/dist/lib/controller/AdaptiveLightingController.js.map +1 -1
  88. package/dist/lib/controller/CameraController.d.ts +0 -6
  89. package/dist/lib/controller/CameraController.d.ts.map +1 -1
  90. package/dist/lib/controller/CameraController.js +192 -258
  91. package/dist/lib/controller/CameraController.js.map +1 -1
  92. package/dist/lib/controller/Controller.d.ts +1 -1
  93. package/dist/lib/controller/Controller.d.ts.map +1 -1
  94. package/dist/lib/controller/Controller.js +3 -3
  95. package/dist/lib/controller/Controller.js.map +1 -1
  96. package/dist/lib/controller/DoorbellController.js +38 -39
  97. package/dist/lib/controller/DoorbellController.js.map +1 -1
  98. package/dist/lib/controller/RemoteController.d.ts +4 -20
  99. package/dist/lib/controller/RemoteController.d.ts.map +1 -1
  100. package/dist/lib/controller/RemoteController.js +351 -424
  101. package/dist/lib/controller/RemoteController.js.map +1 -1
  102. package/dist/lib/controller/index.js +1 -1
  103. package/dist/lib/datastream/DataStreamManagement.js +57 -58
  104. package/dist/lib/datastream/DataStreamManagement.js.map +1 -1
  105. package/dist/lib/datastream/DataStreamParser.d.ts +0 -1
  106. package/dist/lib/datastream/DataStreamParser.d.ts.map +1 -1
  107. package/dist/lib/datastream/DataStreamParser.js +261 -306
  108. package/dist/lib/datastream/DataStreamParser.js.map +1 -1
  109. package/dist/lib/datastream/DataStreamServer.d.ts +0 -8
  110. package/dist/lib/datastream/DataStreamServer.d.ts.map +1 -1
  111. package/dist/lib/datastream/DataStreamServer.js +262 -275
  112. package/dist/lib/datastream/DataStreamServer.js.map +1 -1
  113. package/dist/lib/datastream/index.js +1 -1
  114. package/dist/lib/definitions/CharacteristicDefinitions.d.ts +50 -40
  115. package/dist/lib/definitions/CharacteristicDefinitions.d.ts.map +1 -1
  116. package/dist/lib/definitions/CharacteristicDefinitions.js +2059 -2754
  117. package/dist/lib/definitions/CharacteristicDefinitions.js.map +1 -1
  118. package/dist/lib/definitions/ServiceDefinitions.d.ts +14 -8
  119. package/dist/lib/definitions/ServiceDefinitions.d.ts.map +1 -1
  120. package/dist/lib/definitions/ServiceDefinitions.js +834 -1053
  121. package/dist/lib/definitions/ServiceDefinitions.js.map +1 -1
  122. package/dist/lib/definitions/generate-definitions.js +383 -679
  123. package/dist/lib/definitions/generate-definitions.js.map +1 -1
  124. package/dist/lib/definitions/generator-configuration.d.ts.map +1 -1
  125. package/dist/lib/definitions/generator-configuration.js +163 -35
  126. package/dist/lib/definitions/generator-configuration.js.map +1 -1
  127. package/dist/lib/definitions/index.js +1 -1
  128. package/dist/lib/model/AccessoryInfo.d.ts +0 -1
  129. package/dist/lib/model/AccessoryInfo.d.ts.map +1 -1
  130. package/dist/lib/model/AccessoryInfo.js +102 -137
  131. package/dist/lib/model/AccessoryInfo.js.map +1 -1
  132. package/dist/lib/model/ControllerStorage.js +86 -89
  133. package/dist/lib/model/ControllerStorage.js.map +1 -1
  134. package/dist/lib/model/HAPStorage.js +15 -16
  135. package/dist/lib/model/HAPStorage.js.map +1 -1
  136. package/dist/lib/model/IdentifierCache.js +49 -49
  137. package/dist/lib/model/IdentifierCache.js.map +1 -1
  138. package/dist/lib/tv/AccessControlManagement.d.ts +0 -1
  139. package/dist/lib/tv/AccessControlManagement.d.ts.map +1 -1
  140. package/dist/lib/tv/AccessControlManagement.js +43 -46
  141. package/dist/lib/tv/AccessControlManagement.js.map +1 -1
  142. package/dist/lib/util/checkName.d.ts +8 -0
  143. package/dist/lib/util/checkName.d.ts.map +1 -0
  144. package/dist/lib/util/checkName.js +17 -0
  145. package/dist/lib/util/checkName.js.map +1 -0
  146. package/dist/lib/util/clone.js +6 -29
  147. package/dist/lib/util/clone.js.map +1 -1
  148. package/dist/lib/util/color-utils.js +8 -12
  149. package/dist/lib/util/color-utils.js.map +1 -1
  150. package/dist/lib/util/eventedhttp.d.ts +5 -9
  151. package/dist/lib/util/eventedhttp.d.ts.map +1 -1
  152. package/dist/lib/util/eventedhttp.js +306 -405
  153. package/dist/lib/util/eventedhttp.js.map +1 -1
  154. package/dist/lib/util/hapCrypto.d.ts +0 -1
  155. package/dist/lib/util/hapCrypto.d.ts.map +1 -1
  156. package/dist/lib/util/hapCrypto.js +39 -41
  157. package/dist/lib/util/hapCrypto.js.map +1 -1
  158. package/dist/lib/util/hapStatusError.js +9 -12
  159. package/dist/lib/util/hapStatusError.js.map +1 -1
  160. package/dist/lib/util/net-utils.d.ts.map +1 -1
  161. package/dist/lib/util/net-utils.js +34 -54
  162. package/dist/lib/util/net-utils.js.map +1 -1
  163. package/dist/lib/util/once.js +4 -10
  164. package/dist/lib/util/once.js.map +1 -1
  165. package/dist/lib/util/promise-utils.d.ts +0 -1
  166. package/dist/lib/util/promise-utils.d.ts.map +1 -1
  167. package/dist/lib/util/promise-utils.js +10 -16
  168. package/dist/lib/util/promise-utils.js.map +1 -1
  169. package/dist/lib/util/request-util.js +8 -10
  170. package/dist/lib/util/request-util.js.map +1 -1
  171. package/dist/lib/util/time.d.ts +0 -1
  172. package/dist/lib/util/time.d.ts.map +1 -1
  173. package/dist/lib/util/time.js +7 -8
  174. package/dist/lib/util/time.js.map +1 -1
  175. package/dist/lib/util/tlv.d.ts +0 -28
  176. package/dist/lib/util/tlv.d.ts.map +1 -1
  177. package/dist/lib/util/tlv.js +83 -126
  178. package/dist/lib/util/tlv.js.map +1 -1
  179. package/dist/lib/util/uuid.d.ts +0 -10
  180. package/dist/lib/util/uuid.d.ts.map +1 -1
  181. package/dist/lib/util/uuid.js +22 -40
  182. package/dist/lib/util/uuid.js.map +1 -1
  183. package/dist/types.d.ts +0 -35
  184. package/dist/types.d.ts.map +1 -1
  185. package/dist/types.js +1 -1
  186. package/dist/types.js.map +1 -1
  187. package/package.json +29 -28
  188. package/dist/lib/AccessoryLoader.d.ts +0 -28
  189. package/dist/lib/AccessoryLoader.d.ts.map +0 -1
  190. package/dist/lib/AccessoryLoader.js +0 -167
  191. package/dist/lib/AccessoryLoader.js.map +0 -1
  192. package/dist/lib/camera/Camera.d.ts +0 -44
  193. package/dist/lib/camera/Camera.d.ts.map +0 -1
  194. package/dist/lib/camera/Camera.js +0 -36
  195. package/dist/lib/camera/Camera.js.map +0 -1
@@ -1,22 +1,20 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.StreamController = exports.RTPStreamManagement = exports.StreamRequestTypes = exports.AudioStreamingSamplerate = exports.AudioStreamingCodecType = exports.SRTPCryptoSuites = exports.AudioSamplerate = exports.AudioBitrate = exports.VideoCodecPacketizationMode = exports.H264Level = exports.H264Profile = exports.VideoCodecType = void 0;
4
- var tslib_1 = require("tslib");
5
- var assert_1 = tslib_1.__importDefault(require("assert"));
6
- var crypto_1 = tslib_1.__importDefault(require("crypto"));
7
- var debug_1 = tslib_1.__importDefault(require("debug"));
8
- var net_1 = tslib_1.__importDefault(require("net"));
9
- var Characteristic_1 = require("../Characteristic");
10
- var controller_1 = require("../controller");
11
- var Service_1 = require("../Service");
12
- var hapStatusError_1 = require("../util/hapStatusError");
13
- var once_1 = require("../util/once");
14
- var tlv = tslib_1.__importStar(require("../util/tlv"));
15
- var uuid = tslib_1.__importStar(require("../util/uuid"));
16
- // noinspection JSDeprecatedSymbols
17
- var Camera_1 = require("./Camera");
18
- var RTPProxy_1 = tslib_1.__importDefault(require("./RTPProxy"));
19
- var debug = (0, debug_1.default)("HAP-NodeJS:Camera:RTPStreamManagement");
3
+ exports.RTPStreamManagement = exports.StreamRequestTypes = exports.AudioStreamingSamplerate = exports.AudioStreamingCodecType = exports.SRTPCryptoSuites = exports.AudioSamplerate = exports.AudioBitrate = exports.VideoCodecPacketizationMode = exports.H264Level = exports.H264Profile = exports.VideoCodecType = void 0;
4
+ const tslib_1 = require("tslib");
5
+ const assert_1 = tslib_1.__importDefault(require("assert"));
6
+ const crypto_1 = tslib_1.__importDefault(require("crypto"));
7
+ const debug_1 = tslib_1.__importDefault(require("debug"));
8
+ const net_1 = tslib_1.__importDefault(require("net"));
9
+ const Characteristic_1 = require("../Characteristic");
10
+ const controller_1 = require("../controller");
11
+ const Service_1 = require("../Service");
12
+ const hapStatusError_1 = require("../util/hapStatusError");
13
+ const once_1 = require("../util/once");
14
+ const tlv = tslib_1.__importStar(require("../util/tlv"));
15
+ const uuid = tslib_1.__importStar(require("../util/uuid"));
16
+ const RTPProxy_1 = tslib_1.__importDefault(require("./RTPProxy"));
17
+ const debug = (0, debug_1.default)("HAP-NodeJS:Camera:RTPStreamManagement");
20
18
  // ---------------------------------- TLV DEFINITIONS START ----------------------------------
21
19
  var StreamingStatusTypes;
22
20
  (function (StreamingStatusTypes) {
@@ -61,7 +59,7 @@ var VideoCodecType;
61
59
  VideoCodecType[VideoCodecType["H264"] = 0] = "H264";
62
60
  // while the namespace is already reserved for H265 it isn't currently supported.
63
61
  // H265 = 0x01,
64
- })(VideoCodecType = exports.VideoCodecType || (exports.VideoCodecType = {}));
62
+ })(VideoCodecType || (exports.VideoCodecType = VideoCodecType = {}));
65
63
  /**
66
64
  * @group Camera
67
65
  */
@@ -70,7 +68,7 @@ var H264Profile;
70
68
  H264Profile[H264Profile["BASELINE"] = 0] = "BASELINE";
71
69
  H264Profile[H264Profile["MAIN"] = 1] = "MAIN";
72
70
  H264Profile[H264Profile["HIGH"] = 2] = "HIGH";
73
- })(H264Profile = exports.H264Profile || (exports.H264Profile = {}));
71
+ })(H264Profile || (exports.H264Profile = H264Profile = {}));
74
72
  /**
75
73
  * @group Camera
76
74
  */
@@ -79,14 +77,14 @@ var H264Level;
79
77
  H264Level[H264Level["LEVEL3_1"] = 0] = "LEVEL3_1";
80
78
  H264Level[H264Level["LEVEL3_2"] = 1] = "LEVEL3_2";
81
79
  H264Level[H264Level["LEVEL4_0"] = 2] = "LEVEL4_0";
82
- })(H264Level = exports.H264Level || (exports.H264Level = {}));
80
+ })(H264Level || (exports.H264Level = H264Level = {}));
83
81
  /**
84
82
  * @group Camera
85
83
  */
86
84
  var VideoCodecPacketizationMode;
87
85
  (function (VideoCodecPacketizationMode) {
88
86
  VideoCodecPacketizationMode[VideoCodecPacketizationMode["NON_INTERLEAVED"] = 0] = "NON_INTERLEAVED";
89
- })(VideoCodecPacketizationMode = exports.VideoCodecPacketizationMode || (exports.VideoCodecPacketizationMode = {}));
87
+ })(VideoCodecPacketizationMode || (exports.VideoCodecPacketizationMode = VideoCodecPacketizationMode = {}));
90
88
  var VideoCodecCVO;
91
89
  (function (VideoCodecCVO) {
92
90
  VideoCodecCVO[VideoCodecCVO["UNSUPPORTED"] = 0] = "UNSUPPORTED";
@@ -127,7 +125,7 @@ var AudioBitrate;
127
125
  (function (AudioBitrate) {
128
126
  AudioBitrate[AudioBitrate["VARIABLE"] = 0] = "VARIABLE";
129
127
  AudioBitrate[AudioBitrate["CONSTANT"] = 1] = "CONSTANT";
130
- })(AudioBitrate = exports.AudioBitrate || (exports.AudioBitrate = {}));
128
+ })(AudioBitrate || (exports.AudioBitrate = AudioBitrate = {}));
131
129
  /**
132
130
  * @group Camera
133
131
  */
@@ -138,7 +136,7 @@ var AudioSamplerate;
138
136
  AudioSamplerate[AudioSamplerate["KHZ_24"] = 2] = "KHZ_24";
139
137
  // 3, 4, 5 are theoretically defined, but no idea to what kHz value they correspond to
140
138
  // probably KHZ_32, KHZ_44_1, KHZ_48 (as supported by Secure Video recordings)
141
- })(AudioSamplerate = exports.AudioSamplerate || (exports.AudioSamplerate = {}));
139
+ })(AudioSamplerate || (exports.AudioSamplerate = AudioSamplerate = {}));
142
140
  // ----------
143
141
  var SupportedRTPConfigurationTypes;
144
142
  (function (SupportedRTPConfigurationTypes) {
@@ -152,7 +150,7 @@ var SRTPCryptoSuites;
152
150
  SRTPCryptoSuites[SRTPCryptoSuites["AES_CM_128_HMAC_SHA1_80"] = 0] = "AES_CM_128_HMAC_SHA1_80";
153
151
  SRTPCryptoSuites[SRTPCryptoSuites["AES_CM_256_HMAC_SHA1_80"] = 1] = "AES_CM_256_HMAC_SHA1_80";
154
152
  SRTPCryptoSuites[SRTPCryptoSuites["NONE"] = 2] = "NONE";
155
- })(SRTPCryptoSuites = exports.SRTPCryptoSuites || (exports.SRTPCryptoSuites = {}));
153
+ })(SRTPCryptoSuites || (exports.SRTPCryptoSuites = SRTPCryptoSuites = {}));
156
154
  // ----------
157
155
  var SetupEndpointsTypes;
158
156
  (function (SetupEndpointsTypes) {
@@ -261,7 +259,7 @@ var AudioStreamingCodecType;
261
259
  AudioStreamingCodecType["MSBC"] = "mSBC";
262
260
  AudioStreamingCodecType["AMR"] = "AMR";
263
261
  AudioStreamingCodecType["AMR_WB"] = "AMR-WB";
264
- })(AudioStreamingCodecType = exports.AudioStreamingCodecType || (exports.AudioStreamingCodecType = {}));
262
+ })(AudioStreamingCodecType || (exports.AudioStreamingCodecType = AudioStreamingCodecType = {}));
265
263
  /**
266
264
  * @group Camera
267
265
  */
@@ -270,7 +268,7 @@ var AudioStreamingSamplerate;
270
268
  AudioStreamingSamplerate[AudioStreamingSamplerate["KHZ_8"] = 8] = "KHZ_8";
271
269
  AudioStreamingSamplerate[AudioStreamingSamplerate["KHZ_16"] = 16] = "KHZ_16";
272
270
  AudioStreamingSamplerate[AudioStreamingSamplerate["KHZ_24"] = 24] = "KHZ_24";
273
- })(AudioStreamingSamplerate = exports.AudioStreamingSamplerate || (exports.AudioStreamingSamplerate = {}));
271
+ })(AudioStreamingSamplerate || (exports.AudioStreamingSamplerate = AudioStreamingSamplerate = {}));
274
272
  /**
275
273
  * @group Camera
276
274
  */
@@ -279,20 +277,47 @@ var StreamRequestTypes;
279
277
  StreamRequestTypes["RECONFIGURE"] = "reconfigure";
280
278
  StreamRequestTypes["START"] = "start";
281
279
  StreamRequestTypes["STOP"] = "stop";
282
- })(StreamRequestTypes = exports.StreamRequestTypes || (exports.StreamRequestTypes = {}));
280
+ })(StreamRequestTypes || (exports.StreamRequestTypes = StreamRequestTypes = {}));
283
281
  /**
284
282
  * @group Camera
285
283
  */
286
- var RTPStreamManagement = /** @class */ (function () {
287
- function RTPStreamManagement(id, options, delegate, service, disabledThroughOperatingMode) {
288
- this.videoOnly = false;
289
- this.sessionIdentifier = undefined;
290
- /**
291
- * @private private API
292
- */
293
- this.streamStatus = 0 /* StreamingStatus.AVAILABLE */; // use _updateStreamStatus to update this property
294
- this.selectedConfiguration = ""; // base64 representation of the currently selected configuration
295
- this.setupEndpointsResponse = ""; // response of the SetupEndpoints Characteristic
284
+ class RTPStreamManagement {
285
+ id;
286
+ delegate;
287
+ service;
288
+ stateChangeDelegate;
289
+ requireProxy;
290
+ disableAudioProxy;
291
+ supportedCryptoSuites;
292
+ videoOnly = false;
293
+ supportedRTPConfiguration;
294
+ supportedVideoStreamConfiguration;
295
+ supportedAudioStreamConfiguration;
296
+ activeConnection;
297
+ activeConnectionClosedListener;
298
+ sessionIdentifier = undefined;
299
+ /**
300
+ * @private private API
301
+ */
302
+ streamStatus = 0 /* StreamingStatus.AVAILABLE */; // use _updateStreamStatus to update this property
303
+ ipVersion; // ip version for the current session
304
+ selectedConfiguration = ""; // base64 representation of the currently selected configuration
305
+ setupEndpointsResponse = ""; // response of the SetupEndpoints Characteristic
306
+ /**
307
+ * @private deprecated API
308
+ */
309
+ audioProxy;
310
+ /**
311
+ * @private deprecated API
312
+ */
313
+ videoProxy;
314
+ /**
315
+ * A RTPStreamManagement is considered disabled if `HomeKitCameraActive` is set to false.
316
+ * We use a closure based approach to retrieve the value of this characteristic.
317
+ * The characteristic is managed by the RecordingManagement.
318
+ */
319
+ disabledThroughOperatingMode;
320
+ constructor(id, options, delegate, service, disabledThroughOperatingMode) {
296
321
  this.id = id;
297
322
  this.delegate = delegate;
298
323
  this.requireProxy = options.proxy || false;
@@ -319,48 +344,37 @@ var RTPStreamManagement = /** @class */ (function () {
319
344
  this.resetSelectedStreamConfiguration();
320
345
  this.disabledThroughOperatingMode = disabledThroughOperatingMode;
321
346
  }
322
- RTPStreamManagement.prototype.forceStop = function () {
347
+ forceStop() {
323
348
  this.handleSessionClosed();
324
- };
325
- RTPStreamManagement.prototype.getService = function () {
349
+ }
350
+ getService() {
326
351
  return this.service;
327
- };
328
- // noinspection JSUnusedGlobalSymbols,JSUnusedLocalSymbols
329
- /**
330
- * @deprecated
331
- */
332
- // eslint-disable-next-line @typescript-eslint/no-unused-vars
333
- RTPStreamManagement.prototype.handleCloseConnection = function (connectionID) {
334
- // This method is only here for legacy compatibility. It used to be called by legacy style CameraSource
335
- // implementations to signal that the associated HAP connection was closed.
336
- // This is now handled automatically. Thus, we don't need to do anything anymore.
337
- };
338
- RTPStreamManagement.prototype.handleFactoryReset = function () {
352
+ }
353
+ handleFactoryReset() {
339
354
  this.resetSelectedStreamConfiguration();
340
355
  this.resetSetupEndpointsResponse();
341
356
  this.service.updateCharacteristic(Characteristic_1.Characteristic.Active, true);
342
357
  // on a factory reset the assumption is that all connections were already terminated and thus "handleStopStream" was already called
343
- };
344
- RTPStreamManagement.prototype.destroy = function () {
358
+ }
359
+ destroy() {
345
360
  if (this.activeConnection) {
346
361
  this._handleStopStream();
347
362
  }
348
- };
349
- RTPStreamManagement.prototype.constructService = function (id) {
350
- var managementService = new Service_1.Service.CameraRTPStreamManagement("", id.toString());
363
+ }
364
+ constructService(id) {
365
+ const managementService = new Service_1.Service.CameraRTPStreamManagement("", id.toString());
351
366
  // this service is required only when recording is enabled. We don't really have access to this info here,
352
367
  // so we just add the characteristic. Doesn't really hurt.
353
368
  managementService.setCharacteristic(Characteristic_1.Characteristic.Active, true);
354
369
  return managementService;
355
- };
356
- RTPStreamManagement.prototype.setupServiceHandlers = function () {
357
- var _this = this;
370
+ }
371
+ setupServiceHandlers() {
358
372
  if (!this.service.testCharacteristic(Characteristic_1.Characteristic.Active)) {
359
373
  // the active characteristic might not be present on some older configurations.
360
374
  this.service.setCharacteristic(Characteristic_1.Characteristic.Active, true);
361
375
  }
362
376
  this.service.getCharacteristic(Characteristic_1.Characteristic.Active)
363
- .on("change" /* CharacteristicEventTypes.CHANGE */, function () { var _a; return (_a = _this.stateChangeDelegate) === null || _a === void 0 ? void 0 : _a.call(_this); })
377
+ .on("change" /* CharacteristicEventTypes.CHANGE */, () => this.stateChangeDelegate?.())
364
378
  .setProps({ adminOnlyAccess: [1 /* Access.WRITE */] });
365
379
  // ensure that configurations are up-to-date and reflected in the characteristic values
366
380
  this.service.setCharacteristic(Characteristic_1.Characteristic.SupportedRTPConfiguration, this.supportedRTPConfiguration);
@@ -369,42 +383,41 @@ var RTPStreamManagement = /** @class */ (function () {
369
383
  this._updateStreamStatus(0 /* StreamingStatus.AVAILABLE */); // reset streaming status to available
370
384
  this.service.setCharacteristic(Characteristic_1.Characteristic.SetupEndpoints, this.setupEndpointsResponse); // reset SetupEndpoints to default
371
385
  this.service.getCharacteristic(Characteristic_1.Characteristic.SelectedRTPStreamConfiguration)
372
- .on("get" /* CharacteristicEventTypes.GET */, function (callback) {
373
- if (_this.streamingIsDisabled()) {
386
+ .on("get" /* CharacteristicEventTypes.GET */, callback => {
387
+ if (this.streamingIsDisabled()) {
374
388
  callback(null, tlv.encode(1 /* SelectedRTPStreamConfigurationTypes.SESSION_CONTROL */, tlv.encode(2 /* SessionControlTypes.COMMAND */, SessionControlCommand.SUSPEND_SESSION)).toString("base64"));
375
389
  return;
376
390
  }
377
- callback(null, _this.selectedConfiguration);
391
+ callback(null, this.selectedConfiguration);
378
392
  })
379
393
  .on("set" /* CharacteristicEventTypes.SET */, this._handleSelectedStreamConfigurationWrite.bind(this));
380
394
  this.service.getCharacteristic(Characteristic_1.Characteristic.SetupEndpoints)
381
- .on("get" /* CharacteristicEventTypes.GET */, function (callback) {
382
- if (_this.streamingIsDisabled()) {
395
+ .on("get" /* CharacteristicEventTypes.GET */, callback => {
396
+ if (this.streamingIsDisabled()) {
383
397
  callback(null, tlv.encode(2 /* SetupEndpointsResponseTypes.STATUS */, 2 /* SetupEndpointsStatus.ERROR */).toString("base64"));
384
398
  return;
385
399
  }
386
- callback(null, _this.setupEndpointsResponse);
400
+ callback(null, this.setupEndpointsResponse);
387
401
  })
388
- .on("set" /* CharacteristicEventTypes.SET */, function (value, callback, context, connection) {
402
+ .on("set" /* CharacteristicEventTypes.SET */, (value, callback, context, connection) => {
389
403
  if (!connection) {
390
404
  debug("Set event handler for SetupEndpoints cannot be called from plugin. Connection undefined!");
391
405
  callback(-70410 /* HAPStatus.INVALID_VALUE_IN_REQUEST */);
392
406
  return;
393
407
  }
394
- _this.handleSetupEndpoints(value, callback, connection);
408
+ this.handleSetupEndpoints(value, callback, connection);
395
409
  });
396
- };
397
- RTPStreamManagement.prototype.handleSessionClosed = function () {
410
+ }
411
+ handleSessionClosed() {
398
412
  this.resetSelectedStreamConfiguration();
399
413
  this.resetSetupEndpointsResponse();
400
414
  if (this.activeConnection) {
401
415
  this.activeConnection.removeListener("closed" /* HAPConnectionEvent.CLOSED */, this.activeConnectionClosedListener);
416
+ this.activeConnection.setMaxListeners(this.activeConnection.getMaxListeners() - 1);
402
417
  this.activeConnection = undefined;
403
418
  }
404
419
  this._updateStreamStatus(0 /* StreamingStatus.AVAILABLE */);
405
420
  this.sessionIdentifier = undefined;
406
- // noinspection JSDeprecatedSymbols
407
- this.connectionID = undefined;
408
421
  this.ipVersion = undefined;
409
422
  if (this.videoProxy) {
410
423
  this.videoProxy.destroy();
@@ -414,51 +427,49 @@ var RTPStreamManagement = /** @class */ (function () {
414
427
  this.audioProxy.destroy();
415
428
  this.audioProxy = undefined;
416
429
  }
417
- };
418
- RTPStreamManagement.prototype.streamingIsDisabled = function (callback) {
419
- var _a;
430
+ }
431
+ streamingIsDisabled(callback) {
420
432
  if (!this.service.getCharacteristic(Characteristic_1.Characteristic.Active).value) {
421
433
  callback && callback(new hapStatusError_1.HapStatusError(-70412 /* HAPStatus.NOT_ALLOWED_IN_CURRENT_STATE */));
422
434
  return true;
423
435
  }
424
- if ((_a = this.disabledThroughOperatingMode) === null || _a === void 0 ? void 0 : _a.call(this)) {
436
+ if (this.disabledThroughOperatingMode?.()) {
425
437
  callback && callback(new hapStatusError_1.HapStatusError(-70412 /* HAPStatus.NOT_ALLOWED_IN_CURRENT_STATE */));
426
438
  return true;
427
439
  }
428
440
  return false;
429
- };
430
- RTPStreamManagement.prototype._handleSelectedStreamConfigurationWrite = function (value, callback) {
431
- var _this = this;
441
+ }
442
+ _handleSelectedStreamConfigurationWrite(value, callback) {
432
443
  if (this.streamingIsDisabled(callback)) {
433
444
  return;
434
445
  }
435
- var data = Buffer.from(value, "base64");
436
- var objects = tlv.decode(data);
437
- var sessionControl = tlv.decode(objects[1 /* SelectedRTPStreamConfigurationTypes.SESSION_CONTROL */]);
438
- var sessionIdentifier = uuid.unparse(sessionControl[1 /* SessionControlTypes.SESSION_IDENTIFIER */]);
439
- var requestType = sessionControl[2 /* SessionControlTypes.COMMAND */][0];
446
+ const data = Buffer.from(value, "base64");
447
+ const objects = tlv.decode(data);
448
+ const sessionControl = tlv.decode(objects[1 /* SelectedRTPStreamConfigurationTypes.SESSION_CONTROL */]);
449
+ const sessionIdentifier = uuid.unparse(sessionControl[1 /* SessionControlTypes.SESSION_IDENTIFIER */]);
450
+ const requestType = sessionControl[2 /* SessionControlTypes.COMMAND */][0];
440
451
  if (sessionIdentifier !== this.sessionIdentifier) {
441
- debug("Received unknown session Identifier with request to ".concat(SessionControlCommand[requestType]));
452
+ debug(`Received unknown session Identifier with request to ${SessionControlCommand[requestType]}`);
442
453
  callback(-70410 /* HAPStatus.INVALID_VALUE_IN_REQUEST */);
443
454
  return;
444
455
  }
445
456
  this.selectedConfiguration = value;
446
457
  // intercept the callback chain to check if an error occurred.
447
- var streamCallback = function (error, writeResponse) {
458
+ const streamCallback = (error, writeResponse) => {
448
459
  callback(error, writeResponse); // does not support writeResponse, but how knows what comes in the future.
449
460
  if (error) {
450
- _this.handleSessionClosed();
461
+ this.handleSessionClosed();
451
462
  }
452
463
  };
453
464
  switch (requestType) {
454
465
  case SessionControlCommand.START_SESSION: {
455
- var selectedVideoParameters = tlv.decode(objects[2 /* SelectedRTPStreamConfigurationTypes.SELECTED_VIDEO_PARAMETERS */]);
456
- var selectedAudioParameters = tlv.decode(objects[3 /* SelectedRTPStreamConfigurationTypes.SELECTED_AUDIO_PARAMETERS */]);
466
+ const selectedVideoParameters = tlv.decode(objects[2 /* SelectedRTPStreamConfigurationTypes.SELECTED_VIDEO_PARAMETERS */]);
467
+ const selectedAudioParameters = tlv.decode(objects[3 /* SelectedRTPStreamConfigurationTypes.SELECTED_AUDIO_PARAMETERS */]);
457
468
  this._handleStartStream(selectedVideoParameters, selectedAudioParameters, streamCallback);
458
469
  break;
459
470
  }
460
471
  case SessionControlCommand.RECONFIGURE_SESSION: {
461
- var reconfiguredVideoParameters = tlv.decode(objects[2 /* SelectedRTPStreamConfigurationTypes.SELECTED_VIDEO_PARAMETERS */]);
472
+ const reconfiguredVideoParameters = tlv.decode(objects[2 /* SelectedRTPStreamConfigurationTypes.SELECTED_VIDEO_PARAMETERS */]);
462
473
  this.handleReconfigureStream(reconfiguredVideoParameters, streamCallback);
463
474
  break;
464
475
  }
@@ -468,68 +479,68 @@ var RTPStreamManagement = /** @class */ (function () {
468
479
  case SessionControlCommand.RESUME_SESSION:
469
480
  case SessionControlCommand.SUSPEND_SESSION:
470
481
  default:
471
- debug("Unhandled request type ".concat(SessionControlCommand[requestType]));
482
+ debug(`Unhandled request type ${SessionControlCommand[requestType]}`);
472
483
  callback(-70410 /* HAPStatus.INVALID_VALUE_IN_REQUEST */);
473
484
  return;
474
485
  }
475
- };
476
- RTPStreamManagement.prototype._handleStartStream = function (videoConfiguration, audioConfiguration, callback) {
486
+ }
487
+ _handleStartStream(videoConfiguration, audioConfiguration, callback) {
477
488
  // selected video configuration
478
489
  // noinspection JSUnusedLocalSymbols
479
- var videoCodec = videoConfiguration[1 /* SelectedVideoParametersTypes.CODEC_TYPE */]; // always 0x00 for h264
480
- var videoParametersTLV = videoConfiguration[2 /* SelectedVideoParametersTypes.CODEC_PARAMETERS */];
481
- var videoAttributesTLV = videoConfiguration[3 /* SelectedVideoParametersTypes.ATTRIBUTES */];
482
- var videoRTPParametersTLV = videoConfiguration[4 /* SelectedVideoParametersTypes.RTP_PARAMETERS */];
490
+ const videoCodec = videoConfiguration[1 /* SelectedVideoParametersTypes.CODEC_TYPE */]; // always 0x00 for h264
491
+ const videoParametersTLV = videoConfiguration[2 /* SelectedVideoParametersTypes.CODEC_PARAMETERS */];
492
+ const videoAttributesTLV = videoConfiguration[3 /* SelectedVideoParametersTypes.ATTRIBUTES */];
493
+ const videoRTPParametersTLV = videoConfiguration[4 /* SelectedVideoParametersTypes.RTP_PARAMETERS */];
483
494
  // video parameters
484
- var videoParameters = tlv.decode(videoParametersTLV);
485
- var h264Profile = videoParameters[1 /* VideoCodecParametersTypes.PROFILE_ID */][0];
486
- var h264Level = videoParameters[2 /* VideoCodecParametersTypes.LEVEL */][0];
487
- var packetizationMode = videoParameters[3 /* VideoCodecParametersTypes.PACKETIZATION_MODE */][0];
488
- var cvoEnabled = videoParameters[4 /* VideoCodecParametersTypes.CVO_ENABLED */];
489
- var cvoId = undefined;
495
+ const videoParameters = tlv.decode(videoParametersTLV);
496
+ const h264Profile = videoParameters[1 /* VideoCodecParametersTypes.PROFILE_ID */][0];
497
+ const h264Level = videoParameters[2 /* VideoCodecParametersTypes.LEVEL */][0];
498
+ const packetizationMode = videoParameters[3 /* VideoCodecParametersTypes.PACKETIZATION_MODE */][0];
499
+ const cvoEnabled = videoParameters[4 /* VideoCodecParametersTypes.CVO_ENABLED */];
500
+ let cvoId = undefined;
490
501
  if (cvoEnabled && cvoEnabled[0] === 1 /* VideoCodecCVO.SUPPORTED */) {
491
502
  cvoId = videoParameters[5 /* VideoCodecParametersTypes.CVO_ID */].readUInt8(0);
492
503
  }
493
504
  // video attributes
494
- var videoAttributes = tlv.decode(videoAttributesTLV);
495
- var width = videoAttributes[1 /* VideoAttributesTypes.IMAGE_WIDTH */].readUInt16LE(0);
496
- var height = videoAttributes[2 /* VideoAttributesTypes.IMAGE_HEIGHT */].readUInt16LE(0);
497
- var frameRate = videoAttributes[3 /* VideoAttributesTypes.FRAME_RATE */].readUInt8(0);
505
+ const videoAttributes = tlv.decode(videoAttributesTLV);
506
+ const width = videoAttributes[1 /* VideoAttributesTypes.IMAGE_WIDTH */].readUInt16LE(0);
507
+ const height = videoAttributes[2 /* VideoAttributesTypes.IMAGE_HEIGHT */].readUInt16LE(0);
508
+ const frameRate = videoAttributes[3 /* VideoAttributesTypes.FRAME_RATE */].readUInt8(0);
498
509
  // video rtp parameters
499
- var videoRTPParameters = tlv.decode(videoRTPParametersTLV);
500
- var videoPayloadType = videoRTPParameters[1 /* VideoRTPParametersTypes.PAYLOAD_TYPE */].readUInt8(0); // 99
501
- var videoSSRC = videoRTPParameters[2 /* VideoRTPParametersTypes.SYNCHRONIZATION_SOURCE */].readUInt32LE(0);
502
- var videoMaximumBitrate = videoRTPParameters[3 /* VideoRTPParametersTypes.MAX_BIT_RATE */].readUInt16LE(0);
503
- var videoRTCPInterval = videoRTPParameters[4 /* VideoRTPParametersTypes.MIN_RTCP_INTERVAL */].readFloatLE(0);
504
- var maxMTU = this.ipVersion === "ipv6" ? 1228 : 1378; // default values ipv4: 1378 bytes; ipv6: 1228 bytes
510
+ const videoRTPParameters = tlv.decode(videoRTPParametersTLV);
511
+ const videoPayloadType = videoRTPParameters[1 /* VideoRTPParametersTypes.PAYLOAD_TYPE */].readUInt8(0); // 99
512
+ const videoSSRC = videoRTPParameters[2 /* VideoRTPParametersTypes.SYNCHRONIZATION_SOURCE */].readUInt32LE(0);
513
+ const videoMaximumBitrate = videoRTPParameters[3 /* VideoRTPParametersTypes.MAX_BIT_RATE */].readUInt16LE(0);
514
+ const videoRTCPInterval = videoRTPParameters[4 /* VideoRTPParametersTypes.MIN_RTCP_INTERVAL */].readFloatLE(0);
515
+ let maxMTU = this.ipVersion === "ipv6" ? 1228 : 1378; // default values ipv4: 1378 bytes; ipv6: 1228 bytes
505
516
  if (videoRTPParameters[5 /* VideoRTPParametersTypes.MAX_MTU */]) {
506
517
  maxMTU = videoRTPParameters[5 /* VideoRTPParametersTypes.MAX_MTU */].readUInt16LE(0);
507
518
  }
508
519
  // selected audio configuration
509
- var audioCodec = audioConfiguration[1 /* SelectedAudioParametersTypes.CODEC_TYPE */][0];
510
- var audioParametersTLV = audioConfiguration[2 /* SelectedAudioParametersTypes.CODEC_PARAMETERS */];
511
- var audioRTPParametersTLV = audioConfiguration[3 /* SelectedAudioParametersTypes.RTP_PARAMETERS */];
512
- var comfortNoise = !!audioConfiguration[4 /* SelectedAudioParametersTypes.COMFORT_NOISE */].readUInt8(0);
520
+ const audioCodec = audioConfiguration[1 /* SelectedAudioParametersTypes.CODEC_TYPE */][0];
521
+ const audioParametersTLV = audioConfiguration[2 /* SelectedAudioParametersTypes.CODEC_PARAMETERS */];
522
+ const audioRTPParametersTLV = audioConfiguration[3 /* SelectedAudioParametersTypes.RTP_PARAMETERS */];
523
+ const comfortNoise = !!audioConfiguration[4 /* SelectedAudioParametersTypes.COMFORT_NOISE */].readUInt8(0);
513
524
  // audio parameters
514
- var audioParameters = tlv.decode(audioParametersTLV);
515
- var channels = audioParameters[1 /* AudioCodecParametersTypes.CHANNEL */][0];
516
- var audioBitrate = audioParameters[2 /* AudioCodecParametersTypes.BIT_RATE */][0];
517
- var samplerate = audioParameters[3 /* AudioCodecParametersTypes.SAMPLE_RATE */][0];
518
- var rtpPacketTime = audioParameters[4 /* AudioCodecParametersTypes.PACKET_TIME */].readUInt8(0);
525
+ const audioParameters = tlv.decode(audioParametersTLV);
526
+ const channels = audioParameters[1 /* AudioCodecParametersTypes.CHANNEL */][0];
527
+ const audioBitrate = audioParameters[2 /* AudioCodecParametersTypes.BIT_RATE */][0];
528
+ const samplerate = audioParameters[3 /* AudioCodecParametersTypes.SAMPLE_RATE */][0];
529
+ const rtpPacketTime = audioParameters[4 /* AudioCodecParametersTypes.PACKET_TIME */].readUInt8(0);
519
530
  // audio rtp parameters
520
- var audioRTPParameters = tlv.decode(audioRTPParametersTLV);
521
- var audioPayloadType = audioRTPParameters[1 /* AudioRTPParametersTypes.PAYLOAD_TYPE */].readUInt8(0); // 110
522
- var audioSSRC = audioRTPParameters[2 /* AudioRTPParametersTypes.SYNCHRONIZATION_SOURCE */].readUInt32LE(0);
523
- var audioMaximumBitrate = audioRTPParameters[3 /* AudioRTPParametersTypes.MAX_BIT_RATE */].readUInt16LE(0);
524
- var audioRTCPInterval = audioRTPParameters[4 /* AudioRTPParametersTypes.MIN_RTCP_INTERVAL */].readFloatLE(0);
525
- var comfortNoisePayloadType = audioRTPParameters[6 /* AudioRTPParametersTypes.COMFORT_NOISE_PAYLOAD_TYPE */].readUInt8(0); // 13
531
+ const audioRTPParameters = tlv.decode(audioRTPParametersTLV);
532
+ const audioPayloadType = audioRTPParameters[1 /* AudioRTPParametersTypes.PAYLOAD_TYPE */].readUInt8(0); // 110
533
+ const audioSSRC = audioRTPParameters[2 /* AudioRTPParametersTypes.SYNCHRONIZATION_SOURCE */].readUInt32LE(0);
534
+ const audioMaximumBitrate = audioRTPParameters[3 /* AudioRTPParametersTypes.MAX_BIT_RATE */].readUInt16LE(0);
535
+ const audioRTCPInterval = audioRTPParameters[4 /* AudioRTPParametersTypes.MIN_RTCP_INTERVAL */].readFloatLE(0);
536
+ const comfortNoisePayloadType = audioRTPParameters[6 /* AudioRTPParametersTypes.COMFORT_NOISE_PAYLOAD_TYPE */].readUInt8(0); // 13
526
537
  if (this.requireProxy) {
527
538
  this.videoProxy.setOutgoingPayloadType(videoPayloadType);
528
539
  if (!this.disableAudioProxy) {
529
540
  this.audioProxy.setOutgoingPayloadType(audioPayloadType);
530
541
  }
531
542
  }
532
- var videoInfo = {
543
+ const videoInfo = {
533
544
  codec: videoCodec.readUInt8(0),
534
545
  profile: h264Profile,
535
546
  level: h264Level,
@@ -544,8 +555,8 @@ var RTPStreamManagement = /** @class */ (function () {
544
555
  rtcp_interval: videoRTCPInterval,
545
556
  mtu: maxMTU,
546
557
  };
547
- var audioCodecName;
548
- var samplerateNum;
558
+ let audioCodecName;
559
+ let samplerateNum;
549
560
  switch (audioCodec) {
550
561
  case 0 /* AudioCodecTypes.PCMU */:
551
562
  audioCodecName = "PCMU" /* AudioStreamingCodecType.PCMU */;
@@ -569,7 +580,7 @@ var RTPStreamManagement = /** @class */ (function () {
569
580
  audioCodecName = "AMR-WB" /* AudioStreamingCodecType.AMR_WB */;
570
581
  break;
571
582
  default:
572
- throw new Error("Encountered unknown selected audio codec ".concat(audioCodec));
583
+ throw new Error(`Encountered unknown selected audio codec ${audioCodec}`);
573
584
  }
574
585
  switch (samplerate) {
575
586
  case 0 /* AudioSamplerate.KHZ_8 */:
@@ -582,9 +593,9 @@ var RTPStreamManagement = /** @class */ (function () {
582
593
  samplerateNum = 24;
583
594
  break;
584
595
  default:
585
- throw new Error("Encountered unknown selected audio samplerate ".concat(samplerate));
596
+ throw new Error(`Encountered unknown selected audio samplerate ${samplerate}`);
586
597
  }
587
- var audioInfo = {
598
+ const audioInfo = {
588
599
  codec: audioCodecName,
589
600
  channel: channels,
590
601
  bit_rate: audioBitrate,
@@ -597,58 +608,57 @@ var RTPStreamManagement = /** @class */ (function () {
597
608
  comfort_pt: comfortNoisePayloadType,
598
609
  comfortNoiseEnabled: comfortNoise,
599
610
  };
600
- var request = {
611
+ const request = {
601
612
  sessionID: this.sessionIdentifier,
602
613
  type: "start" /* StreamRequestTypes.START */,
603
614
  video: videoInfo,
604
615
  audio: audioInfo,
605
616
  };
606
- this.delegate.handleStreamRequest(request, function (error) { return callback(error); });
607
- };
608
- RTPStreamManagement.prototype.handleReconfigureStream = function (videoConfiguration, callback) {
617
+ this.delegate.handleStreamRequest(request, error => callback(error));
618
+ }
619
+ handleReconfigureStream(videoConfiguration, callback) {
609
620
  // selected video configuration
610
- var videoAttributesTLV = videoConfiguration[3 /* SelectedVideoParametersTypes.ATTRIBUTES */];
611
- var videoRTPParametersTLV = videoConfiguration[4 /* SelectedVideoParametersTypes.RTP_PARAMETERS */];
621
+ const videoAttributesTLV = videoConfiguration[3 /* SelectedVideoParametersTypes.ATTRIBUTES */];
622
+ const videoRTPParametersTLV = videoConfiguration[4 /* SelectedVideoParametersTypes.RTP_PARAMETERS */];
612
623
  // video attributes
613
- var videoAttributes = tlv.decode(videoAttributesTLV);
614
- var width = videoAttributes[1 /* VideoAttributesTypes.IMAGE_WIDTH */].readUInt16LE(0);
615
- var height = videoAttributes[2 /* VideoAttributesTypes.IMAGE_HEIGHT */].readUInt16LE(0);
616
- var frameRate = videoAttributes[3 /* VideoAttributesTypes.FRAME_RATE */].readUInt8(0);
624
+ const videoAttributes = tlv.decode(videoAttributesTLV);
625
+ const width = videoAttributes[1 /* VideoAttributesTypes.IMAGE_WIDTH */].readUInt16LE(0);
626
+ const height = videoAttributes[2 /* VideoAttributesTypes.IMAGE_HEIGHT */].readUInt16LE(0);
627
+ const frameRate = videoAttributes[3 /* VideoAttributesTypes.FRAME_RATE */].readUInt8(0);
617
628
  // video rtp parameters
618
- var videoRTPParameters = tlv.decode(videoRTPParametersTLV);
619
- var videoMaximumBitrate = videoRTPParameters[3 /* VideoRTPParametersTypes.MAX_BIT_RATE */].readUInt16LE(0);
629
+ const videoRTPParameters = tlv.decode(videoRTPParametersTLV);
630
+ const videoMaximumBitrate = videoRTPParameters[3 /* VideoRTPParametersTypes.MAX_BIT_RATE */].readUInt16LE(0);
620
631
  // seems to be always zero, use default of 0.5
621
- var videoRTCPInterval = videoRTPParameters[4 /* VideoRTPParametersTypes.MIN_RTCP_INTERVAL */].readFloatLE(0) || 0.5;
622
- var reconfiguredVideoInfo = {
632
+ const videoRTCPInterval = videoRTPParameters[4 /* VideoRTPParametersTypes.MIN_RTCP_INTERVAL */].readFloatLE(0) || 0.5;
633
+ const reconfiguredVideoInfo = {
623
634
  width: width,
624
635
  height: height,
625
636
  fps: frameRate,
626
637
  max_bit_rate: videoMaximumBitrate,
627
638
  rtcp_interval: videoRTCPInterval,
628
639
  };
629
- var request = {
640
+ const request = {
630
641
  sessionID: this.sessionIdentifier,
631
642
  type: "reconfigure" /* StreamRequestTypes.RECONFIGURE */,
632
643
  video: reconfiguredVideoInfo,
633
644
  };
634
- this.delegate.handleStreamRequest(request, function (error) { return callback(error); });
635
- };
636
- RTPStreamManagement.prototype._handleStopStream = function (callback) {
637
- var request = {
638
- sessionID: this.sessionIdentifier,
645
+ this.delegate.handleStreamRequest(request, error => callback(error));
646
+ }
647
+ _handleStopStream(callback) {
648
+ const request = {
649
+ sessionID: this.sessionIdentifier, // save sessionIdentifier before handleSessionClosed is called
639
650
  type: "stop" /* StreamRequestTypes.STOP */,
640
651
  };
641
652
  this.handleSessionClosed();
642
- this.delegate.handleStreamRequest(request, function (error) { return callback ? callback(error) : undefined; });
643
- };
644
- RTPStreamManagement.prototype.handleSetupEndpoints = function (value, callback, connection) {
645
- var _this = this;
653
+ this.delegate.handleStreamRequest(request, error => callback ? callback(error) : undefined);
654
+ }
655
+ handleSetupEndpoints(value, callback, connection) {
646
656
  if (this.streamingIsDisabled(callback)) {
647
657
  return;
648
658
  }
649
- var data = Buffer.from(value, "base64");
650
- var objects = tlv.decode(data);
651
- var sessionIdentifier = uuid.unparse(objects[1 /* SetupEndpointsTypes.SESSION_ID */]);
659
+ const data = Buffer.from(value, "base64");
660
+ const objects = tlv.decode(data);
661
+ const sessionIdentifier = uuid.unparse(objects[1 /* SetupEndpointsTypes.SESSION_ID */]);
652
662
  if (this.streamStatus !== 0 /* StreamingStatus.AVAILABLE */) {
653
663
  this.setupEndpointsResponse = tlv.encode(1 /* SetupEndpointsResponseTypes.SESSION_ID */, uuid.write(sessionIdentifier), 2 /* SetupEndpointsResponseTypes.STATUS */, 1 /* SetupEndpointsStatus.BUSY */).toString("base64");
654
664
  callback();
@@ -656,33 +666,33 @@ var RTPStreamManagement = /** @class */ (function () {
656
666
  }
657
667
  (0, assert_1.default)(this.activeConnection == null, "Found non-nil `activeConnection` when trying to setup streaming endpoints, even though streamStatus is reported to be AVAILABLE!");
658
668
  this.activeConnection = connection;
669
+ this.activeConnection.setMaxListeners(this.activeConnection.getMaxListeners() + 1);
659
670
  this.activeConnection.on("closed" /* HAPConnectionEvent.CLOSED */, this.activeConnectionClosedListener);
660
- // noinspection JSDeprecatedSymbols
661
- this.connectionID = connection.sessionID;
662
671
  this.sessionIdentifier = sessionIdentifier;
663
672
  this._updateStreamStatus(1 /* StreamingStatus.IN_USE */);
664
673
  // Address
665
- var targetAddressPayload = objects[3 /* SetupEndpointsTypes.CONTROLLER_ADDRESS */];
666
- var processedAddressInfo = tlv.decode(targetAddressPayload);
667
- var addressVersion = processedAddressInfo[1 /* AddressTypes.ADDRESS_VERSION */][0];
668
- var controllerAddress = processedAddressInfo[2 /* AddressTypes.ADDRESS */].toString("utf8");
669
- var targetVideoPort = processedAddressInfo[3 /* AddressTypes.VIDEO_RTP_PORT */].readUInt16LE(0);
670
- var targetAudioPort = processedAddressInfo[4 /* AddressTypes.AUDIO_RTP_PORT */].readUInt16LE(0);
674
+ const targetAddressPayload = objects[3 /* SetupEndpointsTypes.CONTROLLER_ADDRESS */];
675
+ const processedAddressInfo = tlv.decode(targetAddressPayload);
676
+ const addressVersion = processedAddressInfo[1 /* AddressTypes.ADDRESS_VERSION */][0];
677
+ const controllerAddress = processedAddressInfo[2 /* AddressTypes.ADDRESS */].toString("utf8");
678
+ const targetVideoPort = processedAddressInfo[3 /* AddressTypes.VIDEO_RTP_PORT */].readUInt16LE(0);
679
+ const targetAudioPort = processedAddressInfo[4 /* AddressTypes.AUDIO_RTP_PORT */].readUInt16LE(0);
671
680
  // Video SRTP Params
672
- var videoSRTPPayload = objects[4 /* SetupEndpointsTypes.VIDEO_SRTP_PARAMETERS */];
673
- var processedVideoInfo = tlv.decode(videoSRTPPayload);
674
- var videoCryptoSuite = processedVideoInfo[1 /* SRTPParametersTypes.SRTP_CRYPTO_SUITE */][0];
675
- var videoMasterKey = processedVideoInfo[2 /* SRTPParametersTypes.MASTER_KEY */];
676
- var videoMasterSalt = processedVideoInfo[3 /* SRTPParametersTypes.MASTER_SALT */];
681
+ const videoSRTPPayload = objects[4 /* SetupEndpointsTypes.VIDEO_SRTP_PARAMETERS */];
682
+ const processedVideoInfo = tlv.decode(videoSRTPPayload);
683
+ const videoCryptoSuite = processedVideoInfo[1 /* SRTPParametersTypes.SRTP_CRYPTO_SUITE */][0];
684
+ const videoMasterKey = processedVideoInfo[2 /* SRTPParametersTypes.MASTER_KEY */];
685
+ const videoMasterSalt = processedVideoInfo[3 /* SRTPParametersTypes.MASTER_SALT */];
677
686
  // Audio SRTP Params
678
- var audioSRTPPayload = objects[5 /* SetupEndpointsTypes.AUDIO_SRTP_PARAMETERS */];
679
- var processedAudioInfo = tlv.decode(audioSRTPPayload);
680
- var audioCryptoSuite = processedAudioInfo[1 /* SRTPParametersTypes.SRTP_CRYPTO_SUITE */][0];
681
- var audioMasterKey = processedAudioInfo[2 /* SRTPParametersTypes.MASTER_KEY */];
682
- var audioMasterSalt = processedAudioInfo[3 /* SRTPParametersTypes.MASTER_SALT */];
687
+ const audioSRTPPayload = objects[5 /* SetupEndpointsTypes.AUDIO_SRTP_PARAMETERS */];
688
+ const processedAudioInfo = tlv.decode(audioSRTPPayload);
689
+ const audioCryptoSuite = processedAudioInfo[1 /* SRTPParametersTypes.SRTP_CRYPTO_SUITE */][0];
690
+ const audioMasterKey = processedAudioInfo[2 /* SRTPParametersTypes.MASTER_KEY */];
691
+ const audioMasterSalt = processedAudioInfo[3 /* SRTPParametersTypes.MASTER_SALT */];
683
692
  debug("Session: ", sessionIdentifier, "\nControllerAddress: ", controllerAddress, "\nVideoPort: ", targetVideoPort, "\nAudioPort: ", targetAudioPort, "\nVideo Crypto: ", videoCryptoSuite, "\nVideo Master Key: ", videoMasterKey, "\nVideo Master Salt: ", videoMasterSalt, "\nAudio Crypto: ", audioCryptoSuite, "\nAudio Master Key: ", audioMasterKey, "\nAudio Master Salt: ", audioMasterSalt);
684
- var prepareRequest = {
693
+ const prepareRequest = {
685
694
  sessionID: sessionIdentifier,
695
+ sourceAddress: connection.localAddress,
686
696
  targetAddress: controllerAddress,
687
697
  addressVersion: addressVersion === 1 /* IPAddressVersion.IPV6 */ ? "ipv6" : "ipv4",
688
698
  video: {
@@ -698,72 +708,72 @@ var RTPStreamManagement = /** @class */ (function () {
698
708
  srtp_salt: audioMasterSalt,
699
709
  },
700
710
  };
701
- var promises = [];
711
+ const promises = [];
702
712
  if (this.requireProxy) {
703
713
  prepareRequest.targetAddress = connection.getLocalAddress(addressVersion === 1 /* IPAddressVersion.IPV6 */ ? "ipv6" : "ipv4"); // ip versions must be the same
704
714
  this.videoProxy = new RTPProxy_1.default({
705
715
  outgoingAddress: controllerAddress,
706
716
  outgoingPort: targetVideoPort,
707
- outgoingSSRC: crypto_1.default.randomBytes(4).readUInt32LE(0),
717
+ outgoingSSRC: crypto_1.default.randomBytes(4).readUInt32LE(0), // videoSSRC
708
718
  disabled: false,
709
719
  });
710
- promises.push(this.videoProxy.setup().then(function () {
711
- prepareRequest.video.proxy_rtp = _this.videoProxy.incomingRTPPort();
712
- prepareRequest.video.proxy_rtcp = _this.videoProxy.incomingRTCPPort();
720
+ promises.push(this.videoProxy.setup().then(() => {
721
+ prepareRequest.video.proxy_rtp = this.videoProxy.incomingRTPPort();
722
+ prepareRequest.video.proxy_rtcp = this.videoProxy.incomingRTCPPort();
713
723
  }));
714
724
  if (!this.disableAudioProxy) {
715
725
  this.audioProxy = new RTPProxy_1.default({
716
726
  outgoingAddress: controllerAddress,
717
727
  outgoingPort: targetAudioPort,
718
- outgoingSSRC: crypto_1.default.randomBytes(4).readUInt32LE(0),
728
+ outgoingSSRC: crypto_1.default.randomBytes(4).readUInt32LE(0), // audioSSRC
719
729
  disabled: this.videoOnly,
720
730
  });
721
- promises.push(this.audioProxy.setup().then(function () {
722
- prepareRequest.audio.proxy_rtp = _this.audioProxy.incomingRTPPort();
723
- prepareRequest.audio.proxy_rtcp = _this.audioProxy.incomingRTCPPort();
731
+ promises.push(this.audioProxy.setup().then(() => {
732
+ prepareRequest.audio.proxy_rtp = this.audioProxy.incomingRTPPort();
733
+ prepareRequest.audio.proxy_rtcp = this.audioProxy.incomingRTCPPort();
724
734
  }));
725
735
  }
726
736
  }
727
- Promise.all(promises).then(function () {
728
- _this.delegate.prepareStream(prepareRequest, (0, once_1.once)(function (error, response) {
737
+ Promise.all(promises).then(() => {
738
+ this.delegate.prepareStream(prepareRequest, (0, once_1.once)((error, response) => {
729
739
  if (error || !response) {
730
- debug("PrepareStream request encountered an error: ".concat(error ? error.message : undefined));
731
- _this.setupEndpointsResponse = tlv.encode(1 /* SetupEndpointsResponseTypes.SESSION_ID */, uuid.write(sessionIdentifier), 2 /* SetupEndpointsResponseTypes.STATUS */, 2 /* SetupEndpointsStatus.ERROR */).toString("base64");
732
- _this.handleSessionClosed();
740
+ debug(`PrepareStream request encountered an error: ${error ? error.message : undefined}`);
741
+ this.setupEndpointsResponse = tlv.encode(1 /* SetupEndpointsResponseTypes.SESSION_ID */, uuid.write(sessionIdentifier), 2 /* SetupEndpointsResponseTypes.STATUS */, 2 /* SetupEndpointsStatus.ERROR */).toString("base64");
742
+ this.handleSessionClosed();
733
743
  callback(error);
734
744
  }
735
745
  else {
736
- _this.generateSetupEndpointResponse(connection, sessionIdentifier, prepareRequest, response, callback);
746
+ this.generateSetupEndpointResponse(connection, sessionIdentifier, prepareRequest, response, callback);
737
747
  }
738
748
  }));
739
749
  });
740
- };
741
- RTPStreamManagement.prototype.generateSetupEndpointResponse = function (connection, identifier, request, response, callback) {
742
- var address;
743
- var addressVersion = request.addressVersion;
744
- var videoPort;
745
- var audioPort;
746
- var videoCryptoSuite;
747
- var videoSRTPKey;
748
- var videoSRTPSalt;
749
- var audioCryptoSuite;
750
- var audioSRTPKey;
751
- var audioSRTPSalt;
752
- var videoSSRC;
753
- var audioSSRC;
750
+ }
751
+ generateSetupEndpointResponse(connection, identifier, request, response, callback) {
752
+ let address;
753
+ let addressVersion = request.addressVersion;
754
+ let videoPort;
755
+ let audioPort;
756
+ let videoCryptoSuite;
757
+ let videoSRTPKey;
758
+ let videoSRTPSalt;
759
+ let audioCryptoSuite;
760
+ let audioSRTPKey;
761
+ let audioSRTPSalt;
762
+ let videoSSRC;
763
+ let audioSSRC;
754
764
  if (!this.videoOnly && !response.audio) {
755
765
  throw new Error("Audio was enabled but not supplied in PrepareStreamResponse!");
756
766
  }
757
767
  // Provide default values if audio was not supplied
758
- var audio = response.audio || {
768
+ const audio = response.audio || {
759
769
  port: request.audio.port,
760
770
  ssrc: controller_1.CameraController.generateSynchronisationSource(),
761
771
  srtp_key: request.audio.srtp_key,
762
772
  srtp_salt: request.audio.srtp_salt,
763
773
  };
764
774
  if (!this.requireProxy) {
765
- var videoInfo = response.video;
766
- var audioInfo = audio;
775
+ const videoInfo = response.video;
776
+ const audioInfo = audio;
767
777
  if (response.addressOverride) {
768
778
  addressVersion = net_1.default.isIPv4(response.addressOverride) ? "ipv4" : "ipv6";
769
779
  address = response.addressOverride;
@@ -772,7 +782,7 @@ var RTPStreamManagement = /** @class */ (function () {
772
782
  address = connection.getLocalAddress(addressVersion);
773
783
  }
774
784
  if (request.addressVersion !== addressVersion) {
775
- throw new Error("Incoming and outgoing ip address versions must match! Expected ".concat(request.addressVersion, " but got ").concat(addressVersion));
785
+ throw new Error(`Incoming and outgoing ip address versions must match! Expected ${request.addressVersion} but got ${addressVersion}`);
776
786
  }
777
787
  videoPort = videoInfo.port;
778
788
  audioPort = audioInfo.port;
@@ -794,7 +804,7 @@ var RTPStreamManagement = /** @class */ (function () {
794
804
  audioSSRC = audioInfo.ssrc;
795
805
  }
796
806
  else {
797
- var videoInfo = response.video;
807
+ const videoInfo = response.video;
798
808
  address = connection.getLocalAddress(request.addressVersion);
799
809
  videoCryptoSuite = 2 /* SRTPCryptoSuites.NONE */;
800
810
  videoSRTPKey = Buffer.alloc(0);
@@ -809,7 +819,7 @@ var RTPStreamManagement = /** @class */ (function () {
809
819
  videoPort = this.videoProxy.outgoingLocalPort();
810
820
  videoSSRC = this.videoProxy.outgoingSSRC;
811
821
  if (!this.disableAudioProxy) {
812
- var audioInfo = response.audio;
822
+ const audioInfo = response.audio;
813
823
  this.audioProxy.setIncomingPayloadType(audioInfo.proxy_pt);
814
824
  this.audioProxy.setServerAddress(audioInfo.proxy_server_address);
815
825
  this.audioProxy.setServerRTPPort(audioInfo.proxy_server_rtp);
@@ -818,66 +828,66 @@ var RTPStreamManagement = /** @class */ (function () {
818
828
  audioSSRC = this.audioProxy.outgoingSSRC;
819
829
  }
820
830
  else {
821
- var audioInfo = response.audio;
831
+ const audioInfo = response.audio;
822
832
  audioPort = audioInfo.port;
823
833
  audioSSRC = audioInfo.ssrc;
824
834
  }
825
835
  }
826
836
  this.ipVersion = addressVersion; // we need to save this in order to calculate some default mtu values later
827
- var accessoryAddress = tlv.encode(1 /* AddressTypes.ADDRESS_VERSION */, addressVersion === "ipv4" ? 0 /* IPAddressVersion.IPV4 */ : 1 /* IPAddressVersion.IPV6 */, 2 /* AddressTypes.ADDRESS */, address, 3 /* AddressTypes.VIDEO_RTP_PORT */, tlv.writeUInt16(videoPort), 4 /* AddressTypes.AUDIO_RTP_PORT */, tlv.writeUInt16(audioPort));
828
- var videoSRTPParameters = tlv.encode(1 /* SRTPParametersTypes.SRTP_CRYPTO_SUITE */, videoCryptoSuite, 2 /* SRTPParametersTypes.MASTER_KEY */, videoSRTPKey, 3 /* SRTPParametersTypes.MASTER_SALT */, videoSRTPSalt);
829
- var audioSRTPParameters = tlv.encode(1 /* SRTPParametersTypes.SRTP_CRYPTO_SUITE */, audioCryptoSuite, 2 /* SRTPParametersTypes.MASTER_KEY */, audioSRTPKey, 3 /* SRTPParametersTypes.MASTER_SALT */, audioSRTPSalt);
837
+ const accessoryAddress = tlv.encode(1 /* AddressTypes.ADDRESS_VERSION */, addressVersion === "ipv4" ? 0 /* IPAddressVersion.IPV4 */ : 1 /* IPAddressVersion.IPV6 */, 2 /* AddressTypes.ADDRESS */, address, 3 /* AddressTypes.VIDEO_RTP_PORT */, tlv.writeUInt16(videoPort), 4 /* AddressTypes.AUDIO_RTP_PORT */, tlv.writeUInt16(audioPort));
838
+ const videoSRTPParameters = tlv.encode(1 /* SRTPParametersTypes.SRTP_CRYPTO_SUITE */, videoCryptoSuite, 2 /* SRTPParametersTypes.MASTER_KEY */, videoSRTPKey, 3 /* SRTPParametersTypes.MASTER_SALT */, videoSRTPSalt);
839
+ const audioSRTPParameters = tlv.encode(1 /* SRTPParametersTypes.SRTP_CRYPTO_SUITE */, audioCryptoSuite, 2 /* SRTPParametersTypes.MASTER_KEY */, audioSRTPKey, 3 /* SRTPParametersTypes.MASTER_SALT */, audioSRTPSalt);
830
840
  this.setupEndpointsResponse = tlv.encode(1 /* SetupEndpointsResponseTypes.SESSION_ID */, uuid.write(identifier), 2 /* SetupEndpointsResponseTypes.STATUS */, 0 /* SetupEndpointsStatus.SUCCESS */, 3 /* SetupEndpointsResponseTypes.ACCESSORY_ADDRESS */, accessoryAddress, 4 /* SetupEndpointsResponseTypes.VIDEO_SRTP_PARAMETERS */, videoSRTPParameters, 5 /* SetupEndpointsResponseTypes.AUDIO_SRTP_PARAMETERS */, audioSRTPParameters, 6 /* SetupEndpointsResponseTypes.VIDEO_SSRC */, tlv.writeUInt32(videoSSRC), 7 /* SetupEndpointsResponseTypes.AUDIO_SSRC */, tlv.writeUInt32(audioSSRC)).toString("base64");
831
841
  callback();
832
- };
833
- RTPStreamManagement.prototype._updateStreamStatus = function (status) {
842
+ }
843
+ _updateStreamStatus(status) {
834
844
  this.streamStatus = status;
835
845
  this.service.updateCharacteristic(Characteristic_1.Characteristic.StreamingStatus, tlv.encode(1 /* StreamingStatusTypes.STATUS */, this.streamStatus).toString("base64"));
836
- };
837
- RTPStreamManagement._supportedRTPConfiguration = function (supportedCryptoSuites) {
846
+ }
847
+ static _supportedRTPConfiguration(supportedCryptoSuites) {
838
848
  if (supportedCryptoSuites.length === 1 && supportedCryptoSuites[0] === 2 /* SRTPCryptoSuites.NONE */) {
839
849
  debug("Client claims it doesn't support SRTP. The stream may stops working with future iOS releases.");
840
850
  }
841
851
  return tlv.encode(2 /* SupportedRTPConfigurationTypes.SRTP_CRYPTO_SUITE */, supportedCryptoSuites).toString("base64");
842
- };
843
- RTPStreamManagement._supportedVideoStreamConfiguration = function (videoOptions) {
852
+ }
853
+ static _supportedVideoStreamConfiguration(videoOptions) {
844
854
  if (!videoOptions.codec) {
845
855
  throw new Error("Video codec cannot be undefined");
846
856
  }
847
857
  if (!videoOptions.resolutions) {
848
858
  throw new Error("Video resolutions cannot be undefined");
849
859
  }
850
- var codecParameters = tlv.encode(1 /* VideoCodecParametersTypes.PROFILE_ID */, videoOptions.codec.profiles, 2 /* VideoCodecParametersTypes.LEVEL */, videoOptions.codec.levels, 3 /* VideoCodecParametersTypes.PACKETIZATION_MODE */, 0 /* VideoCodecPacketizationMode.NON_INTERLEAVED */);
860
+ let codecParameters = tlv.encode(1 /* VideoCodecParametersTypes.PROFILE_ID */, videoOptions.codec.profiles, 2 /* VideoCodecParametersTypes.LEVEL */, videoOptions.codec.levels, 3 /* VideoCodecParametersTypes.PACKETIZATION_MODE */, 0 /* VideoCodecPacketizationMode.NON_INTERLEAVED */);
851
861
  if (videoOptions.cvoId != null) {
852
862
  codecParameters = Buffer.concat([
853
863
  codecParameters,
854
864
  tlv.encode(4 /* VideoCodecParametersTypes.CVO_ENABLED */, 1 /* VideoCodecCVO.SUPPORTED */, 5 /* VideoCodecParametersTypes.CVO_ID */, videoOptions.cvoId),
855
865
  ]);
856
866
  }
857
- var videoStreamConfiguration = tlv.encode(1 /* VideoCodecConfigurationTypes.CODEC_TYPE */, 0 /* VideoCodecType.H264 */, 2 /* VideoCodecConfigurationTypes.CODEC_PARAMETERS */, codecParameters, 3 /* VideoCodecConfigurationTypes.ATTRIBUTES */, videoOptions.resolutions.map(function (resolution) {
867
+ const videoStreamConfiguration = tlv.encode(1 /* VideoCodecConfigurationTypes.CODEC_TYPE */, 0 /* VideoCodecType.H264 */, 2 /* VideoCodecConfigurationTypes.CODEC_PARAMETERS */, codecParameters, 3 /* VideoCodecConfigurationTypes.ATTRIBUTES */, videoOptions.resolutions.map(resolution => {
858
868
  if (resolution.length !== 3) {
859
869
  throw new Error("Unexpected video resolution");
860
870
  }
861
- var width = Buffer.alloc(2);
862
- var height = Buffer.alloc(2);
863
- var frameRate = Buffer.alloc(1);
871
+ const width = Buffer.alloc(2);
872
+ const height = Buffer.alloc(2);
873
+ const frameRate = Buffer.alloc(1);
864
874
  width.writeUInt16LE(resolution[0], 0);
865
875
  height.writeUInt16LE(resolution[1], 0);
866
876
  frameRate.writeUInt8(resolution[2], 0);
867
877
  return tlv.encode(1 /* VideoAttributesTypes.IMAGE_WIDTH */, width, 2 /* VideoAttributesTypes.IMAGE_HEIGHT */, height, 3 /* VideoAttributesTypes.FRAME_RATE */, frameRate);
868
878
  }));
869
879
  return tlv.encode(1 /* SupportedVideoStreamConfigurationTypes.VIDEO_CODEC_CONFIGURATION */, videoStreamConfiguration).toString("base64");
870
- };
871
- RTPStreamManagement.prototype.checkForLegacyAudioCodecRepresentation = function (codecs) {
872
- var codecMap = {};
873
- codecs.slice().forEach(function (codec) {
874
- var previous = codecMap[codec.type];
880
+ }
881
+ checkForLegacyAudioCodecRepresentation(codecs) {
882
+ const codecMap = {};
883
+ codecs.slice().forEach(codec => {
884
+ const previous = codecMap[codec.type];
875
885
  if (previous) {
876
886
  if (typeof previous.samplerate === "number") {
877
887
  previous.samplerate = [previous.samplerate];
878
888
  }
879
889
  previous.samplerate = previous.samplerate.concat(codec.samplerate);
880
- var index = codecs.indexOf(codec);
890
+ const index = codecs.indexOf(codec);
881
891
  if (index >= 0) {
882
892
  codecs.splice(index, 1);
883
893
  }
@@ -886,23 +896,23 @@ var RTPStreamManagement = /** @class */ (function () {
886
896
  codecMap[codec.type] = codec;
887
897
  }
888
898
  });
889
- };
890
- RTPStreamManagement.prototype._supportedAudioStreamConfiguration = function (audioOptions) {
899
+ }
900
+ _supportedAudioStreamConfiguration(audioOptions) {
891
901
  // Only AAC-ELD and OPUS are accepted by iOS currently, and we need to give it something it will accept
892
902
  // for it to start the video stream.
893
- var comfortNoise = audioOptions && !!audioOptions.comfort_noise;
894
- var supportedCodecs = (audioOptions && audioOptions.codecs) || [];
903
+ const comfortNoise = audioOptions && !!audioOptions.comfort_noise;
904
+ const supportedCodecs = (audioOptions && audioOptions.codecs) || [];
895
905
  this.checkForLegacyAudioCodecRepresentation(supportedCodecs);
896
906
  if (supportedCodecs.length === 0) { // Fake a Codec if we haven't got anything
897
907
  debug("Client doesn't support any audio codec that HomeKit supports.");
898
908
  this.videoOnly = true;
899
909
  supportedCodecs.push({
900
- type: "OPUS" /* AudioStreamingCodecType.OPUS */,
910
+ type: "OPUS" /* AudioStreamingCodecType.OPUS */, // Opus @16K required by Apple Watch AFAIK
901
911
  samplerate: [16 /* AudioStreamingSamplerate.KHZ_16 */, 24 /* AudioStreamingSamplerate.KHZ_24 */], // 16 and 24 must be supported
902
912
  });
903
913
  }
904
- var codecConfigurations = supportedCodecs.map(function (codec) {
905
- var type;
914
+ const codecConfigurations = supportedCodecs.map(codec => {
915
+ let type;
906
916
  switch (codec.type) {
907
917
  case "OPUS" /* AudioStreamingCodecType.OPUS */:
908
918
  type = 3 /* AudioCodecTypes.OPUS */;
@@ -928,8 +938,8 @@ var RTPStreamManagement = /** @class */ (function () {
928
938
  default:
929
939
  throw new Error("Unsupported codec: " + codec.type);
930
940
  }
931
- var providedSamplerates = (typeof codec.samplerate === "number" ? [codec.samplerate] : codec.samplerate).map(function (rate) {
932
- var samplerate;
941
+ const providedSamplerates = (typeof codec.samplerate === "number" ? [codec.samplerate] : codec.samplerate).map(rate => {
942
+ let samplerate;
933
943
  switch (rate) {
934
944
  case 8 /* AudioStreamingSamplerate.KHZ_8 */:
935
945
  samplerate = 0 /* AudioSamplerate.KHZ_8 */;
@@ -945,28 +955,28 @@ var RTPStreamManagement = /** @class */ (function () {
945
955
  samplerate = -1;
946
956
  }
947
957
  return samplerate;
948
- }).filter(function (rate) { return rate !== -1; });
958
+ }).filter(rate => rate !== -1);
949
959
  if (providedSamplerates.length === 0) {
950
960
  throw new Error("Audio samplerate cannot be empty!");
951
961
  }
952
- var audioParameters = tlv.encode(1 /* AudioCodecParametersTypes.CHANNEL */, Math.max(1, codec.audioChannels || 1), 2 /* AudioCodecParametersTypes.BIT_RATE */, codec.bitrate || 0 /* AudioBitrate.VARIABLE */, 3 /* AudioCodecParametersTypes.SAMPLE_RATE */, providedSamplerates);
962
+ const audioParameters = tlv.encode(1 /* AudioCodecParametersTypes.CHANNEL */, Math.max(1, codec.audioChannels || 1), 2 /* AudioCodecParametersTypes.BIT_RATE */, codec.bitrate || 0 /* AudioBitrate.VARIABLE */, 3 /* AudioCodecParametersTypes.SAMPLE_RATE */, providedSamplerates);
953
963
  return tlv.encode(1 /* AudioCodecConfigurationTypes.CODEC_TYPE */, type, 2 /* AudioCodecConfigurationTypes.CODEC_PARAMETERS */, audioParameters);
954
964
  });
955
965
  return tlv.encode(1 /* SupportedAudioStreamConfigurationTypes.AUDIO_CODEC_CONFIGURATION */, codecConfigurations, 2 /* SupportedAudioStreamConfigurationTypes.COMFORT_NOISE_SUPPORT */, comfortNoise ? 1 : 0).toString("base64");
956
- };
957
- RTPStreamManagement.prototype.resetSetupEndpointsResponse = function () {
966
+ }
967
+ resetSetupEndpointsResponse() {
958
968
  this.setupEndpointsResponse = tlv.encode(2 /* SetupEndpointsResponseTypes.STATUS */, 2 /* SetupEndpointsStatus.ERROR */).toString("base64");
959
969
  this.service.updateCharacteristic(Characteristic_1.Characteristic.SetupEndpoints, this.setupEndpointsResponse);
960
- };
961
- RTPStreamManagement.prototype.resetSelectedStreamConfiguration = function () {
970
+ }
971
+ resetSelectedStreamConfiguration() {
962
972
  this.selectedConfiguration = tlv.encode(1 /* SelectedRTPStreamConfigurationTypes.SESSION_CONTROL */, tlv.encode(2 /* SessionControlTypes.COMMAND */, SessionControlCommand.SUSPEND_SESSION)).toString("base64");
963
973
  this.service.updateCharacteristic(Characteristic_1.Characteristic.SelectedRTPStreamConfiguration, this.selectedConfiguration);
964
- };
974
+ }
965
975
  /**
966
976
  * @private
967
977
  */
968
- RTPStreamManagement.prototype.serialize = function () {
969
- var characteristicValue = this.service.getCharacteristic(Characteristic_1.Characteristic.Active).value;
978
+ serialize() {
979
+ const characteristicValue = this.service.getCharacteristic(Characteristic_1.Characteristic.Active).value;
970
980
  if (characteristicValue === true) {
971
981
  return undefined;
972
982
  }
@@ -974,50 +984,20 @@ var RTPStreamManagement = /** @class */ (function () {
974
984
  id: this.id,
975
985
  active: !!characteristicValue,
976
986
  };
977
- };
987
+ }
978
988
  /**
979
989
  * @private
980
990
  */
981
- RTPStreamManagement.prototype.deserialize = function (serialized) {
982
- (0, assert_1.default)(serialized.id === this.id, "Tried to initialize RTPStreamManagement ".concat(this.id, " with data from management with id ").concat(serialized.id, "!"));
991
+ deserialize(serialized) {
992
+ (0, assert_1.default)(serialized.id === this.id, `Tried to initialize RTPStreamManagement ${this.id} with data from management with id ${serialized.id}!`);
983
993
  this.service.updateCharacteristic(Characteristic_1.Characteristic.Active, serialized.active);
984
- };
994
+ }
985
995
  /**
986
996
  * @private
987
997
  */
988
- RTPStreamManagement.prototype.setupStateChangeDelegate = function (delegate) {
998
+ setupStateChangeDelegate(delegate) {
989
999
  this.stateChangeDelegate = delegate;
990
- };
991
- /**
992
- * @deprecated Please use the SRTPCryptoSuites const enum above.
993
- */
994
- // @ts-expect-error: forceConsistentCasingInFileNames compiler option
995
- RTPStreamManagement.SRTPCryptoSuites = SRTPCryptoSuites;
996
- /**
997
- * @deprecated Please use the H264Profile const enum above.
998
- */
999
- // @ts-expect-error: forceConsistentCasingInFileNames compiler option
1000
- RTPStreamManagement.VideoCodecParamProfileIDTypes = H264Profile;
1001
- /**
1002
- * @deprecated won't be updated anymore. Please use the H264Level const enum above.
1003
- */
1004
- RTPStreamManagement.VideoCodecParamLevelTypes = Object.freeze({ TYPE3_1: 0, TYPE3_2: 1, TYPE4_0: 2 });
1005
- return RTPStreamManagement;
1006
- }());
1007
- exports.RTPStreamManagement = RTPStreamManagement;
1008
- /**
1009
- * @group Camera
1010
- * @deprecated - only there for backwards compatibility, please use {@link RTPStreamManagement} directly
1011
- */
1012
- var StreamController = /** @class */ (function (_super) {
1013
- tslib_1.__extends(StreamController, _super);
1014
- // noinspection JSDeprecatedSymbols
1015
- function StreamController(id, options, delegate, service) {
1016
- var _this = _super.call(this, id, options, new Camera_1.LegacyCameraSourceAdapter(delegate), service) || this;
1017
- _this.options = options;
1018
- return _this;
1019
1000
  }
1020
- return StreamController;
1021
- }(RTPStreamManagement));
1022
- exports.StreamController = StreamController;
1001
+ }
1002
+ exports.RTPStreamManagement = RTPStreamManagement;
1023
1003
  //# sourceMappingURL=RTPStreamManagement.js.map