@homebridge/hap-nodejs 2.3.1-beta.1 → 2.3.1-beta.2

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 (252) hide show
  1. package/README.md +13 -4
  2. package/dist/accessories/types.d.ts +0 -1
  3. package/dist/hap.d.ts +1 -1
  4. package/dist/hap.js +6 -4
  5. package/dist/hap.js.map +1 -1
  6. package/dist/index.d.ts +4 -1
  7. package/dist/index.js +4 -0
  8. package/dist/index.js.map +1 -1
  9. package/dist/internal-types.d.ts +6 -7
  10. package/dist/internal-types.js +1 -5
  11. package/dist/internal-types.js.map +1 -1
  12. package/dist/lib/Accessory.d.ts +49 -25
  13. package/dist/lib/Accessory.js +275 -171
  14. package/dist/lib/Accessory.js.map +1 -1
  15. package/dist/lib/Advertiser.d.ts +37 -18
  16. package/dist/lib/Advertiser.js +143 -62
  17. package/dist/lib/Advertiser.js.map +1 -1
  18. package/dist/lib/Bridge.d.ts +1 -2
  19. package/dist/lib/Bridge.js +1 -1
  20. package/dist/lib/Characteristic.d.ts +19 -20
  21. package/dist/lib/Characteristic.js +187 -153
  22. package/dist/lib/Characteristic.js.map +1 -1
  23. package/dist/lib/HAPServer.d.ts +19 -13
  24. package/dist/lib/HAPServer.js +266 -220
  25. package/dist/lib/HAPServer.js.map +1 -1
  26. package/dist/lib/Service.d.ts +11 -11
  27. package/dist/lib/Service.js +54 -37
  28. package/dist/lib/Service.js.map +1 -1
  29. package/dist/lib/camera/RTPProxy.d.ts +5 -5
  30. package/dist/lib/camera/RTPProxy.js +48 -23
  31. package/dist/lib/camera/RTPProxy.js.map +1 -1
  32. package/dist/lib/camera/RTPStreamManagement.d.ts +18 -13
  33. package/dist/lib/camera/RTPStreamManagement.js +247 -216
  34. package/dist/lib/camera/RTPStreamManagement.js.map +1 -1
  35. package/dist/lib/camera/RecordingManagement.d.ts +13 -13
  36. package/dist/lib/camera/RecordingManagement.js +115 -110
  37. package/dist/lib/camera/RecordingManagement.js.map +1 -1
  38. package/dist/lib/camera/index.d.ts +0 -1
  39. package/dist/lib/controller/AdaptiveLightingController.d.ts +41 -36
  40. package/dist/lib/controller/AdaptiveLightingController.js +126 -113
  41. package/dist/lib/controller/AdaptiveLightingController.js.map +1 -1
  42. package/dist/lib/controller/CameraController.d.ts +17 -17
  43. package/dist/lib/controller/CameraController.js +30 -26
  44. package/dist/lib/controller/CameraController.js.map +1 -1
  45. package/dist/lib/controller/Controller.d.ts +15 -12
  46. package/dist/lib/controller/Controller.js +0 -1
  47. package/dist/lib/controller/Controller.js.map +1 -1
  48. package/dist/lib/controller/DoorbellController.d.ts +6 -6
  49. package/dist/lib/controller/DoorbellController.js +10 -3
  50. package/dist/lib/controller/DoorbellController.js.map +1 -1
  51. package/dist/lib/controller/RemoteController.d.ts +46 -27
  52. package/dist/lib/controller/RemoteController.js +268 -178
  53. package/dist/lib/controller/RemoteController.js.map +1 -1
  54. package/dist/lib/controller/index.d.ts +0 -1
  55. package/dist/lib/datastream/DataStreamManagement.d.ts +6 -6
  56. package/dist/lib/datastream/DataStreamManagement.js +30 -26
  57. package/dist/lib/datastream/DataStreamManagement.js.map +1 -1
  58. package/dist/lib/datastream/DataStreamParser.d.ts +25 -8
  59. package/dist/lib/datastream/DataStreamParser.js +124 -105
  60. package/dist/lib/datastream/DataStreamParser.js.map +1 -1
  61. package/dist/lib/datastream/DataStreamServer.d.ts +47 -23
  62. package/dist/lib/datastream/DataStreamServer.js +285 -143
  63. package/dist/lib/datastream/DataStreamServer.js.map +1 -1
  64. package/dist/lib/datastream/index.d.ts +0 -1
  65. package/dist/lib/definitions/CharacteristicDefinitions.d.ts +0 -1
  66. package/dist/lib/definitions/CharacteristicDefinitions.js +578 -578
  67. package/dist/lib/definitions/CharacteristicDefinitions.js.map +1 -1
  68. package/dist/lib/definitions/ServiceDefinitions.d.ts +0 -1
  69. package/dist/lib/definitions/index.d.ts +0 -1
  70. package/dist/lib/gen/HomeKit.d.ts +0 -1
  71. package/dist/lib/model/AccessoryInfo.d.ts +5 -6
  72. package/dist/lib/model/AccessoryInfo.js +23 -19
  73. package/dist/lib/model/AccessoryInfo.js.map +1 -1
  74. package/dist/lib/model/ControllerStorage.d.ts +11 -5
  75. package/dist/lib/model/ControllerStorage.js +34 -8
  76. package/dist/lib/model/ControllerStorage.js.map +1 -1
  77. package/dist/lib/model/HAPFileStorage.d.ts +20 -2
  78. package/dist/lib/model/HAPFileStorage.js +59 -10
  79. package/dist/lib/model/HAPFileStorage.js.map +1 -1
  80. package/dist/lib/model/HAPStorage.d.ts +0 -1
  81. package/dist/lib/model/HAPStorage.js +6 -3
  82. package/dist/lib/model/HAPStorage.js.map +1 -1
  83. package/dist/lib/model/IdentifierCache.d.ts +2 -3
  84. package/dist/lib/model/IdentifierCache.js +26 -13
  85. package/dist/lib/model/IdentifierCache.js.map +1 -1
  86. package/dist/lib/tv/AccessControlManagement.d.ts +6 -7
  87. package/dist/lib/tv/AccessControlManagement.js +13 -19
  88. package/dist/lib/tv/AccessControlManagement.js.map +1 -1
  89. package/dist/lib/util/checkName.d.ts +1 -2
  90. package/dist/lib/util/checkName.js.map +1 -1
  91. package/dist/lib/util/clone.d.ts +0 -1
  92. package/dist/lib/util/clone.js.map +1 -1
  93. package/dist/lib/util/color-utils.d.ts +1 -2
  94. package/dist/lib/util/color-utils.js +1 -1
  95. package/dist/lib/util/errors.d.ts +4 -0
  96. package/dist/lib/util/errors.js +15 -0
  97. package/dist/lib/util/errors.js.map +1 -0
  98. package/dist/lib/util/eventedhttp.d.ts +63 -19
  99. package/dist/lib/util/eventedhttp.js +170 -48
  100. package/dist/lib/util/eventedhttp.js.map +1 -1
  101. package/dist/lib/util/hapCrypto.d.ts +1 -2
  102. package/dist/lib/util/hapCrypto.js +6 -7
  103. package/dist/lib/util/hapCrypto.js.map +1 -1
  104. package/dist/lib/util/hapStatusError.d.ts +0 -1
  105. package/dist/lib/util/hapStatusError.js +1 -1
  106. package/dist/lib/util/hapStatusError.js.map +1 -1
  107. package/dist/lib/util/net-utils.d.ts +1 -2
  108. package/dist/lib/util/net-utils.js +6 -7
  109. package/dist/lib/util/net-utils.js.map +1 -1
  110. package/dist/lib/util/once.d.ts +0 -1
  111. package/dist/lib/util/promise-utils.d.ts +1 -2
  112. package/dist/lib/util/promise-utils.js +2 -1
  113. package/dist/lib/util/promise-utils.js.map +1 -1
  114. package/dist/lib/util/request-util.d.ts +4 -4
  115. package/dist/lib/util/request-util.js +29 -28
  116. package/dist/lib/util/request-util.js.map +1 -1
  117. package/dist/lib/util/time.d.ts +1 -2
  118. package/dist/lib/util/time.js.map +1 -1
  119. package/dist/lib/util/tlv.d.ts +4 -4
  120. package/dist/lib/util/tlv.js +16 -5
  121. package/dist/lib/util/tlv.js.map +1 -1
  122. package/dist/lib/util/uuid.d.ts +5 -2
  123. package/dist/lib/util/uuid.js +6 -0
  124. package/dist/lib/util/uuid.js.map +1 -1
  125. package/dist/types.d.ts +20 -17
  126. package/dist/types.js +0 -1
  127. package/dist/types.js.map +1 -1
  128. package/package.json +8 -14
  129. package/dist/accessories/AirConditioner_accessory.d.ts +0 -2
  130. package/dist/accessories/AirConditioner_accessory.d.ts.map +0 -1
  131. package/dist/accessories/AirConditioner_accessory.js +0 -126
  132. package/dist/accessories/AirConditioner_accessory.js.map +0 -1
  133. package/dist/accessories/AppleTVRemote_accessory.d.ts +0 -2
  134. package/dist/accessories/AppleTVRemote_accessory.d.ts.map +0 -1
  135. package/dist/accessories/AppleTVRemote_accessory.js +0 -146
  136. package/dist/accessories/AppleTVRemote_accessory.js.map +0 -1
  137. package/dist/accessories/Camera_accessory.d.ts +0 -2
  138. package/dist/accessories/Camera_accessory.d.ts.map +0 -1
  139. package/dist/accessories/Camera_accessory.js +0 -562
  140. package/dist/accessories/Camera_accessory.js.map +0 -1
  141. package/dist/accessories/Fan_accessory.d.ts +0 -2
  142. package/dist/accessories/Fan_accessory.d.ts.map +0 -1
  143. package/dist/accessories/Fan_accessory.js +0 -71
  144. package/dist/accessories/Fan_accessory.js.map +0 -1
  145. package/dist/accessories/GarageDoorOpener_accessory.d.ts +0 -2
  146. package/dist/accessories/GarageDoorOpener_accessory.d.ts.map +0 -1
  147. package/dist/accessories/GarageDoorOpener_accessory.js +0 -76
  148. package/dist/accessories/GarageDoorOpener_accessory.js.map +0 -1
  149. package/dist/accessories/Light-AdaptiveLighting_accessory.d.ts +0 -2
  150. package/dist/accessories/Light-AdaptiveLighting_accessory.d.ts.map +0 -1
  151. package/dist/accessories/Light-AdaptiveLighting_accessory.js +0 -103
  152. package/dist/accessories/Light-AdaptiveLighting_accessory.js.map +0 -1
  153. package/dist/accessories/Light_accessory.d.ts +0 -2
  154. package/dist/accessories/Light_accessory.d.ts.map +0 -1
  155. package/dist/accessories/Light_accessory.js +0 -143
  156. package/dist/accessories/Light_accessory.js.map +0 -1
  157. package/dist/accessories/Lock_accessory.d.ts +0 -2
  158. package/dist/accessories/Lock_accessory.d.ts.map +0 -1
  159. package/dist/accessories/Lock_accessory.js +0 -74
  160. package/dist/accessories/Lock_accessory.js.map +0 -1
  161. package/dist/accessories/MotionSensor_accessory.d.ts +0 -2
  162. package/dist/accessories/MotionSensor_accessory.d.ts.map +0 -1
  163. package/dist/accessories/MotionSensor_accessory.js +0 -43
  164. package/dist/accessories/MotionSensor_accessory.js.map +0 -1
  165. package/dist/accessories/Outlet_accessory.d.ts +0 -2
  166. package/dist/accessories/Outlet_accessory.d.ts.map +0 -1
  167. package/dist/accessories/Outlet_accessory.js +0 -77
  168. package/dist/accessories/Outlet_accessory.js.map +0 -1
  169. package/dist/accessories/SmartSpeaker_accessory.d.ts +0 -2
  170. package/dist/accessories/SmartSpeaker_accessory.d.ts.map +0 -1
  171. package/dist/accessories/SmartSpeaker_accessory.js +0 -42
  172. package/dist/accessories/SmartSpeaker_accessory.js.map +0 -1
  173. package/dist/accessories/Sprinkler_accessory.d.ts +0 -2
  174. package/dist/accessories/Sprinkler_accessory.d.ts.map +0 -1
  175. package/dist/accessories/Sprinkler_accessory.js +0 -126
  176. package/dist/accessories/Sprinkler_accessory.js.map +0 -1
  177. package/dist/accessories/TV_accessory.d.ts +0 -2
  178. package/dist/accessories/TV_accessory.d.ts.map +0 -1
  179. package/dist/accessories/TV_accessory.js +0 -99
  180. package/dist/accessories/TV_accessory.js.map +0 -1
  181. package/dist/accessories/TemperatureSensor_accessory.d.ts +0 -2
  182. package/dist/accessories/TemperatureSensor_accessory.d.ts.map +0 -1
  183. package/dist/accessories/TemperatureSensor_accessory.js +0 -42
  184. package/dist/accessories/TemperatureSensor_accessory.js.map +0 -1
  185. package/dist/accessories/Wi-FiRouter_accessory.d.ts +0 -3
  186. package/dist/accessories/Wi-FiRouter_accessory.d.ts.map +0 -1
  187. package/dist/accessories/Wi-FiRouter_accessory.js +0 -14
  188. package/dist/accessories/Wi-FiRouter_accessory.js.map +0 -1
  189. package/dist/accessories/Wi-FiSatellite_accessory.d.ts +0 -3
  190. package/dist/accessories/Wi-FiSatellite_accessory.d.ts.map +0 -1
  191. package/dist/accessories/Wi-FiSatellite_accessory.js +0 -16
  192. package/dist/accessories/Wi-FiSatellite_accessory.js.map +0 -1
  193. package/dist/accessories/gstreamer-audioProducer.d.ts +0 -25
  194. package/dist/accessories/gstreamer-audioProducer.d.ts.map +0 -1
  195. package/dist/accessories/gstreamer-audioProducer.js +0 -145
  196. package/dist/accessories/gstreamer-audioProducer.js.map +0 -1
  197. package/dist/accessories/types.d.ts.map +0 -1
  198. package/dist/hap.d.ts.map +0 -1
  199. package/dist/index.d.ts.map +0 -1
  200. package/dist/internal-types.d.ts.map +0 -1
  201. package/dist/lib/Accessory.d.ts.map +0 -1
  202. package/dist/lib/Advertiser.d.ts.map +0 -1
  203. package/dist/lib/Bridge.d.ts.map +0 -1
  204. package/dist/lib/Characteristic.d.ts.map +0 -1
  205. package/dist/lib/HAPServer.d.ts.map +0 -1
  206. package/dist/lib/Service.d.ts.map +0 -1
  207. package/dist/lib/camera/RTPProxy.d.ts.map +0 -1
  208. package/dist/lib/camera/RTPStreamManagement.d.ts.map +0 -1
  209. package/dist/lib/camera/RecordingManagement.d.ts.map +0 -1
  210. package/dist/lib/camera/index.d.ts.map +0 -1
  211. package/dist/lib/controller/AdaptiveLightingController.d.ts.map +0 -1
  212. package/dist/lib/controller/CameraController.d.ts.map +0 -1
  213. package/dist/lib/controller/Controller.d.ts.map +0 -1
  214. package/dist/lib/controller/DoorbellController.d.ts.map +0 -1
  215. package/dist/lib/controller/RemoteController.d.ts.map +0 -1
  216. package/dist/lib/controller/index.d.ts.map +0 -1
  217. package/dist/lib/datastream/DataStreamManagement.d.ts.map +0 -1
  218. package/dist/lib/datastream/DataStreamParser.d.ts.map +0 -1
  219. package/dist/lib/datastream/DataStreamServer.d.ts.map +0 -1
  220. package/dist/lib/datastream/index.d.ts.map +0 -1
  221. package/dist/lib/definitions/CharacteristicDefinitions.d.ts.map +0 -1
  222. package/dist/lib/definitions/ServiceDefinitions.d.ts.map +0 -1
  223. package/dist/lib/definitions/generate-definitions.d.ts +0 -34
  224. package/dist/lib/definitions/generate-definitions.d.ts.map +0 -1
  225. package/dist/lib/definitions/generate-definitions.js +0 -624
  226. package/dist/lib/definitions/generate-definitions.js.map +0 -1
  227. package/dist/lib/definitions/generator-configuration.d.ts +0 -22
  228. package/dist/lib/definitions/generator-configuration.d.ts.map +0 -1
  229. package/dist/lib/definitions/generator-configuration.js +0 -674
  230. package/dist/lib/definitions/generator-configuration.js.map +0 -1
  231. package/dist/lib/definitions/index.d.ts.map +0 -1
  232. package/dist/lib/gen/HomeKit.d.ts.map +0 -1
  233. package/dist/lib/model/AccessoryInfo.d.ts.map +0 -1
  234. package/dist/lib/model/ControllerStorage.d.ts.map +0 -1
  235. package/dist/lib/model/HAPFileStorage.d.ts.map +0 -1
  236. package/dist/lib/model/HAPStorage.d.ts.map +0 -1
  237. package/dist/lib/model/IdentifierCache.d.ts.map +0 -1
  238. package/dist/lib/tv/AccessControlManagement.d.ts.map +0 -1
  239. package/dist/lib/util/checkName.d.ts.map +0 -1
  240. package/dist/lib/util/clone.d.ts.map +0 -1
  241. package/dist/lib/util/color-utils.d.ts.map +0 -1
  242. package/dist/lib/util/eventedhttp.d.ts.map +0 -1
  243. package/dist/lib/util/hapCrypto.d.ts.map +0 -1
  244. package/dist/lib/util/hapStatusError.d.ts.map +0 -1
  245. package/dist/lib/util/net-utils.d.ts.map +0 -1
  246. package/dist/lib/util/once.d.ts.map +0 -1
  247. package/dist/lib/util/promise-utils.d.ts.map +0 -1
  248. package/dist/lib/util/request-util.d.ts.map +0 -1
  249. package/dist/lib/util/time.d.ts.map +0 -1
  250. package/dist/lib/util/tlv.d.ts.map +0 -1
  251. package/dist/lib/util/uuid.d.ts.map +0 -1
  252. package/dist/types.d.ts.map +0 -1
