@homebridge/hap-nodejs 2.0.0-beta.3

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