@@ -3,10 +3,12 @@ import { Buffer } from 'node:buffer';
3
3
  import crypto from 'node:crypto';
4
4
  import net from 'node:net';
5
5
  import createDebug from 'debug';
6
- import { Characteristic } from '../Characteristic.js';
7
- import { CameraController } from '../controller/index.js';
6
+ import { Access, Characteristic, CharacteristicEventTypes } from '../Characteristic.js';
7
+ import { CameraController } from '../controller/CameraController.js';
8
8
  import { HAPStatus } from '../HAPServer.js';
9
9
  import { Service } from '../Service.js';
10
+ import { errorMessage } from '../util/errors.js';
11
+ import { HAPConnectionEvent } from '../util/eventedhttp.js';
10
12
  import { HapStatusError } from '../util/hapStatusError.js';
11
13
  import { once } from '../util/once.js';
12
14
  import * as tlv from '../util/tlv.js';
@@ -14,12 +16,10 @@ import * as uuid from '../util/uuid.js';
14
16
  import RTPProxy from './RTPProxy.js';
15
17
  const debug = createDebug('HAP-NodeJS:Camera:RTPStreamManagement');
16
18
  // ---------------------------------- TLV DEFINITIONS START ----------------------------------
17
- // eslint-disable-next-line no-restricted-syntax
18
19
  var StreamingStatusTypes;
19
20
  (function (StreamingStatusTypes) {
20
21
  StreamingStatusTypes[StreamingStatusTypes["STATUS"] = 1] = "STATUS";
21
22
  })(StreamingStatusTypes || (StreamingStatusTypes = {}));
22
- // eslint-disable-next-line no-restricted-syntax
23
23
  var StreamingStatus;
24
24
  (function (StreamingStatus) {
25
25
  StreamingStatus[StreamingStatus["AVAILABLE"] = 0] = "AVAILABLE";
@@ -27,19 +27,16 @@ var StreamingStatus;
27
27
  StreamingStatus[StreamingStatus["UNAVAILABLE"] = 2] = "UNAVAILABLE";
28
28
  })(StreamingStatus || (StreamingStatus = {}));
29
29
  // ----------
30
- // eslint-disable-next-line no-restricted-syntax
31
30
  var SupportedVideoStreamConfigurationTypes;
32
31
  (function (SupportedVideoStreamConfigurationTypes) {
33
32
  SupportedVideoStreamConfigurationTypes[SupportedVideoStreamConfigurationTypes["VIDEO_CODEC_CONFIGURATION"] = 1] = "VIDEO_CODEC_CONFIGURATION";
34
33
  })(SupportedVideoStreamConfigurationTypes || (SupportedVideoStreamConfigurationTypes = {}));
35
- // eslint-disable-next-line no-restricted-syntax
36
34
  var VideoCodecConfigurationTypes;
37
35
  (function (VideoCodecConfigurationTypes) {
38
36
  VideoCodecConfigurationTypes[VideoCodecConfigurationTypes["CODEC_TYPE"] = 1] = "CODEC_TYPE";
39
37
  VideoCodecConfigurationTypes[VideoCodecConfigurationTypes["CODEC_PARAMETERS"] = 2] = "CODEC_PARAMETERS";
40
38
  VideoCodecConfigurationTypes[VideoCodecConfigurationTypes["ATTRIBUTES"] = 3] = "ATTRIBUTES";
41
39
  })(VideoCodecConfigurationTypes || (VideoCodecConfigurationTypes = {}));
42
- // eslint-disable-next-line no-restricted-syntax
43
40
  var VideoCodecParametersTypes;
44
41
  (function (VideoCodecParametersTypes) {
45
42
  VideoCodecParametersTypes[VideoCodecParametersTypes["PROFILE_ID"] = 1] = "PROFILE_ID";
@@ -48,7 +45,6 @@ var VideoCodecParametersTypes;
48
45
  VideoCodecParametersTypes[VideoCodecParametersTypes["CVO_ENABLED"] = 4] = "CVO_ENABLED";
49
46
  VideoCodecParametersTypes[VideoCodecParametersTypes["CVO_ID"] = 5] = "CVO_ID";
50
47
  })(VideoCodecParametersTypes || (VideoCodecParametersTypes = {}));
51
- // eslint-disable-next-line no-restricted-syntax
52
48
  var VideoAttributesTypes;
53
49
  (function (VideoAttributesTypes) {
54
50
  VideoAttributesTypes[VideoAttributesTypes["IMAGE_WIDTH"] = 1] = "IMAGE_WIDTH";
@@ -58,7 +54,6 @@ var VideoAttributesTypes;
58
54
  /**
59
55
  * @group Camera
60
56
  */
61
- // eslint-disable-next-line no-restricted-syntax
62
57
  export var VideoCodecType;
63
58
  (function (VideoCodecType) {
64
59
  VideoCodecType[VideoCodecType["H264"] = 0] = "H264";
@@ -68,7 +63,6 @@ export var VideoCodecType;
68
63
  /**
69
64
  * @group Camera
70
65
  */
71
- // eslint-disable-next-line no-restricted-syntax
72
66
  export var H264Profile;
73
67
  (function (H264Profile) {
74
68
  H264Profile[H264Profile["BASELINE"] = 0] = "BASELINE";
@@ -78,7 +72,6 @@ export var H264Profile;
78
72
  /**
79
73
  * @group Camera
80
74
  */
81
- // eslint-disable-next-line no-restricted-syntax
82
75
  export var H264Level;
83
76
  (function (H264Level) {
84
77
  H264Level[H264Level["LEVEL3_1"] = 0] = "LEVEL3_1";
@@ -88,31 +81,26 @@ export var H264Level;
88
81
  /**
89
82
  * @group Camera
90
83
  */
91
- // eslint-disable-next-line no-restricted-syntax
92
84
  export var VideoCodecPacketizationMode;
93
85
  (function (VideoCodecPacketizationMode) {
94
86
  VideoCodecPacketizationMode[VideoCodecPacketizationMode["NON_INTERLEAVED"] = 0] = "NON_INTERLEAVED";
95
87
  })(VideoCodecPacketizationMode || (VideoCodecPacketizationMode = {}));
96
- // eslint-disable-next-line no-restricted-syntax
97
88
  var VideoCodecCVO;
98
89
  (function (VideoCodecCVO) {
99
90
  VideoCodecCVO[VideoCodecCVO["UNSUPPORTED"] = 0] = "UNSUPPORTED";
100
91
  VideoCodecCVO[VideoCodecCVO["SUPPORTED"] = 1] = "SUPPORTED";
101
92
  })(VideoCodecCVO || (VideoCodecCVO = {}));
102
93
  // ----------
103
- // eslint-disable-next-line no-restricted-syntax
104
94
  var SupportedAudioStreamConfigurationTypes;
105
95
  (function (SupportedAudioStreamConfigurationTypes) {
106
96
  SupportedAudioStreamConfigurationTypes[SupportedAudioStreamConfigurationTypes["AUDIO_CODEC_CONFIGURATION"] = 1] = "AUDIO_CODEC_CONFIGURATION";
107
97
  SupportedAudioStreamConfigurationTypes[SupportedAudioStreamConfigurationTypes["COMFORT_NOISE_SUPPORT"] = 2] = "COMFORT_NOISE_SUPPORT";
108
98
  })(SupportedAudioStreamConfigurationTypes || (SupportedAudioStreamConfigurationTypes = {}));
109
- // eslint-disable-next-line no-restricted-syntax
110
99
  var AudioCodecConfigurationTypes;
111
100
  (function (AudioCodecConfigurationTypes) {
112
101
  AudioCodecConfigurationTypes[AudioCodecConfigurationTypes["CODEC_TYPE"] = 1] = "CODEC_TYPE";
113
102
  AudioCodecConfigurationTypes[AudioCodecConfigurationTypes["CODEC_PARAMETERS"] = 2] = "CODEC_PARAMETERS";
114
103
  })(AudioCodecConfigurationTypes || (AudioCodecConfigurationTypes = {}));
115
- // eslint-disable-next-line no-restricted-syntax
116
104
  var AudioCodecTypes;
117
105
  (function (AudioCodecTypes) {
118
106
  AudioCodecTypes[AudioCodecTypes["PCMU"] = 0] = "PCMU";
@@ -123,7 +111,6 @@ var AudioCodecTypes;
123
111
  AudioCodecTypes[AudioCodecTypes["AMR"] = 5] = "AMR";
124
112
  AudioCodecTypes[AudioCodecTypes["AMR_WB"] = 6] = "AMR_WB";
125
113
  })(AudioCodecTypes || (AudioCodecTypes = {}));
126
- // eslint-disable-next-line no-restricted-syntax
127
114
  var AudioCodecParametersTypes;
128
115
  (function (AudioCodecParametersTypes) {
129
116
  AudioCodecParametersTypes[AudioCodecParametersTypes["CHANNEL"] = 1] = "CHANNEL";
@@ -134,7 +121,6 @@ var AudioCodecParametersTypes;
134
121
  /**
135
122
  * @group Camera
136
123
  */
137
- // eslint-disable-next-line no-restricted-syntax
138
124
  export var AudioBitrate;
139
125
  (function (AudioBitrate) {
140
126
  AudioBitrate[AudioBitrate["VARIABLE"] = 0] = "VARIABLE";
@@ -143,17 +129,15 @@ export var AudioBitrate;
143
129
  /**
144
130
  * @group Camera
145
131
  */
146
- // eslint-disable-next-line no-restricted-syntax
147
132
  export var AudioSamplerate;
148
133
  (function (AudioSamplerate) {
149
134
  AudioSamplerate[AudioSamplerate["KHZ_8"] = 0] = "KHZ_8";
150
135
  AudioSamplerate[AudioSamplerate["KHZ_16"] = 1] = "KHZ_16";
151
136
  AudioSamplerate[AudioSamplerate["KHZ_24"] = 2] = "KHZ_24";
152
- // 3, 4, 5 are theoretically defined, but no idea to what kHz value they correspond to
137
+ // 3, 4, 5 are theoretically defined, but no idea what kHz value they correspond to
153
138
  // probably KHZ_32, KHZ_44_1, KHZ_48 (as supported by Secure Video recordings)
154
139
  })(AudioSamplerate || (AudioSamplerate = {}));
155
140
  // ----------
156
- // eslint-disable-next-line no-restricted-syntax
157
141
  var SupportedRTPConfigurationTypes;
158
142
  (function (SupportedRTPConfigurationTypes) {
159
143
  SupportedRTPConfigurationTypes[SupportedRTPConfigurationTypes["SRTP_CRYPTO_SUITE"] = 2] = "SRTP_CRYPTO_SUITE";
@@ -161,7 +145,6 @@ var SupportedRTPConfigurationTypes;
161
145
  /**
162
146
  * @group Camera
163
147
  */
164
- // eslint-disable-next-line no-restricted-syntax
165
148
  export var SRTPCryptoSuites;
166
149
  (function (SRTPCryptoSuites) {
167
150
  SRTPCryptoSuites[SRTPCryptoSuites["AES_CM_128_HMAC_SHA1_80"] = 0] = "AES_CM_128_HMAC_SHA1_80";
@@ -169,7 +152,6 @@ export var SRTPCryptoSuites;
169
152
  SRTPCryptoSuites[SRTPCryptoSuites["NONE"] = 2] = "NONE";
170
153
  })(SRTPCryptoSuites || (SRTPCryptoSuites = {}));
171
154
  // ----------
172
- // eslint-disable-next-line no-restricted-syntax
173
155
  var SetupEndpointsTypes;
174
156
  (function (SetupEndpointsTypes) {
175
157
  SetupEndpointsTypes[SetupEndpointsTypes["SESSION_ID"] = 1] = "SESSION_ID";
@@ -177,7 +159,6 @@ var SetupEndpointsTypes;
177
159
  SetupEndpointsTypes[SetupEndpointsTypes["VIDEO_SRTP_PARAMETERS"] = 4] = "VIDEO_SRTP_PARAMETERS";
178
160
  SetupEndpointsTypes[SetupEndpointsTypes["AUDIO_SRTP_PARAMETERS"] = 5] = "AUDIO_SRTP_PARAMETERS";
179
161
  })(SetupEndpointsTypes || (SetupEndpointsTypes = {}));
180
- // eslint-disable-next-line no-restricted-syntax
181
162
  var AddressTypes;
182
163
  (function (AddressTypes) {
183
164
  AddressTypes[AddressTypes["ADDRESS_VERSION"] = 1] = "ADDRESS_VERSION";
@@ -185,20 +166,17 @@ var AddressTypes;
185
166
  AddressTypes[AddressTypes["VIDEO_RTP_PORT"] = 3] = "VIDEO_RTP_PORT";
186
167
  AddressTypes[AddressTypes["AUDIO_RTP_PORT"] = 4] = "AUDIO_RTP_PORT";
187
168
  })(AddressTypes || (AddressTypes = {}));
188
- // eslint-disable-next-line no-restricted-syntax
189
169
  var IPAddressVersion;
190
170
  (function (IPAddressVersion) {
191
171
  IPAddressVersion[IPAddressVersion["IPV4"] = 0] = "IPV4";
192
172
  IPAddressVersion[IPAddressVersion["IPV6"] = 1] = "IPV6";
193
173
  })(IPAddressVersion || (IPAddressVersion = {}));
194
- // eslint-disable-next-line no-restricted-syntax
195
174
  var SRTPParametersTypes;
196
175
  (function (SRTPParametersTypes) {
197
176
  SRTPParametersTypes[SRTPParametersTypes["SRTP_CRYPTO_SUITE"] = 1] = "SRTP_CRYPTO_SUITE";
198
177
  SRTPParametersTypes[SRTPParametersTypes["MASTER_KEY"] = 2] = "MASTER_KEY";
199
178
  SRTPParametersTypes[SRTPParametersTypes["MASTER_SALT"] = 3] = "MASTER_SALT";
200
179
  })(SRTPParametersTypes || (SRTPParametersTypes = {}));
201
- // eslint-disable-next-line no-restricted-syntax
202
180
  var SetupEndpointsResponseTypes;
203
181
  (function (SetupEndpointsResponseTypes) {
204
182
  SetupEndpointsResponseTypes[SetupEndpointsResponseTypes["SESSION_ID"] = 1] = "SESSION_ID";
@@ -209,7 +187,6 @@ var SetupEndpointsResponseTypes;
209
187
  SetupEndpointsResponseTypes[SetupEndpointsResponseTypes["VIDEO_SSRC"] = 6] = "VIDEO_SSRC";
210
188
  SetupEndpointsResponseTypes[SetupEndpointsResponseTypes["AUDIO_SSRC"] = 7] = "AUDIO_SSRC";
211
189
  })(SetupEndpointsResponseTypes || (SetupEndpointsResponseTypes = {}));
212
- // eslint-disable-next-line no-restricted-syntax
213
190
  var SetupEndpointsStatus;
214
191
  (function (SetupEndpointsStatus) {
215
192
  SetupEndpointsStatus[SetupEndpointsStatus["SUCCESS"] = 0] = "SUCCESS";
@@ -217,14 +194,12 @@ var SetupEndpointsStatus;
217
194
  SetupEndpointsStatus[SetupEndpointsStatus["ERROR"] = 2] = "ERROR";
218
195
  })(SetupEndpointsStatus || (SetupEndpointsStatus = {}));
219
196
  // ----------
220
- // eslint-disable-next-line no-restricted-syntax
221
197
  var SelectedRTPStreamConfigurationTypes;
222
198
  (function (SelectedRTPStreamConfigurationTypes) {
223
199
  SelectedRTPStreamConfigurationTypes[SelectedRTPStreamConfigurationTypes["SESSION_CONTROL"] = 1] = "SESSION_CONTROL";
224
200
  SelectedRTPStreamConfigurationTypes[SelectedRTPStreamConfigurationTypes["SELECTED_VIDEO_PARAMETERS"] = 2] = "SELECTED_VIDEO_PARAMETERS";
225
201
  SelectedRTPStreamConfigurationTypes[SelectedRTPStreamConfigurationTypes["SELECTED_AUDIO_PARAMETERS"] = 3] = "SELECTED_AUDIO_PARAMETERS";
226
202
  })(SelectedRTPStreamConfigurationTypes || (SelectedRTPStreamConfigurationTypes = {}));
227
- // eslint-disable-next-line no-restricted-syntax
228
203
  var SessionControlTypes;
229
204
  (function (SessionControlTypes) {
230
205
  SessionControlTypes[SessionControlTypes["SESSION_IDENTIFIER"] = 1] = "SESSION_IDENTIFIER";
@@ -238,7 +213,6 @@ var SessionControlCommand;
238
213
  SessionControlCommand[SessionControlCommand["RESUME_SESSION"] = 3] = "RESUME_SESSION";
239
214
  SessionControlCommand[SessionControlCommand["RECONFIGURE_SESSION"] = 4] = "RECONFIGURE_SESSION";
240
215
  })(SessionControlCommand || (SessionControlCommand = {}));
241
- // eslint-disable-next-line no-restricted-syntax
242
216
  var SelectedVideoParametersTypes;
243
217
  (function (SelectedVideoParametersTypes) {
244
218
  SelectedVideoParametersTypes[SelectedVideoParametersTypes["CODEC_TYPE"] = 1] = "CODEC_TYPE";
@@ -246,7 +220,6 @@ var SelectedVideoParametersTypes;
246
220
  SelectedVideoParametersTypes[SelectedVideoParametersTypes["ATTRIBUTES"] = 3] = "ATTRIBUTES";
247
221
  SelectedVideoParametersTypes[SelectedVideoParametersTypes["RTP_PARAMETERS"] = 4] = "RTP_PARAMETERS";
248
222
  })(SelectedVideoParametersTypes || (SelectedVideoParametersTypes = {}));
249
- // eslint-disable-next-line no-restricted-syntax
250
223
  var VideoRTPParametersTypes;
251
224
  (function (VideoRTPParametersTypes) {
252
225
  VideoRTPParametersTypes[VideoRTPParametersTypes["PAYLOAD_TYPE"] = 1] = "PAYLOAD_TYPE";
@@ -255,7 +228,6 @@ var VideoRTPParametersTypes;
255
228
  VideoRTPParametersTypes[VideoRTPParametersTypes["MIN_RTCP_INTERVAL"] = 4] = "MIN_RTCP_INTERVAL";
256
229
  VideoRTPParametersTypes[VideoRTPParametersTypes["MAX_MTU"] = 5] = "MAX_MTU";
257
230
  })(VideoRTPParametersTypes || (VideoRTPParametersTypes = {}));
258
- // eslint-disable-next-line no-restricted-syntax
259
231
  var SelectedAudioParametersTypes;
260
232
  (function (SelectedAudioParametersTypes) {
261
233
  SelectedAudioParametersTypes[SelectedAudioParametersTypes["CODEC_TYPE"] = 1] = "CODEC_TYPE";
@@ -263,7 +235,6 @@ var SelectedAudioParametersTypes;
263
235
  SelectedAudioParametersTypes[SelectedAudioParametersTypes["RTP_PARAMETERS"] = 3] = "RTP_PARAMETERS";
264
236
  SelectedAudioParametersTypes[SelectedAudioParametersTypes["COMFORT_NOISE"] = 4] = "COMFORT_NOISE";
265
237
  })(SelectedAudioParametersTypes || (SelectedAudioParametersTypes = {}));
266
- // eslint-disable-next-line no-restricted-syntax
267
238
  var AudioRTPParametersTypes;
268
239
  (function (AudioRTPParametersTypes) {
269
240
  AudioRTPParametersTypes[AudioRTPParametersTypes["PAYLOAD_TYPE"] = 1] = "PAYLOAD_TYPE";
@@ -278,7 +249,6 @@ function isLegacySRTPOptions(options) {
278
249
  /**
279
250
  * @group Camera
280
251
  */
281
- // eslint-disable-next-line no-restricted-syntax
282
252
  export var AudioStreamingCodecType;
283
253
  (function (AudioStreamingCodecType) {
284
254
  AudioStreamingCodecType["PCMU"] = "PCMU";
@@ -292,7 +262,6 @@ export var AudioStreamingCodecType;
292
262
  /**
293
263
  * @group Camera
294
264
  */
295
- // eslint-disable-next-line no-restricted-syntax
296
265
  export var AudioStreamingSamplerate;
297
266
  (function (AudioStreamingSamplerate) {
298
267
  AudioStreamingSamplerate[AudioStreamingSamplerate["KHZ_8"] = 8] = "KHZ_8";
@@ -302,7 +271,6 @@ export var AudioStreamingSamplerate;
302
271
  /**
303
272
  * @group Camera
304
273
  */
305
- // eslint-disable-next-line no-restricted-syntax
306
274
  export var StreamRequestTypes;
307
275
  (function (StreamRequestTypes) {
308
276
  StreamRequestTypes["RECONFIGURE"] = "reconfigure";
@@ -330,10 +298,15 @@ export class RTPStreamManagement {
330
298
  /**
331
299
  * @private
332
300
  */
333
- streamStatus = 0 /* StreamingStatus.AVAILABLE */; // use _updateStreamStatus to update this property
301
+ streamStatus = StreamingStatus.AVAILABLE; // use _updateStreamStatus to update this property
334
302
  ipVersion; // ip version for the current session
335
303
  selectedConfiguration = ''; // base64 representation of the currently selected configuration
336
304
  setupEndpointsResponse = ''; // response of the SetupEndpoints Characteristic
305
+ /**
306
+ * The BUSY answers for the connections which asked for a stream while another session held it.
307
+ * They are kept apart from {@link setupEndpointsResponse}, which belongs to the session which holds the stream.
308
+ */
309
+ busySetupEndpointsResponses = new WeakMap();
337
310
  /**
338
311
  * @private
339
312
  */
@@ -355,14 +328,14 @@ export class RTPStreamManagement {
355
328
  this.disableAudioProxy = options.disable_audio_proxy || false;
356
329
  if (isLegacySRTPOptions(options)) {
357
330
  this.supportedCryptoSuites = [
358
- options.srtp ? 0 /* SRTPCryptoSuites.AES_CM_128_HMAC_SHA1_80 */ : 2 /* SRTPCryptoSuites.NONE */,
331
+ options.srtp ? SRTPCryptoSuites.AES_CM_128_HMAC_SHA1_80 : SRTPCryptoSuites.NONE,
359
332
  ];
360
333
  }
361
334
  else {
362
- this.supportedCryptoSuites = options.supportedCryptoSuites;
335
+ this.supportedCryptoSuites = [...options.supportedCryptoSuites]; // a copy: the options belong to the plugin, and are shared by all streams
363
336
  }
364
337
  if (this.supportedCryptoSuites.length === 0) {
365
- this.supportedCryptoSuites.push(2 /* SRTPCryptoSuites.NONE */);
338
+ this.supportedCryptoSuites.push(SRTPCryptoSuites.NONE);
366
339
  }
367
340
  if (!options.video) {
368
341
  throw new Error('Video parameters cannot be undefined in options');
@@ -387,7 +360,7 @@ export class RTPStreamManagement {
387
360
  this.resetSelectedStreamConfiguration();
388
361
  this.resetSetupEndpointsResponse();
389
362
  this.service.updateCharacteristic(Characteristic.Active, true);
390
- // on a factory reset the assumption is that all connections were already terminated and thus "handleStopStream" was already called
363
+ // on a factory reset the assumption is that all connections were already terminated and thus "_handleStopStream" was already called
391
364
  }
392
365
  destroy() {
393
366
  if (this.activeConnection) {
@@ -407,34 +380,35 @@ export class RTPStreamManagement {
407
380
  this.service.setCharacteristic(Characteristic.Active, true);
408
381
  }
409
382
  this.service.getCharacteristic(Characteristic.Active)
410
- .on("change" /* CharacteristicEventTypes.CHANGE */, () => this.stateChangeDelegate?.())
383
+ .on(CharacteristicEventTypes.CHANGE, () => this.stateChangeDelegate?.())
411
384
  .setProps({
412
- adminOnlyAccess: [1 /* Access.WRITE */],
385
+ adminOnlyAccess: [Access.WRITE],
413
386
  });
414
387
  // ensure that configurations are up-to-date and reflected in the characteristic values
415
388
  this.service.setCharacteristic(Characteristic.SupportedRTPConfiguration, this.supportedRTPConfiguration);
416
389
  this.service.setCharacteristic(Characteristic.SupportedVideoStreamConfiguration, this.supportedVideoStreamConfiguration);
417
390
  this.service.setCharacteristic(Characteristic.SupportedAudioStreamConfiguration, this.supportedAudioStreamConfiguration);
418
- this._updateStreamStatus(0 /* StreamingStatus.AVAILABLE */); // reset streaming status to available
391
+ this._updateStreamStatus(StreamingStatus.AVAILABLE); // reset streaming status to available
419
392
  this.service.setCharacteristic(Characteristic.SetupEndpoints, this.setupEndpointsResponse); // reset SetupEndpoints to default
420
393
  this.service.getCharacteristic(Characteristic.SelectedRTPStreamConfiguration)
421
- .on("get" /* CharacteristicEventTypes.GET */, (callback) => {
394
+ .on(CharacteristicEventTypes.GET, (callback) => {
422
395
  if (this.streamingIsDisabled()) {
423
- callback(null, tlv.encode(1 /* SelectedRTPStreamConfigurationTypes.SESSION_CONTROL */, tlv.encode(2 /* SessionControlTypes.COMMAND */, SessionControlCommand.SUSPEND_SESSION)).toString('base64'));
396
+ callback(null, tlv.encode(SelectedRTPStreamConfigurationTypes.SESSION_CONTROL, tlv.encode(SessionControlTypes.COMMAND, SessionControlCommand.SUSPEND_SESSION)).toString('base64'));
424
397
  return;
425
398
  }
426
399
  callback(null, this.selectedConfiguration);
427
400
  })
428
- .on("set" /* CharacteristicEventTypes.SET */, this._handleSelectedStreamConfigurationWrite.bind(this));
401
+ .on(CharacteristicEventTypes.SET, this._handleSelectedStreamConfigurationWrite.bind(this));
429
402
  this.service.getCharacteristic(Characteristic.SetupEndpoints)
430
- .on("get" /* CharacteristicEventTypes.GET */, (callback) => {
403
+ .on(CharacteristicEventTypes.GET, (callback, _context, connection) => {
431
404
  if (this.streamingIsDisabled()) {
432
- callback(null, tlv.encode(2 /* SetupEndpointsResponseTypes.STATUS */, 2 /* SetupEndpointsStatus.ERROR */).toString('base64'));
405
+ callback(null, tlv.encode(SetupEndpointsResponseTypes.STATUS, SetupEndpointsStatus.ERROR).toString('base64'));
433
406
  return;
434
407
  }
435
- callback(null, this.setupEndpointsResponse);
408
+ // a connection which was told that the stream is busy reads that answer, everybody else the one of the session
409
+ callback(null, (connection && this.busySetupEndpointsResponses.get(connection)) ?? this.setupEndpointsResponse);
436
410
  })
437
- .on("set" /* CharacteristicEventTypes.SET */, (value, callback, context, connection) => {
411
+ .on(CharacteristicEventTypes.SET, (value, callback, _context, connection) => {
438
412
  if (!connection) {
439
413
  debug('Set event handler for SetupEndpoints cannot be called from plugin. Connection undefined!');
440
414
  callback(HAPStatus.INVALID_VALUE_IN_REQUEST);
@@ -447,11 +421,11 @@ export class RTPStreamManagement {
447
421
  this.resetSelectedStreamConfiguration();
448
422
  this.resetSetupEndpointsResponse();
449
423
  if (this.activeConnection) {
450
- this.activeConnection.removeListener("closed" /* HAPConnectionEvent.CLOSED */, this.activeConnectionClosedListener);
424
+ this.activeConnection.removeListener(HAPConnectionEvent.CLOSED, this.activeConnectionClosedListener);
451
425
  this.activeConnection.setMaxListeners(this.activeConnection.getMaxListeners() - 1);
452
426
  this.activeConnection = undefined;
453
427
  }
454
- this._updateStreamStatus(0 /* StreamingStatus.AVAILABLE */);
428
+ this._updateStreamStatus(StreamingStatus.AVAILABLE);
455
429
  this.sessionIdentifier = undefined;
456
430
  this.ipVersion = undefined;
457
431
  if (this.videoProxy) {
@@ -484,9 +458,9 @@ export class RTPStreamManagement {
484
458
  }
485
459
  const data = Buffer.from(value, 'base64');
486
460
  const objects = tlv.decode(data);
487
- const sessionControl = tlv.decode(objects[1 /* SelectedRTPStreamConfigurationTypes.SESSION_CONTROL */]);
488
- const sessionIdentifier = uuid.unparse(sessionControl[1 /* SessionControlTypes.SESSION_IDENTIFIER */]);
489
- const requestType = sessionControl[2 /* SessionControlTypes.COMMAND */][0];
461
+ const sessionControl = tlv.decode(objects[SelectedRTPStreamConfigurationTypes.SESSION_CONTROL]);
462
+ const sessionIdentifier = uuid.unparse(sessionControl[SessionControlTypes.SESSION_IDENTIFIER]);
463
+ const requestType = sessionControl[SessionControlTypes.COMMAND][0];
490
464
  if (sessionIdentifier !== this.sessionIdentifier) {
491
465
  debug(`Received unknown session Identifier with request to ${SessionControlCommand[requestType]}`);
492
466
  callback(HAPStatus.INVALID_VALUE_IN_REQUEST);
@@ -495,20 +469,33 @@ export class RTPStreamManagement {
495
469
  this.selectedConfiguration = value;
496
470
  // intercept the callback chain to check if an error occurred.
497
471
  const streamCallback = (error, writeResponse) => {
498
- callback(error, writeResponse); // does not support writeResponse, but how knows what comes in the future.
499
- if (error) {
500
- this.handleSessionClosed();
472
+ callback(error, writeResponse); // does not support writeResponse, but who knows what comes in the future.
473
+ // a late answer for a session which already ended must leave the session which came after it alone
474
+ if (error && this.sessionIdentifier === sessionIdentifier) {
475
+ if (requestType !== SessionControlCommand.END_SESSION) {
476
+ // The session is given up, but the delegate may still be streaming for it (it does after a failed
477
+ // reconfigure). The controller's END_SESSION won't reach it anymore, so it is told to stop here.
478
+ try {
479
+ this._handleStopStream();
480
+ }
481
+ catch (stopError) {
482
+ debug('Failed to stop the stream after a failed request: %s', errorMessage(stopError));
483
+ }
484
+ }
485
+ else {
486
+ this.handleSessionClosed();
487
+ }
501
488
  }
502
489
  };
503
490
  switch (requestType) {
504
491
  case SessionControlCommand.START_SESSION: {
505
- const selectedVideoParameters = tlv.decode(objects[2 /* SelectedRTPStreamConfigurationTypes.SELECTED_VIDEO_PARAMETERS */]);
506
- const selectedAudioParameters = tlv.decode(objects[3 /* SelectedRTPStreamConfigurationTypes.SELECTED_AUDIO_PARAMETERS */]);
492
+ const selectedVideoParameters = tlv.decode(objects[SelectedRTPStreamConfigurationTypes.SELECTED_VIDEO_PARAMETERS]);
493
+ const selectedAudioParameters = tlv.decode(objects[SelectedRTPStreamConfigurationTypes.SELECTED_AUDIO_PARAMETERS]);
507
494
  this._handleStartStream(selectedVideoParameters, selectedAudioParameters, streamCallback);
508
495
  break;
509
496
  }
510
497
  case SessionControlCommand.RECONFIGURE_SESSION: {
511
- const reconfiguredVideoParameters = tlv.decode(objects[2 /* SelectedRTPStreamConfigurationTypes.SELECTED_VIDEO_PARAMETERS */]);
498
+ const reconfiguredVideoParameters = tlv.decode(objects[SelectedRTPStreamConfigurationTypes.SELECTED_VIDEO_PARAMETERS]);
512
499
  this.handleReconfigureStream(reconfiguredVideoParameters, streamCallback);
513
500
  break;
514
501
  }
@@ -527,62 +514,62 @@ export class RTPStreamManagement {
527
514
  this._handleStartStreamInner(videoConfiguration, audioConfiguration, callback);
528
515
  }
529
516
  catch (error) {
530
- debug('Failed to parse stream start request: %s', error.message);
517
+ debug('Failed to parse stream start request: %s', errorMessage(error));
531
518
  callback(HAPStatus.INVALID_VALUE_IN_REQUEST);
532
519
  }
533
520
  }
534
521
  _handleStartStreamInner(videoConfiguration, audioConfiguration, callback) {
535
522
  // selected video configuration
536
523
  // noinspection JSUnusedLocalSymbols
537
- const videoCodec = videoConfiguration[1 /* SelectedVideoParametersTypes.CODEC_TYPE */]; // always 0x00 for h264
538
- const videoParametersTLV = videoConfiguration[2 /* SelectedVideoParametersTypes.CODEC_PARAMETERS */];
539
- const videoAttributesTLV = videoConfiguration[3 /* SelectedVideoParametersTypes.ATTRIBUTES */];
540
- const videoRTPParametersTLV = videoConfiguration[4 /* SelectedVideoParametersTypes.RTP_PARAMETERS */];
524
+ const videoCodec = videoConfiguration[SelectedVideoParametersTypes.CODEC_TYPE]; // always 0x00 for h264
525
+ const videoParametersTLV = videoConfiguration[SelectedVideoParametersTypes.CODEC_PARAMETERS];
526
+ const videoAttributesTLV = videoConfiguration[SelectedVideoParametersTypes.ATTRIBUTES];
527
+ const videoRTPParametersTLV = videoConfiguration[SelectedVideoParametersTypes.RTP_PARAMETERS];
541
528
  // video parameters
542
529
  const videoParameters = tlv.decode(videoParametersTLV);
543
- const h264Profile = videoParameters[1 /* VideoCodecParametersTypes.PROFILE_ID */][0];
544
- const h264Level = videoParameters[2 /* VideoCodecParametersTypes.LEVEL */][0];
545
- const packetizationMode = videoParameters[3 /* VideoCodecParametersTypes.PACKETIZATION_MODE */][0];
546
- const cvoEnabled = videoParameters[4 /* VideoCodecParametersTypes.CVO_ENABLED */];
530
+ const h264Profile = videoParameters[VideoCodecParametersTypes.PROFILE_ID][0];
531
+ const h264Level = videoParameters[VideoCodecParametersTypes.LEVEL][0];
532
+ const packetizationMode = videoParameters[VideoCodecParametersTypes.PACKETIZATION_MODE][0];
533
+ const cvoEnabled = videoParameters[VideoCodecParametersTypes.CVO_ENABLED];
547
534
  let cvoId;
548
- if (cvoEnabled && cvoEnabled[0] === 1 /* VideoCodecCVO.SUPPORTED */) {
549
- cvoId = videoParameters[5 /* VideoCodecParametersTypes.CVO_ID */].readUInt8(0);
535
+ if (cvoEnabled && cvoEnabled[0] === VideoCodecCVO.SUPPORTED) {
536
+ cvoId = videoParameters[VideoCodecParametersTypes.CVO_ID].readUInt8(0);
550
537
  }
551
538
  // video attributes
552
539
  const videoAttributes = tlv.decode(videoAttributesTLV);
553
- const width = videoAttributes[1 /* VideoAttributesTypes.IMAGE_WIDTH */].readUInt16LE(0);
554
- const height = videoAttributes[2 /* VideoAttributesTypes.IMAGE_HEIGHT */].readUInt16LE(0);
555
- const frameRate = videoAttributes[3 /* VideoAttributesTypes.FRAME_RATE */].readUInt8(0);
540
+ const width = videoAttributes[VideoAttributesTypes.IMAGE_WIDTH].readUInt16LE(0);
541
+ const height = videoAttributes[VideoAttributesTypes.IMAGE_HEIGHT].readUInt16LE(0);
542
+ const frameRate = videoAttributes[VideoAttributesTypes.FRAME_RATE].readUInt8(0);
556
543
  // video rtp parameters
557
544
  const videoRTPParameters = tlv.decode(videoRTPParametersTLV);
558
- const videoPayloadType = videoRTPParameters[1 /* VideoRTPParametersTypes.PAYLOAD_TYPE */].readUInt8(0); // 99
559
- const videoSSRC = videoRTPParameters[2 /* VideoRTPParametersTypes.SYNCHRONIZATION_SOURCE */].readUInt32LE(0);
560
- const videoMaximumBitrate = videoRTPParameters[3 /* VideoRTPParametersTypes.MAX_BIT_RATE */].readUInt16LE(0);
561
- const videoRTCPInterval = videoRTPParameters[4 /* VideoRTPParametersTypes.MIN_RTCP_INTERVAL */].readFloatLE(0);
545
+ const videoPayloadType = videoRTPParameters[VideoRTPParametersTypes.PAYLOAD_TYPE].readUInt8(0); // 99
546
+ const videoSSRC = videoRTPParameters[VideoRTPParametersTypes.SYNCHRONIZATION_SOURCE].readUInt32LE(0);
547
+ const videoMaximumBitrate = videoRTPParameters[VideoRTPParametersTypes.MAX_BIT_RATE].readUInt16LE(0);
548
+ const videoRTCPInterval = videoRTPParameters[VideoRTPParametersTypes.MIN_RTCP_INTERVAL].readFloatLE(0);
562
549
  let maxMTU = this.ipVersion === 'ipv6'
563
550
  ? 1228
564
551
  : 1378; // default values ipv4: 1378 bytes; ipv6: 1228 bytes
565
- if (videoRTPParameters[5 /* VideoRTPParametersTypes.MAX_MTU */]) {
566
- maxMTU = videoRTPParameters[5 /* VideoRTPParametersTypes.MAX_MTU */].readUInt16LE(0);
552
+ if (videoRTPParameters[VideoRTPParametersTypes.MAX_MTU]) {
553
+ maxMTU = videoRTPParameters[VideoRTPParametersTypes.MAX_MTU].readUInt16LE(0);
567
554
  }
568
555
  // selected audio configuration
569
- const audioCodec = audioConfiguration[1 /* SelectedAudioParametersTypes.CODEC_TYPE */][0];
570
- const audioParametersTLV = audioConfiguration[2 /* SelectedAudioParametersTypes.CODEC_PARAMETERS */];
571
- const audioRTPParametersTLV = audioConfiguration[3 /* SelectedAudioParametersTypes.RTP_PARAMETERS */];
572
- const comfortNoise = !!audioConfiguration[4 /* SelectedAudioParametersTypes.COMFORT_NOISE */].readUInt8(0);
556
+ const audioCodec = audioConfiguration[SelectedAudioParametersTypes.CODEC_TYPE][0];
557
+ const audioParametersTLV = audioConfiguration[SelectedAudioParametersTypes.CODEC_PARAMETERS];
558
+ const audioRTPParametersTLV = audioConfiguration[SelectedAudioParametersTypes.RTP_PARAMETERS];
559
+ const comfortNoise = !!audioConfiguration[SelectedAudioParametersTypes.COMFORT_NOISE].readUInt8(0);
573
560
  // audio parameters
574
561
  const audioParameters = tlv.decode(audioParametersTLV);
575
- const channels = audioParameters[1 /* AudioCodecParametersTypes.CHANNEL */][0];
576
- const audioBitrate = audioParameters[2 /* AudioCodecParametersTypes.BIT_RATE */][0];
577
- const samplerate = audioParameters[3 /* AudioCodecParametersTypes.SAMPLE_RATE */][0];
578
- const rtpPacketTime = audioParameters[4 /* AudioCodecParametersTypes.PACKET_TIME */].readUInt8(0);
562
+ const channels = audioParameters[AudioCodecParametersTypes.CHANNEL][0];
563
+ const audioBitrate = audioParameters[AudioCodecParametersTypes.BIT_RATE][0];
564
+ const samplerate = audioParameters[AudioCodecParametersTypes.SAMPLE_RATE][0];
565
+ const rtpPacketTime = audioParameters[AudioCodecParametersTypes.PACKET_TIME].readUInt8(0);
579
566
  // audio rtp parameters
580
567
  const audioRTPParameters = tlv.decode(audioRTPParametersTLV);
581
- const audioPayloadType = audioRTPParameters[1 /* AudioRTPParametersTypes.PAYLOAD_TYPE */].readUInt8(0); // 110
582
- const audioSSRC = audioRTPParameters[2 /* AudioRTPParametersTypes.SYNCHRONIZATION_SOURCE */].readUInt32LE(0);
583
- const audioMaximumBitrate = audioRTPParameters[3 /* AudioRTPParametersTypes.MAX_BIT_RATE */].readUInt16LE(0);
584
- const audioRTCPInterval = audioRTPParameters[4 /* AudioRTPParametersTypes.MIN_RTCP_INTERVAL */].readFloatLE(0);
585
- const comfortNoisePayloadType = audioRTPParameters[6 /* AudioRTPParametersTypes.COMFORT_NOISE_PAYLOAD_TYPE */].readUInt8(0); // 13
568
+ const audioPayloadType = audioRTPParameters[AudioRTPParametersTypes.PAYLOAD_TYPE].readUInt8(0); // 110
569
+ const audioSSRC = audioRTPParameters[AudioRTPParametersTypes.SYNCHRONIZATION_SOURCE].readUInt32LE(0);
570
+ const audioMaximumBitrate = audioRTPParameters[AudioRTPParametersTypes.MAX_BIT_RATE].readUInt16LE(0);
571
+ const audioRTCPInterval = audioRTPParameters[AudioRTPParametersTypes.MIN_RTCP_INTERVAL].readFloatLE(0);
572
+ const comfortNoisePayloadType = audioRTPParameters[AudioRTPParametersTypes.COMFORT_NOISE_PAYLOAD_TYPE].readUInt8(0); // 13
586
573
  if (this.requireProxy) {
587
574
  this.videoProxy.setOutgoingPayloadType(videoPayloadType);
588
575
  if (!this.disableAudioProxy) {
@@ -607,38 +594,38 @@ export class RTPStreamManagement {
607
594
  let audioCodecName;
608
595
  let samplerateNum;
609
596
  switch (audioCodec) {
610
- case 0 /* AudioCodecTypes.PCMU */:
611
- audioCodecName = "PCMU" /* AudioStreamingCodecType.PCMU */;
597
+ case AudioCodecTypes.PCMU:
598
+ audioCodecName = AudioStreamingCodecType.PCMU;
612
599
  break;
613
- case 1 /* AudioCodecTypes.PCMA */:
614
- audioCodecName = "PCMA" /* AudioStreamingCodecType.PCMA */;
600
+ case AudioCodecTypes.PCMA:
601
+ audioCodecName = AudioStreamingCodecType.PCMA;
615
602
  break;
616
- case 2 /* AudioCodecTypes.AAC_ELD */:
617
- audioCodecName = "AAC-eld" /* AudioStreamingCodecType.AAC_ELD */;
603
+ case AudioCodecTypes.AAC_ELD:
604
+ audioCodecName = AudioStreamingCodecType.AAC_ELD;
618
605
  break;
619
- case 3 /* AudioCodecTypes.OPUS */:
620
- audioCodecName = "OPUS" /* AudioStreamingCodecType.OPUS */;
606
+ case AudioCodecTypes.OPUS:
607
+ audioCodecName = AudioStreamingCodecType.OPUS;
621
608
  break;
622
- case 4 /* AudioCodecTypes.MSBC */:
623
- audioCodecName = "mSBC" /* AudioStreamingCodecType.MSBC */;
609
+ case AudioCodecTypes.MSBC:
610
+ audioCodecName = AudioStreamingCodecType.MSBC;
624
611
  break;
625
- case 5 /* AudioCodecTypes.AMR */:
626
- audioCodecName = "AMR" /* AudioStreamingCodecType.AMR */;
612
+ case AudioCodecTypes.AMR:
613
+ audioCodecName = AudioStreamingCodecType.AMR;
627
614
  break;
628
- case 6 /* AudioCodecTypes.AMR_WB */:
629
- audioCodecName = "AMR-WB" /* AudioStreamingCodecType.AMR_WB */;
615
+ case AudioCodecTypes.AMR_WB:
616
+ audioCodecName = AudioStreamingCodecType.AMR_WB;
630
617
  break;
631
618
  default:
632
619
  throw new Error(`Encountered unknown selected audio codec ${audioCodec}`);
633
620
  }
634
621
  switch (samplerate) {
635
- case 0 /* AudioSamplerate.KHZ_8 */:
622
+ case AudioSamplerate.KHZ_8:
636
623
  samplerateNum = 8;
637
624
  break;
638
- case 1 /* AudioSamplerate.KHZ_16 */:
625
+ case AudioSamplerate.KHZ_16:
639
626
  samplerateNum = 16;
640
627
  break;
641
- case 2 /* AudioSamplerate.KHZ_24 */:
628
+ case AudioSamplerate.KHZ_24:
642
629
  samplerateNum = 24;
643
630
  break;
644
631
  default:
@@ -659,7 +646,7 @@ export class RTPStreamManagement {
659
646
  };
660
647
  const request = {
661
648
  sessionID: this.sessionIdentifier,
662
- type: "start" /* StreamRequestTypes.START */,
649
+ type: StreamRequestTypes.START,
663
650
  video: videoInfo,
664
651
  audio: audioInfo,
665
652
  };
@@ -667,18 +654,18 @@ export class RTPStreamManagement {
667
654
  }
668
655
  handleReconfigureStream(videoConfiguration, callback) {
669
656
  // selected video configuration
670
- const videoAttributesTLV = videoConfiguration[3 /* SelectedVideoParametersTypes.ATTRIBUTES */];
671
- const videoRTPParametersTLV = videoConfiguration[4 /* SelectedVideoParametersTypes.RTP_PARAMETERS */];
657
+ const videoAttributesTLV = videoConfiguration[SelectedVideoParametersTypes.ATTRIBUTES];
658
+ const videoRTPParametersTLV = videoConfiguration[SelectedVideoParametersTypes.RTP_PARAMETERS];
672
659
  // video attributes
673
660
  const videoAttributes = tlv.decode(videoAttributesTLV);
674
- const width = videoAttributes[1 /* VideoAttributesTypes.IMAGE_WIDTH */].readUInt16LE(0);
675
- const height = videoAttributes[2 /* VideoAttributesTypes.IMAGE_HEIGHT */].readUInt16LE(0);
676
- const frameRate = videoAttributes[3 /* VideoAttributesTypes.FRAME_RATE */].readUInt8(0);
661
+ const width = videoAttributes[VideoAttributesTypes.IMAGE_WIDTH].readUInt16LE(0);
662
+ const height = videoAttributes[VideoAttributesTypes.IMAGE_HEIGHT].readUInt16LE(0);
663
+ const frameRate = videoAttributes[VideoAttributesTypes.FRAME_RATE].readUInt8(0);
677
664
  // video rtp parameters
678
665
  const videoRTPParameters = tlv.decode(videoRTPParametersTLV);
679
- const videoMaximumBitrate = videoRTPParameters[3 /* VideoRTPParametersTypes.MAX_BIT_RATE */].readUInt16LE(0);
666
+ const videoMaximumBitrate = videoRTPParameters[VideoRTPParametersTypes.MAX_BIT_RATE].readUInt16LE(0);
680
667
  // seems to be always zero, use default of 0.5
681
- const videoRTCPInterval = videoRTPParameters[4 /* VideoRTPParametersTypes.MIN_RTCP_INTERVAL */].readFloatLE(0) || 0.5;
668
+ const videoRTCPInterval = videoRTPParameters[VideoRTPParametersTypes.MIN_RTCP_INTERVAL].readFloatLE(0) || 0.5;
682
669
  const reconfiguredVideoInfo = {
683
670
  width,
684
671
  height,
@@ -688,7 +675,7 @@ export class RTPStreamManagement {
688
675
  };
689
676
  const request = {
690
677
  sessionID: this.sessionIdentifier,
691
- type: "reconfigure" /* StreamRequestTypes.RECONFIGURE */,
678
+ type: StreamRequestTypes.RECONFIGURE,
692
679
  video: reconfiguredVideoInfo,
693
680
  };
694
681
  this.delegate.handleStreamRequest(request, error => callback(error));
@@ -696,7 +683,7 @@ export class RTPStreamManagement {
696
683
  _handleStopStream(callback) {
697
684
  const request = {
698
685
  sessionID: this.sessionIdentifier, // save sessionIdentifier before handleSessionClosed is called
699
- type: "stop" /* StreamRequestTypes.STOP */,
686
+ type: StreamRequestTypes.STOP,
700
687
  };
701
688
  this.handleSessionClosed();
702
689
  this.delegate.handleStreamRequest(request, error => callback
@@ -713,28 +700,29 @@ export class RTPStreamManagement {
713
700
  request = this.parseSetupEndpointsRequest(value);
714
701
  }
715
702
  catch (error) {
716
- debug('Failed to parse SetupEndpoints request: %s', error.message);
703
+ debug('Failed to parse SetupEndpoints request: %s', errorMessage(error));
717
704
  callback(HAPStatus.INVALID_VALUE_IN_REQUEST);
718
705
  return;
719
706
  }
720
707
  const { sessionIdentifier, addressVersion, controllerAddress, targetVideoPort, targetAudioPort, videoCryptoSuite, videoMasterKey, videoMasterSalt, audioCryptoSuite, audioMasterKey, audioMasterSalt, } = request;
721
- if (this.streamStatus !== 0 /* StreamingStatus.AVAILABLE */) {
722
- this.setupEndpointsResponse = tlv.encode(1 /* SetupEndpointsResponseTypes.SESSION_ID */, uuid.write(sessionIdentifier), 2 /* SetupEndpointsResponseTypes.STATUS */, 1 /* SetupEndpointsStatus.BUSY */).toString('base64');
708
+ if (this.streamStatus !== StreamingStatus.AVAILABLE) {
709
+ // only the connection which asked reads this answer: the response of the session which holds the stream stays
710
+ this.busySetupEndpointsResponses.set(connection, tlv.encode(SetupEndpointsResponseTypes.SESSION_ID, uuid.write(sessionIdentifier), SetupEndpointsResponseTypes.STATUS, SetupEndpointsStatus.BUSY).toString('base64'));
723
711
  callback();
724
712
  return;
725
713
  }
726
714
  assert(this.activeConnection == null, 'Found non-nil `activeConnection` when trying to setup streaming endpoints, even though streamStatus is reported to be AVAILABLE!');
727
715
  this.activeConnection = connection;
728
716
  this.activeConnection.setMaxListeners(this.activeConnection.getMaxListeners() + 1);
729
- this.activeConnection.on("closed" /* HAPConnectionEvent.CLOSED */, this.activeConnectionClosedListener);
717
+ this.activeConnection.on(HAPConnectionEvent.CLOSED, this.activeConnectionClosedListener);
730
718
  this.sessionIdentifier = sessionIdentifier;
731
- this._updateStreamStatus(1 /* StreamingStatus.IN_USE */);
732
- 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);
719
+ this._updateStreamStatus(StreamingStatus.IN_USE);
720
+ debug('Session: ', sessionIdentifier, '\nControllerAddress: ', controllerAddress, '\nVideoPort: ', targetVideoPort, '\nAudioPort: ', targetAudioPort, '\nVideo Crypto: ', videoCryptoSuite, '\nAudio Crypto: ', audioCryptoSuite);
733
721
  const prepareRequest = {
734
722
  sessionID: sessionIdentifier,
735
723
  sourceAddress: connection.localAddress,
736
724
  targetAddress: controllerAddress,
737
- addressVersion: addressVersion === 1 /* IPAddressVersion.IPV6 */
725
+ addressVersion: addressVersion === IPAddressVersion.IPV6
738
726
  ? 'ipv6'
739
727
  : 'ipv4',
740
728
  video: {
@@ -751,40 +739,70 @@ export class RTPStreamManagement {
751
739
  },
752
740
  };
753
741
  const promises = [];
742
+ // kept in local variables, as the fields are cleared, or belong to the next session, once this session ended
743
+ let videoProxy;
744
+ let audioProxy;
754
745
  if (this.requireProxy) {
755
- prepareRequest.targetAddress = connection.getLocalAddress(addressVersion === 1 /* IPAddressVersion.IPV6 */
756
- ? 'ipv6'
757
- : 'ipv4'); // ip versions must be the same
758
- this.videoProxy = new RTPProxy({
746
+ try {
747
+ prepareRequest.targetAddress = connection.getLocalAddress(addressVersion === IPAddressVersion.IPV6
748
+ ? 'ipv6'
749
+ : 'ipv4'); // ip versions must be the same
750
+ }
751
+ catch (error) {
752
+ // the stream is marked as in use by now: free it and answer, or it stays blocked until the connection closes
753
+ debug(`Could not find the local address for the RTP proxy: ${errorMessage(error)}`);
754
+ this.handleSessionClosed();
755
+ callback(error instanceof Error
756
+ ? error
757
+ : new Error(String(error)));
758
+ return;
759
+ }
760
+ this.videoProxy = videoProxy = new RTPProxy({
759
761
  outgoingAddress: controllerAddress,
760
762
  outgoingPort: targetVideoPort,
761
763
  outgoingSSRC: crypto.randomBytes(4).readUInt32LE(0), // videoSSRC
762
764
  disabled: false,
763
765
  });
764
- promises.push(this.videoProxy.setup().then(() => {
765
- prepareRequest.video.proxy_rtp = this.videoProxy.incomingRTPPort();
766
- prepareRequest.video.proxy_rtcp = this.videoProxy.incomingRTCPPort();
767
- }));
766
+ promises.push(videoProxy.setup());
768
767
  if (!this.disableAudioProxy) {
769
- this.audioProxy = new RTPProxy({
768
+ this.audioProxy = audioProxy = new RTPProxy({
770
769
  outgoingAddress: controllerAddress,
771
770
  outgoingPort: targetAudioPort,
772
771
  outgoingSSRC: crypto.randomBytes(4).readUInt32LE(0), // audioSSRC
773
772
  disabled: this.videoOnly,
774
773
  });
775
- promises.push(this.audioProxy.setup().then(() => {
776
- prepareRequest.audio.proxy_rtp = this.audioProxy.incomingRTPPort();
777
- prepareRequest.audio.proxy_rtcp = this.audioProxy.incomingRTCPPort();
778
- }));
774
+ promises.push(audioProxy.setup());
779
775
  }
780
776
  }
781
777
  Promise.all(promises).then(() => {
778
+ if (this.sessionIdentifier !== sessionIdentifier) {
779
+ // The session ended while the proxy sockets were being bound (e.g. the connection closed), which closed its
780
+ // proxies. The delegate must not prepare a stream nobody waits for.
781
+ debug('Not preparing the stream for session %s which is not the current session anymore', sessionIdentifier);
782
+ callback(HAPStatus.SERVICE_COMMUNICATION_FAILURE);
783
+ return;
784
+ }
785
+ if (videoProxy) {
786
+ prepareRequest.video.proxy_rtp = videoProxy.incomingRTPPort();
787
+ prepareRequest.video.proxy_rtcp = videoProxy.incomingRTCPPort();
788
+ }
789
+ if (audioProxy) {
790
+ prepareRequest.audio.proxy_rtp = audioProxy.incomingRTPPort();
791
+ prepareRequest.audio.proxy_rtcp = audioProxy.incomingRTCPPort();
792
+ }
782
793
  this.delegate.prepareStream(prepareRequest, once((error, response) => {
794
+ if (this.sessionIdentifier !== sessionIdentifier) {
795
+ // The session ended while the delegate was preparing it (e.g. the connection closed), and another one
796
+ // may have started since. This answer must not touch that one.
797
+ debug('Ignoring the PrepareStream response for session %s which is not the current session anymore', sessionIdentifier);
798
+ callback(HAPStatus.SERVICE_COMMUNICATION_FAILURE);
799
+ return;
800
+ }
783
801
  if (error || !response) {
784
802
  debug(`PrepareStream request encountered an error: ${error ? error.message : undefined}`);
785
- this.setupEndpointsResponse = tlv.encode(1 /* SetupEndpointsResponseTypes.SESSION_ID */, uuid.write(sessionIdentifier), 2 /* SetupEndpointsResponseTypes.STATUS */, 2 /* SetupEndpointsStatus.ERROR */).toString('base64');
786
- this.handleSessionClosed();
787
- callback(error);
803
+ this.handleSessionClosed(); // resets the SetupEndpoints answer to a plain error
804
+ // an answer with neither an error nor a response must not tell the controller that the setup worked
805
+ callback(error ?? HAPStatus.SERVICE_COMMUNICATION_FAILURE);
788
806
  }
789
807
  else {
790
808
  try {
@@ -792,48 +810,52 @@ export class RTPStreamManagement {
792
810
  }
793
811
  catch (error) {
794
812
  // the delegate usually calls back asynchronously, so nothing up the stack would catch this
795
- debug(`Failed to build the SetupEndpoints response from the PrepareStreamResponse: ${error.message}`);
796
- this.setupEndpointsResponse = tlv.encode(1 /* SetupEndpointsResponseTypes.SESSION_ID */, uuid.write(sessionIdentifier), 2 /* SetupEndpointsResponseTypes.STATUS */, 2 /* SetupEndpointsStatus.ERROR */).toString('base64');
797
- this.handleSessionClosed();
798
- callback(error);
813
+ debug(`Failed to build the SetupEndpoints response from the PrepareStreamResponse: ${errorMessage(error)}`);
814
+ this.handleSessionClosed(); // resets the SetupEndpoints answer to a plain error
815
+ callback(error instanceof Error
816
+ ? error
817
+ : new Error(String(error)));
799
818
  }
800
819
  }
801
820
  }));
802
821
  }).catch((error) => {
803
822
  debug(`RTP proxy setup failed: ${error.message}`);
804
- this.setupEndpointsResponse = tlv.encode(1 /* SetupEndpointsResponseTypes.SESSION_ID */, uuid.write(sessionIdentifier), 2 /* SetupEndpointsResponseTypes.STATUS */, 2 /* SetupEndpointsStatus.ERROR */).toString('base64');
805
- this.handleSessionClosed();
823
+ if (this.sessionIdentifier !== sessionIdentifier) {
824
+ callback(HAPStatus.SERVICE_COMMUNICATION_FAILURE); // as above: not the current session anymore
825
+ return;
826
+ }
827
+ this.handleSessionClosed(); // resets the SetupEndpoints answer to a plain error
806
828
  callback(error);
807
829
  });
808
830
  }
809
831
  parseSetupEndpointsRequest(value) {
810
832
  const data = Buffer.from(value, 'base64');
811
833
  const objects = tlv.decode(data);
812
- const sessionIdentifier = uuid.unparse(objects[1 /* SetupEndpointsTypes.SESSION_ID */]);
834
+ const sessionIdentifier = uuid.unparse(objects[SetupEndpointsTypes.SESSION_ID]);
813
835
  // Address
814
- const targetAddressPayload = objects[3 /* SetupEndpointsTypes.CONTROLLER_ADDRESS */];
836
+ const targetAddressPayload = objects[SetupEndpointsTypes.CONTROLLER_ADDRESS];
815
837
  const processedAddressInfo = tlv.decode(targetAddressPayload);
816
- const addressVersion = processedAddressInfo[1 /* AddressTypes.ADDRESS_VERSION */].readUInt8(0);
817
- const controllerAddress = processedAddressInfo[2 /* AddressTypes.ADDRESS */].toString('utf8');
818
- const targetVideoPort = processedAddressInfo[3 /* AddressTypes.VIDEO_RTP_PORT */].readUInt16LE(0);
819
- const targetAudioPort = processedAddressInfo[4 /* AddressTypes.AUDIO_RTP_PORT */].readUInt16LE(0);
838
+ const addressVersion = processedAddressInfo[AddressTypes.ADDRESS_VERSION].readUInt8(0);
839
+ const controllerAddress = processedAddressInfo[AddressTypes.ADDRESS].toString('utf8');
840
+ const targetVideoPort = processedAddressInfo[AddressTypes.VIDEO_RTP_PORT].readUInt16LE(0);
841
+ const targetAudioPort = processedAddressInfo[AddressTypes.AUDIO_RTP_PORT].readUInt16LE(0);
820
842
  // Video SRTP Params
821
- const videoSRTPPayload = objects[4 /* SetupEndpointsTypes.VIDEO_SRTP_PARAMETERS */];
843
+ const videoSRTPPayload = objects[SetupEndpointsTypes.VIDEO_SRTP_PARAMETERS];
822
844
  const processedVideoInfo = tlv.decode(videoSRTPPayload);
823
- const videoCryptoSuite = processedVideoInfo[1 /* SRTPParametersTypes.SRTP_CRYPTO_SUITE */].readUInt8(0);
824
- const videoMasterKey = processedVideoInfo[2 /* SRTPParametersTypes.MASTER_KEY */];
825
- const videoMasterSalt = processedVideoInfo[3 /* SRTPParametersTypes.MASTER_SALT */];
845
+ const videoCryptoSuite = processedVideoInfo[SRTPParametersTypes.SRTP_CRYPTO_SUITE].readUInt8(0);
846
+ const videoMasterKey = processedVideoInfo[SRTPParametersTypes.MASTER_KEY];
847
+ const videoMasterSalt = processedVideoInfo[SRTPParametersTypes.MASTER_SALT];
826
848
  // Audio SRTP Params
827
- const audioSRTPPayload = objects[5 /* SetupEndpointsTypes.AUDIO_SRTP_PARAMETERS */];
849
+ const audioSRTPPayload = objects[SetupEndpointsTypes.AUDIO_SRTP_PARAMETERS];
828
850
  const processedAudioInfo = tlv.decode(audioSRTPPayload);
829
- const audioCryptoSuite = processedAudioInfo[1 /* SRTPParametersTypes.SRTP_CRYPTO_SUITE */].readUInt8(0);
830
- const audioMasterKey = processedAudioInfo[2 /* SRTPParametersTypes.MASTER_KEY */];
831
- const audioMasterSalt = processedAudioInfo[3 /* SRTPParametersTypes.MASTER_SALT */];
851
+ const audioCryptoSuite = processedAudioInfo[SRTPParametersTypes.SRTP_CRYPTO_SUITE].readUInt8(0);
852
+ const audioMasterKey = processedAudioInfo[SRTPParametersTypes.MASTER_KEY];
853
+ const audioMasterSalt = processedAudioInfo[SRTPParametersTypes.MASTER_SALT];
832
854
  // if the suite is NONE, keys and salts are zero-length
833
- if (videoCryptoSuite !== 2 /* SRTPCryptoSuites.NONE */ && (!videoMasterKey || !videoMasterSalt)) {
855
+ if (videoCryptoSuite !== SRTPCryptoSuites.NONE && (!videoMasterKey || !videoMasterSalt)) {
834
856
  throw new Error('Video SRTP master key or salt is missing');
835
857
  }
836
- if (audioCryptoSuite !== 2 /* SRTPCryptoSuites.NONE */ && (!audioMasterKey || !audioMasterSalt)) {
858
+ if (audioCryptoSuite !== SRTPCryptoSuites.NONE && (!audioMasterKey || !audioMasterSalt)) {
837
859
  throw new Error('Audio SRTP master key or salt is missing');
838
860
  }
839
861
  return {
@@ -890,11 +912,11 @@ export class RTPStreamManagement {
890
912
  }
891
913
  videoPort = videoInfo.port;
892
914
  audioPort = audioInfo.port;
893
- if (request.video.srtpCryptoSuite !== 2 /* SRTPCryptoSuites.NONE */
915
+ if (request.video.srtpCryptoSuite !== SRTPCryptoSuites.NONE
894
916
  && (videoInfo.srtp_key === undefined || videoInfo.srtp_salt === undefined)) {
895
917
  throw new Error('SRTP was selected for the prepared video stream, but no \'srtp_key\' or \'srtp_salt\' was specified!');
896
918
  }
897
- if (request.audio.srtpCryptoSuite !== 2 /* SRTPCryptoSuites.NONE */
919
+ if (request.audio.srtpCryptoSuite !== SRTPCryptoSuites.NONE
898
920
  && (audioInfo.srtp_key === undefined || audioInfo.srtp_salt === undefined)) {
899
921
  throw new Error('SRTP was selected for the prepared audio stream, but no \'srtp_key\' or \'srtp_salt\' was specified!');
900
922
  }
@@ -910,10 +932,10 @@ export class RTPStreamManagement {
910
932
  else {
911
933
  const videoInfo = response.video;
912
934
  address = connection.getLocalAddress(request.addressVersion);
913
- videoCryptoSuite = 2 /* SRTPCryptoSuites.NONE */;
935
+ videoCryptoSuite = SRTPCryptoSuites.NONE;
914
936
  videoSRTPKey = Buffer.alloc(0);
915
937
  videoSRTPSalt = Buffer.alloc(0);
916
- audioCryptoSuite = 2 /* SRTPCryptoSuites.NONE */;
938
+ audioCryptoSuite = SRTPCryptoSuites.NONE;
917
939
  audioSRTPKey = Buffer.alloc(0);
918
940
  audioSRTPSalt = Buffer.alloc(0);
919
941
  this.videoProxy.setIncomingPayloadType(videoInfo.proxy_pt);
@@ -922,7 +944,12 @@ export class RTPStreamManagement {
922
944
  this.videoProxy.setServerRTCPPort(videoInfo.proxy_server_rtcp);
923
945
  videoPort = this.videoProxy.outgoingLocalPort();
924
946
  videoSSRC = this.videoProxy.outgoingSSRC;
925
- if (!this.disableAudioProxy) {
947
+ if (!response.audio) {
948
+ // a camera without audio (videoOnly) has no audio source to proxy: answer with the defaults, as without a proxy
949
+ audioPort = audio.port;
950
+ audioSSRC = audio.ssrc;
951
+ }
952
+ else if (!this.disableAudioProxy) {
926
953
  const audioInfo = response.audio;
927
954
  this.audioProxy.setIncomingPayloadType(audioInfo.proxy_pt);
928
955
  this.audioProxy.setServerAddress(audioInfo.proxy_server_address);
@@ -938,23 +965,24 @@ export class RTPStreamManagement {
938
965
  }
939
966
  }
940
967
  this.ipVersion = addressVersion; // we need to save this in order to calculate some default mtu values later
941
- const accessoryAddress = tlv.encode(1 /* AddressTypes.ADDRESS_VERSION */, addressVersion === 'ipv4'
942
- ? 0 /* IPAddressVersion.IPV4 */
943
- : 1 /* IPAddressVersion.IPV6 */, 2 /* AddressTypes.ADDRESS */, address, 3 /* AddressTypes.VIDEO_RTP_PORT */, tlv.writeUInt16(videoPort), 4 /* AddressTypes.AUDIO_RTP_PORT */, tlv.writeUInt16(audioPort));
944
- const videoSRTPParameters = tlv.encode(1 /* SRTPParametersTypes.SRTP_CRYPTO_SUITE */, videoCryptoSuite, 2 /* SRTPParametersTypes.MASTER_KEY */, videoSRTPKey, 3 /* SRTPParametersTypes.MASTER_SALT */, videoSRTPSalt);
945
- const audioSRTPParameters = tlv.encode(1 /* SRTPParametersTypes.SRTP_CRYPTO_SUITE */, audioCryptoSuite, 2 /* SRTPParametersTypes.MASTER_KEY */, audioSRTPKey, 3 /* SRTPParametersTypes.MASTER_SALT */, audioSRTPSalt);
946
- 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');
968
+ const accessoryAddress = tlv.encode(AddressTypes.ADDRESS_VERSION, addressVersion === 'ipv4'
969
+ ? IPAddressVersion.IPV4
970
+ : IPAddressVersion.IPV6, AddressTypes.ADDRESS, address, AddressTypes.VIDEO_RTP_PORT, tlv.writeUInt16(videoPort), AddressTypes.AUDIO_RTP_PORT, tlv.writeUInt16(audioPort));
971
+ const videoSRTPParameters = tlv.encode(SRTPParametersTypes.SRTP_CRYPTO_SUITE, videoCryptoSuite, SRTPParametersTypes.MASTER_KEY, videoSRTPKey, SRTPParametersTypes.MASTER_SALT, videoSRTPSalt);
972
+ const audioSRTPParameters = tlv.encode(SRTPParametersTypes.SRTP_CRYPTO_SUITE, audioCryptoSuite, SRTPParametersTypes.MASTER_KEY, audioSRTPKey, SRTPParametersTypes.MASTER_SALT, audioSRTPSalt);
973
+ this.busySetupEndpointsResponses.delete(connection); // it reads the response of its session from now on
974
+ this.setupEndpointsResponse = tlv.encode(SetupEndpointsResponseTypes.SESSION_ID, uuid.write(identifier), SetupEndpointsResponseTypes.STATUS, SetupEndpointsStatus.SUCCESS, SetupEndpointsResponseTypes.ACCESSORY_ADDRESS, accessoryAddress, SetupEndpointsResponseTypes.VIDEO_SRTP_PARAMETERS, videoSRTPParameters, SetupEndpointsResponseTypes.AUDIO_SRTP_PARAMETERS, audioSRTPParameters, SetupEndpointsResponseTypes.VIDEO_SSRC, tlv.writeUInt32(videoSSRC), SetupEndpointsResponseTypes.AUDIO_SSRC, tlv.writeUInt32(audioSSRC)).toString('base64');
947
975
  callback();
948
976
  }
949
977
  _updateStreamStatus(status) {
950
978
  this.streamStatus = status;
951
- this.service.updateCharacteristic(Characteristic.StreamingStatus, tlv.encode(1 /* StreamingStatusTypes.STATUS */, this.streamStatus).toString('base64'));
979
+ this.service.updateCharacteristic(Characteristic.StreamingStatus, tlv.encode(StreamingStatusTypes.STATUS, this.streamStatus).toString('base64'));
952
980
  }
953
981
  static _supportedRTPConfiguration(supportedCryptoSuites) {
954
- if (supportedCryptoSuites.length === 1 && supportedCryptoSuites[0] === 2 /* SRTPCryptoSuites.NONE */) {
955
- debug('Client claims it doesn\'t support SRTP. The stream may stops working with future iOS releases.');
982
+ if (supportedCryptoSuites.length === 1 && supportedCryptoSuites[0] === SRTPCryptoSuites.NONE) {
983
+ debug('Client claims it doesn\'t support SRTP. The stream may stop working with future iOS releases.');
956
984
  }
957
- return tlv.encode(2 /* SupportedRTPConfigurationTypes.SRTP_CRYPTO_SUITE */, supportedCryptoSuites).toString('base64');
985
+ return tlv.encode(SupportedRTPConfigurationTypes.SRTP_CRYPTO_SUITE, supportedCryptoSuites).toString('base64');
958
986
  }
959
987
  static _supportedVideoStreamConfiguration(videoOptions) {
960
988
  if (!videoOptions.codec) {
@@ -963,14 +991,14 @@ export class RTPStreamManagement {
963
991
  if (!videoOptions.resolutions) {
964
992
  throw new Error('Video resolutions cannot be undefined');
965
993
  }
966
- 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 */);
994
+ let codecParameters = tlv.encode(VideoCodecParametersTypes.PROFILE_ID, videoOptions.codec.profiles, VideoCodecParametersTypes.LEVEL, videoOptions.codec.levels, VideoCodecParametersTypes.PACKETIZATION_MODE, VideoCodecPacketizationMode.NON_INTERLEAVED);
967
995
  if (videoOptions.cvoId != null) {
968
996
  codecParameters = Buffer.concat([
969
997
  codecParameters,
970
- tlv.encode(4 /* VideoCodecParametersTypes.CVO_ENABLED */, 1 /* VideoCodecCVO.SUPPORTED */, 5 /* VideoCodecParametersTypes.CVO_ID */, videoOptions.cvoId),
998
+ tlv.encode(VideoCodecParametersTypes.CVO_ENABLED, VideoCodecCVO.SUPPORTED, VideoCodecParametersTypes.CVO_ID, videoOptions.cvoId),
971
999
  ]);
972
1000
  }
973
- const videoStreamConfiguration = tlv.encode(1 /* VideoCodecConfigurationTypes.CODEC_TYPE */, 0 /* VideoCodecType.H264 */, 2 /* VideoCodecConfigurationTypes.CODEC_PARAMETERS */, codecParameters, 3 /* VideoCodecConfigurationTypes.ATTRIBUTES */, videoOptions.resolutions.map((resolution) => {
1001
+ const videoStreamConfiguration = tlv.encode(VideoCodecConfigurationTypes.CODEC_TYPE, VideoCodecType.H264, VideoCodecConfigurationTypes.CODEC_PARAMETERS, codecParameters, VideoCodecConfigurationTypes.ATTRIBUTES, videoOptions.resolutions.map((resolution) => {
974
1002
  if (resolution.length !== 3) {
975
1003
  throw new Error('Unexpected video resolution');
976
1004
  }
@@ -980,9 +1008,9 @@ export class RTPStreamManagement {
980
1008
  width.writeUInt16LE(resolution[0], 0);
981
1009
  height.writeUInt16LE(resolution[1], 0);
982
1010
  frameRate.writeUInt8(resolution[2], 0);
983
- return tlv.encode(1 /* VideoAttributesTypes.IMAGE_WIDTH */, width, 2 /* VideoAttributesTypes.IMAGE_HEIGHT */, height, 3 /* VideoAttributesTypes.FRAME_RATE */, frameRate);
1011
+ return tlv.encode(VideoAttributesTypes.IMAGE_WIDTH, width, VideoAttributesTypes.IMAGE_HEIGHT, height, VideoAttributesTypes.FRAME_RATE, frameRate);
984
1012
  }));
985
- return tlv.encode(1 /* SupportedVideoStreamConfigurationTypes.VIDEO_CODEC_CONFIGURATION */, videoStreamConfiguration).toString('base64');
1013
+ return tlv.encode(SupportedVideoStreamConfigurationTypes.VIDEO_CODEC_CONFIGURATION, videoStreamConfiguration).toString('base64');
986
1014
  }
987
1015
  checkForLegacyAudioCodecRepresentation(codecs) {
988
1016
  const codecMap = {};
@@ -1007,39 +1035,41 @@ export class RTPStreamManagement {
1007
1035
  // Only AAC-ELD and OPUS are accepted by iOS currently, and we need to give it something it will accept
1008
1036
  // for it to start the video stream.
1009
1037
  const comfortNoise = audioOptions && !!audioOptions.comfort_noise;
1010
- const supportedCodecs = (audioOptions && audioOptions.codecs) || [];
1038
+ // Copies of the list and of its entries: both are changed below, and the options belong to the plugin.
1039
+ // They are also shared by all streams of a camera, so a codec added for one stream would be real for the next.
1040
+ const supportedCodecs = (audioOptions?.codecs ?? []).map(codec => ({ ...codec }));
1011
1041
  this.checkForLegacyAudioCodecRepresentation(supportedCodecs);
1012
1042
  if (supportedCodecs.length === 0) { // Fake a Codec if we haven't got anything
1013
1043
  debug('Client doesn\'t support any audio codec that HomeKit supports.');
1014
1044
  this.videoOnly = true;
1015
1045
  supportedCodecs.push({
1016
- type: "OPUS" /* AudioStreamingCodecType.OPUS */, // Opus @16K required by Apple Watch AFAIK
1017
- samplerate: [16 /* AudioStreamingSamplerate.KHZ_16 */, 24 /* AudioStreamingSamplerate.KHZ_24 */], // 16 and 24 must be supported
1046
+ type: AudioStreamingCodecType.OPUS, // Opus @16K required by Apple Watch AFAIK
1047
+ samplerate: [AudioStreamingSamplerate.KHZ_16, AudioStreamingSamplerate.KHZ_24], // 16 and 24 must be supported
1018
1048
  });
1019
1049
  }
1020
1050
  const codecConfigurations = supportedCodecs.map((codec) => {
1021
1051
  let type;
1022
1052
  switch (codec.type) {
1023
- case "OPUS" /* AudioStreamingCodecType.OPUS */:
1024
- type = 3 /* AudioCodecTypes.OPUS */;
1053
+ case AudioStreamingCodecType.OPUS:
1054
+ type = AudioCodecTypes.OPUS;
1025
1055
  break;
1026
- case "AAC-eld" /* AudioStreamingCodecType.AAC_ELD */:
1027
- type = 2 /* AudioCodecTypes.AAC_ELD */;
1056
+ case AudioStreamingCodecType.AAC_ELD:
1057
+ type = AudioCodecTypes.AAC_ELD;
1028
1058
  break;
1029
- case "PCMA" /* AudioStreamingCodecType.PCMA */:
1030
- type = 1 /* AudioCodecTypes.PCMA */;
1059
+ case AudioStreamingCodecType.PCMA:
1060
+ type = AudioCodecTypes.PCMA;
1031
1061
  break;
1032
- case "PCMU" /* AudioStreamingCodecType.PCMU */:
1033
- type = 0 /* AudioCodecTypes.PCMU */;
1062
+ case AudioStreamingCodecType.PCMU:
1063
+ type = AudioCodecTypes.PCMU;
1034
1064
  break;
1035
- case "mSBC" /* AudioStreamingCodecType.MSBC */:
1036
- type = 4 /* AudioCodecTypes.MSBC */;
1065
+ case AudioStreamingCodecType.MSBC:
1066
+ type = AudioCodecTypes.MSBC;
1037
1067
  break;
1038
- case "AMR" /* AudioStreamingCodecType.AMR */:
1039
- type = 5 /* AudioCodecTypes.AMR */;
1068
+ case AudioStreamingCodecType.AMR:
1069
+ type = AudioCodecTypes.AMR;
1040
1070
  break;
1041
- case "AMR-WB" /* AudioStreamingCodecType.AMR_WB */:
1042
- type = 6 /* AudioCodecTypes.AMR_WB */;
1071
+ case AudioStreamingCodecType.AMR_WB:
1072
+ type = AudioCodecTypes.AMR_WB;
1043
1073
  break;
1044
1074
  default:
1045
1075
  throw new Error(`Unsupported codec: ${codec.type}`);
@@ -1049,14 +1079,14 @@ export class RTPStreamManagement {
1049
1079
  : codec.samplerate).map((rate) => {
1050
1080
  let samplerate;
1051
1081
  switch (rate) {
1052
- case 8 /* AudioStreamingSamplerate.KHZ_8 */:
1053
- samplerate = 0 /* AudioSamplerate.KHZ_8 */;
1082
+ case AudioStreamingSamplerate.KHZ_8:
1083
+ samplerate = AudioSamplerate.KHZ_8;
1054
1084
  break;
1055
- case 16 /* AudioStreamingSamplerate.KHZ_16 */:
1056
- samplerate = 1 /* AudioSamplerate.KHZ_16 */;
1085
+ case AudioStreamingSamplerate.KHZ_16:
1086
+ samplerate = AudioSamplerate.KHZ_16;
1057
1087
  break;
1058
- case 24 /* AudioStreamingSamplerate.KHZ_24 */:
1059
- samplerate = 2 /* AudioSamplerate.KHZ_24 */;
1088
+ case AudioStreamingSamplerate.KHZ_24:
1089
+ samplerate = AudioSamplerate.KHZ_24;
1060
1090
  break;
1061
1091
  default:
1062
1092
  console.log('Unsupported sample rate: ', codec.samplerate);
@@ -1067,17 +1097,18 @@ export class RTPStreamManagement {
1067
1097
  if (providedSamplerates.length === 0) {
1068
1098
  throw new Error('Audio samplerate cannot be empty!');
1069
1099
  }
1070
- 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);
1071
- return tlv.encode(1 /* AudioCodecConfigurationTypes.CODEC_TYPE */, type, 2 /* AudioCodecConfigurationTypes.CODEC_PARAMETERS */, audioParameters);
1100
+ const audioParameters = tlv.encode(AudioCodecParametersTypes.CHANNEL, Math.max(1, codec.audioChannels || 1), AudioCodecParametersTypes.BIT_RATE, codec.bitrate || AudioBitrate.VARIABLE, AudioCodecParametersTypes.SAMPLE_RATE, providedSamplerates);
1101
+ return tlv.encode(AudioCodecConfigurationTypes.CODEC_TYPE, type, AudioCodecConfigurationTypes.CODEC_PARAMETERS, audioParameters);
1072
1102
  });
1073
- return tlv.encode(1 /* SupportedAudioStreamConfigurationTypes.AUDIO_CODEC_CONFIGURATION */, codecConfigurations, 2 /* SupportedAudioStreamConfigurationTypes.COMFORT_NOISE_SUPPORT */, comfortNoise ? 1 : 0).toString('base64');
1103
+ return tlv.encode(SupportedAudioStreamConfigurationTypes.AUDIO_CODEC_CONFIGURATION, codecConfigurations, SupportedAudioStreamConfigurationTypes.COMFORT_NOISE_SUPPORT, comfortNoise ? 1 : 0).toString('base64');
1074
1104
  }
1075
1105
  resetSetupEndpointsResponse() {
1076
- this.setupEndpointsResponse = tlv.encode(2 /* SetupEndpointsResponseTypes.STATUS */, 2 /* SetupEndpointsStatus.ERROR */).toString('base64');
1106
+ this.busySetupEndpointsResponses = new WeakMap(); // every connection reads the default response again
1107
+ this.setupEndpointsResponse = tlv.encode(SetupEndpointsResponseTypes.STATUS, SetupEndpointsStatus.ERROR).toString('base64');
1077
1108
  this.service.updateCharacteristic(Characteristic.SetupEndpoints, this.setupEndpointsResponse);
1078
1109
  }
1079
1110
  resetSelectedStreamConfiguration() {
1080
- this.selectedConfiguration = tlv.encode(1 /* SelectedRTPStreamConfigurationTypes.SESSION_CONTROL */, tlv.encode(2 /* SessionControlTypes.COMMAND */, SessionControlCommand.SUSPEND_SESSION)).toString('base64');
1111
+ this.selectedConfiguration = tlv.encode(SelectedRTPStreamConfigurationTypes.SESSION_CONTROL, tlv.encode(SessionControlTypes.COMMAND, SessionControlCommand.SUSPEND_SESSION)).toString('base64');
1081
1112
  this.service.updateCharacteristic(Characteristic.SelectedRTPStreamConfiguration, this.selectedConfiguration);
1082
1113
  }
1083
1114
  /**