matterbridge 3.4.3-dev-20251209-e6cb85f → 3.4.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 (324) hide show
  1. package/README.md +2 -3
  2. package/dist/broadcastServer.d.ts +144 -0
  3. package/dist/broadcastServer.d.ts.map +1 -0
  4. package/dist/broadcastServer.js +119 -0
  5. package/dist/broadcastServer.js.map +1 -0
  6. package/dist/broadcastServerTypes.d.ts +841 -0
  7. package/dist/broadcastServerTypes.d.ts.map +1 -0
  8. package/dist/broadcastServerTypes.js +24 -0
  9. package/dist/broadcastServerTypes.js.map +1 -0
  10. package/dist/cli.d.ts +30 -0
  11. package/dist/cli.d.ts.map +1 -0
  12. package/dist/cli.js +97 -1
  13. package/dist/cli.js.map +1 -0
  14. package/dist/cliEmitter.d.ts +50 -0
  15. package/dist/cliEmitter.d.ts.map +1 -0
  16. package/dist/cliEmitter.js +37 -0
  17. package/dist/cliEmitter.js.map +1 -0
  18. package/dist/cliHistory.d.ts +48 -0
  19. package/dist/cliHistory.d.ts.map +1 -0
  20. package/dist/cliHistory.js +38 -0
  21. package/dist/cliHistory.js.map +1 -0
  22. package/dist/clusters/export.d.ts +2 -0
  23. package/dist/clusters/export.d.ts.map +1 -0
  24. package/dist/clusters/export.js +2 -0
  25. package/dist/clusters/export.js.map +1 -0
  26. package/dist/deviceManager.d.ts +135 -0
  27. package/dist/deviceManager.d.ts.map +1 -0
  28. package/dist/deviceManager.js +113 -1
  29. package/dist/deviceManager.js.map +1 -0
  30. package/dist/devices/airConditioner.d.ts +98 -0
  31. package/dist/devices/airConditioner.d.ts.map +1 -0
  32. package/dist/devices/airConditioner.js +57 -0
  33. package/dist/devices/airConditioner.js.map +1 -0
  34. package/dist/devices/batteryStorage.d.ts +48 -0
  35. package/dist/devices/batteryStorage.d.ts.map +1 -0
  36. package/dist/devices/batteryStorage.js +48 -1
  37. package/dist/devices/batteryStorage.js.map +1 -0
  38. package/dist/devices/cooktop.d.ts +61 -0
  39. package/dist/devices/cooktop.d.ts.map +1 -0
  40. package/dist/devices/cooktop.js +56 -0
  41. package/dist/devices/cooktop.js.map +1 -0
  42. package/dist/devices/dishwasher.d.ts +71 -0
  43. package/dist/devices/dishwasher.d.ts.map +1 -0
  44. package/dist/devices/dishwasher.js +57 -0
  45. package/dist/devices/dishwasher.js.map +1 -0
  46. package/dist/devices/evse.d.ts +76 -0
  47. package/dist/devices/evse.d.ts.map +1 -0
  48. package/dist/devices/evse.js +74 -10
  49. package/dist/devices/evse.js.map +1 -0
  50. package/dist/devices/export.d.ts +17 -0
  51. package/dist/devices/export.d.ts.map +1 -0
  52. package/dist/devices/export.js +5 -0
  53. package/dist/devices/export.js.map +1 -0
  54. package/dist/devices/extractorHood.d.ts +46 -0
  55. package/dist/devices/extractorHood.d.ts.map +1 -0
  56. package/dist/devices/extractorHood.js +43 -0
  57. package/dist/devices/extractorHood.js.map +1 -0
  58. package/dist/devices/heatPump.d.ts +47 -0
  59. package/dist/devices/heatPump.d.ts.map +1 -0
  60. package/dist/devices/heatPump.js +50 -2
  61. package/dist/devices/heatPump.js.map +1 -0
  62. package/dist/devices/laundryDryer.d.ts +67 -0
  63. package/dist/devices/laundryDryer.d.ts.map +1 -0
  64. package/dist/devices/laundryDryer.js +62 -3
  65. package/dist/devices/laundryDryer.js.map +1 -0
  66. package/dist/devices/laundryWasher.d.ts +81 -0
  67. package/dist/devices/laundryWasher.d.ts.map +1 -0
  68. package/dist/devices/laundryWasher.js +70 -4
  69. package/dist/devices/laundryWasher.js.map +1 -0
  70. package/dist/devices/microwaveOven.d.ts +168 -0
  71. package/dist/devices/microwaveOven.d.ts.map +1 -0
  72. package/dist/devices/microwaveOven.js +88 -5
  73. package/dist/devices/microwaveOven.js.map +1 -0
  74. package/dist/devices/oven.d.ts +105 -0
  75. package/dist/devices/oven.d.ts.map +1 -0
  76. package/dist/devices/oven.js +85 -0
  77. package/dist/devices/oven.js.map +1 -0
  78. package/dist/devices/refrigerator.d.ts +118 -0
  79. package/dist/devices/refrigerator.d.ts.map +1 -0
  80. package/dist/devices/refrigerator.js +102 -0
  81. package/dist/devices/refrigerator.js.map +1 -0
  82. package/dist/devices/roboticVacuumCleaner.d.ts +112 -0
  83. package/dist/devices/roboticVacuumCleaner.d.ts.map +1 -0
  84. package/dist/devices/roboticVacuumCleaner.js +100 -9
  85. package/dist/devices/roboticVacuumCleaner.js.map +1 -0
  86. package/dist/devices/solarPower.d.ts +40 -0
  87. package/dist/devices/solarPower.d.ts.map +1 -0
  88. package/dist/devices/solarPower.js +38 -0
  89. package/dist/devices/solarPower.js.map +1 -0
  90. package/dist/devices/speaker.d.ts +87 -0
  91. package/dist/devices/speaker.d.ts.map +1 -0
  92. package/dist/devices/speaker.js +84 -0
  93. package/dist/devices/speaker.js.map +1 -0
  94. package/dist/devices/temperatureControl.d.ts +166 -0
  95. package/dist/devices/temperatureControl.d.ts.map +1 -0
  96. package/dist/devices/temperatureControl.js +24 -3
  97. package/dist/devices/temperatureControl.js.map +1 -0
  98. package/dist/devices/waterHeater.d.ts +111 -0
  99. package/dist/devices/waterHeater.d.ts.map +1 -0
  100. package/dist/devices/waterHeater.js +82 -2
  101. package/dist/devices/waterHeater.js.map +1 -0
  102. package/dist/dgram/coap.d.ts +205 -0
  103. package/dist/dgram/coap.d.ts.map +1 -0
  104. package/dist/dgram/coap.js +126 -13
  105. package/dist/dgram/coap.js.map +1 -0
  106. package/dist/dgram/dgram.d.ts +141 -0
  107. package/dist/dgram/dgram.d.ts.map +1 -0
  108. package/dist/dgram/dgram.js +114 -2
  109. package/dist/dgram/dgram.js.map +1 -0
  110. package/dist/dgram/mb_coap.d.ts +24 -0
  111. package/dist/dgram/mb_coap.d.ts.map +1 -0
  112. package/dist/dgram/mb_coap.js +41 -3
  113. package/dist/dgram/mb_coap.js.map +1 -0
  114. package/dist/dgram/mb_mdns.d.ts +24 -0
  115. package/dist/dgram/mb_mdns.d.ts.map +1 -0
  116. package/dist/dgram/mb_mdns.js +80 -15
  117. package/dist/dgram/mb_mdns.js.map +1 -0
  118. package/dist/dgram/mdns.d.ts +290 -0
  119. package/dist/dgram/mdns.d.ts.map +1 -0
  120. package/dist/dgram/mdns.js +299 -137
  121. package/dist/dgram/mdns.js.map +1 -0
  122. package/dist/dgram/multicast.d.ts +67 -0
  123. package/dist/dgram/multicast.d.ts.map +1 -0
  124. package/dist/dgram/multicast.js +62 -1
  125. package/dist/dgram/multicast.js.map +1 -0
  126. package/dist/dgram/unicast.d.ts +56 -0
  127. package/dist/dgram/unicast.d.ts.map +1 -0
  128. package/dist/dgram/unicast.js +54 -0
  129. package/dist/dgram/unicast.js.map +1 -0
  130. package/dist/frontend.d.ts +238 -0
  131. package/dist/frontend.d.ts.map +1 -0
  132. package/dist/frontend.js +455 -35
  133. package/dist/frontend.js.map +1 -0
  134. package/dist/frontendTypes.d.ts +529 -0
  135. package/dist/frontendTypes.d.ts.map +1 -0
  136. package/dist/frontendTypes.js +45 -0
  137. package/dist/frontendTypes.js.map +1 -0
  138. package/dist/helpers.d.ts +48 -0
  139. package/dist/helpers.d.ts.map +1 -0
  140. package/dist/helpers.js +53 -0
  141. package/dist/helpers.js.map +1 -0
  142. package/dist/index.d.ts +34 -0
  143. package/dist/index.d.ts.map +1 -0
  144. package/dist/index.js +25 -0
  145. package/dist/index.js.map +1 -0
  146. package/dist/jestutils/export.d.ts +2 -0
  147. package/dist/jestutils/export.d.ts.map +1 -0
  148. package/dist/jestutils/export.js +1 -0
  149. package/dist/jestutils/export.js.map +1 -0
  150. package/dist/jestutils/jestHelpers.d.ts +345 -0
  151. package/dist/jestutils/jestHelpers.d.ts.map +1 -0
  152. package/dist/jestutils/jestHelpers.js +371 -14
  153. package/dist/jestutils/jestHelpers.js.map +1 -0
  154. package/dist/logger/export.d.ts +2 -0
  155. package/dist/logger/export.d.ts.map +1 -0
  156. package/dist/logger/export.js +1 -0
  157. package/dist/logger/export.js.map +1 -0
  158. package/dist/matter/behaviors.d.ts +2 -0
  159. package/dist/matter/behaviors.d.ts.map +1 -0
  160. package/dist/matter/behaviors.js +2 -0
  161. package/dist/matter/behaviors.js.map +1 -0
  162. package/dist/matter/clusters.d.ts +2 -0
  163. package/dist/matter/clusters.d.ts.map +1 -0
  164. package/dist/matter/clusters.js +2 -0
  165. package/dist/matter/clusters.js.map +1 -0
  166. package/dist/matter/devices.d.ts +2 -0
  167. package/dist/matter/devices.d.ts.map +1 -0
  168. package/dist/matter/devices.js +2 -0
  169. package/dist/matter/devices.js.map +1 -0
  170. package/dist/matter/endpoints.d.ts +2 -0
  171. package/dist/matter/endpoints.d.ts.map +1 -0
  172. package/dist/matter/endpoints.js +2 -0
  173. package/dist/matter/endpoints.js.map +1 -0
  174. package/dist/matter/export.d.ts +5 -0
  175. package/dist/matter/export.d.ts.map +1 -0
  176. package/dist/matter/export.js +3 -0
  177. package/dist/matter/export.js.map +1 -0
  178. package/dist/matter/types.d.ts +3 -0
  179. package/dist/matter/types.d.ts.map +1 -0
  180. package/dist/matter/types.js +3 -0
  181. package/dist/matter/types.js.map +1 -0
  182. package/dist/matterNode.d.ts +342 -0
  183. package/dist/matterNode.d.ts.map +1 -0
  184. package/dist/matterNode.js +369 -8
  185. package/dist/matterNode.js.map +1 -0
  186. package/dist/matterbridge.d.ts +492 -0
  187. package/dist/matterbridge.d.ts.map +1 -0
  188. package/dist/matterbridge.js +811 -46
  189. package/dist/matterbridge.js.map +1 -0
  190. package/dist/matterbridgeAccessoryPlatform.d.ts +41 -0
  191. package/dist/matterbridgeAccessoryPlatform.d.ts.map +1 -0
  192. package/dist/matterbridgeAccessoryPlatform.js +38 -0
  193. package/dist/matterbridgeAccessoryPlatform.js.map +1 -0
  194. package/dist/matterbridgeBehaviors.d.ts +2404 -0
  195. package/dist/matterbridgeBehaviors.d.ts.map +1 -0
  196. package/dist/matterbridgeBehaviors.js +68 -5
  197. package/dist/matterbridgeBehaviors.js.map +1 -0
  198. package/dist/matterbridgeDeviceTypes.d.ts +698 -0
  199. package/dist/matterbridgeDeviceTypes.d.ts.map +1 -0
  200. package/dist/matterbridgeDeviceTypes.js +635 -14
  201. package/dist/matterbridgeDeviceTypes.js.map +1 -0
  202. package/dist/matterbridgeDynamicPlatform.d.ts +41 -0
  203. package/dist/matterbridgeDynamicPlatform.d.ts.map +1 -0
  204. package/dist/matterbridgeDynamicPlatform.js +38 -0
  205. package/dist/matterbridgeDynamicPlatform.js.map +1 -0
  206. package/dist/matterbridgeEndpoint.d.ts +1507 -0
  207. package/dist/matterbridgeEndpoint.d.ts.map +1 -0
  208. package/dist/matterbridgeEndpoint.js +1444 -53
  209. package/dist/matterbridgeEndpoint.js.map +1 -0
  210. package/dist/matterbridgeEndpointHelpers.d.ts +787 -0
  211. package/dist/matterbridgeEndpointHelpers.d.ts.map +1 -0
  212. package/dist/matterbridgeEndpointHelpers.js +483 -20
  213. package/dist/matterbridgeEndpointHelpers.js.map +1 -0
  214. package/dist/matterbridgeEndpointTypes.d.ts +166 -0
  215. package/dist/matterbridgeEndpointTypes.d.ts.map +1 -0
  216. package/dist/matterbridgeEndpointTypes.js +25 -0
  217. package/dist/matterbridgeEndpointTypes.js.map +1 -0
  218. package/dist/matterbridgePlatform.d.ts +539 -0
  219. package/dist/matterbridgePlatform.d.ts.map +1 -0
  220. package/dist/matterbridgePlatform.js +451 -1
  221. package/dist/matterbridgePlatform.js.map +1 -0
  222. package/dist/matterbridgeTypes.d.ts +251 -0
  223. package/dist/matterbridgeTypes.d.ts.map +1 -0
  224. package/dist/matterbridgeTypes.js +26 -0
  225. package/dist/matterbridgeTypes.js.map +1 -0
  226. package/dist/pluginManager.d.ts +372 -0
  227. package/dist/pluginManager.d.ts.map +1 -0
  228. package/dist/pluginManager.js +341 -5
  229. package/dist/pluginManager.js.map +1 -0
  230. package/dist/shelly.d.ts +181 -0
  231. package/dist/shelly.d.ts.map +1 -0
  232. package/dist/shelly.js +178 -7
  233. package/dist/shelly.js.map +1 -0
  234. package/dist/storage/export.d.ts +2 -0
  235. package/dist/storage/export.d.ts.map +1 -0
  236. package/dist/storage/export.js +1 -0
  237. package/dist/storage/export.js.map +1 -0
  238. package/dist/update.d.ts +84 -0
  239. package/dist/update.d.ts.map +1 -0
  240. package/dist/update.js +93 -1
  241. package/dist/update.js.map +1 -0
  242. package/dist/utils/colorUtils.d.ts +101 -0
  243. package/dist/utils/colorUtils.d.ts.map +1 -0
  244. package/dist/utils/colorUtils.js +97 -2
  245. package/dist/utils/colorUtils.js.map +1 -0
  246. package/dist/utils/commandLine.d.ts +66 -0
  247. package/dist/utils/commandLine.d.ts.map +1 -0
  248. package/dist/utils/commandLine.js +60 -0
  249. package/dist/utils/commandLine.js.map +1 -0
  250. package/dist/utils/copyDirectory.d.ts +35 -0
  251. package/dist/utils/copyDirectory.d.ts.map +1 -0
  252. package/dist/utils/copyDirectory.js +37 -0
  253. package/dist/utils/copyDirectory.js.map +1 -0
  254. package/dist/utils/createDirectory.d.ts +34 -0
  255. package/dist/utils/createDirectory.d.ts.map +1 -0
  256. package/dist/utils/createDirectory.js +33 -0
  257. package/dist/utils/createDirectory.js.map +1 -0
  258. package/dist/utils/createZip.d.ts +39 -0
  259. package/dist/utils/createZip.d.ts.map +1 -0
  260. package/dist/utils/createZip.js +47 -2
  261. package/dist/utils/createZip.js.map +1 -0
  262. package/dist/utils/deepCopy.d.ts +32 -0
  263. package/dist/utils/deepCopy.d.ts.map +1 -0
  264. package/dist/utils/deepCopy.js +39 -0
  265. package/dist/utils/deepCopy.js.map +1 -0
  266. package/dist/utils/deepEqual.d.ts +54 -0
  267. package/dist/utils/deepEqual.d.ts.map +1 -0
  268. package/dist/utils/deepEqual.js +72 -1
  269. package/dist/utils/deepEqual.js.map +1 -0
  270. package/dist/utils/error.d.ts +45 -0
  271. package/dist/utils/error.d.ts.map +1 -0
  272. package/dist/utils/error.js +42 -0
  273. package/dist/utils/error.js.map +1 -0
  274. package/dist/utils/export.d.ts +13 -0
  275. package/dist/utils/export.d.ts.map +1 -0
  276. package/dist/utils/export.js +1 -0
  277. package/dist/utils/export.js.map +1 -0
  278. package/dist/utils/format.d.ts +53 -0
  279. package/dist/utils/format.d.ts.map +1 -0
  280. package/dist/utils/format.js +49 -0
  281. package/dist/utils/format.js.map +1 -0
  282. package/dist/utils/hex.d.ts +89 -0
  283. package/dist/utils/hex.d.ts.map +1 -0
  284. package/dist/utils/hex.js +124 -0
  285. package/dist/utils/hex.js.map +1 -0
  286. package/dist/utils/inspector.d.ts +87 -0
  287. package/dist/utils/inspector.d.ts.map +1 -0
  288. package/dist/utils/inspector.js +69 -1
  289. package/dist/utils/inspector.js.map +1 -0
  290. package/dist/utils/isvalid.d.ts +103 -0
  291. package/dist/utils/isvalid.d.ts.map +1 -0
  292. package/dist/utils/isvalid.js +101 -0
  293. package/dist/utils/isvalid.js.map +1 -0
  294. package/dist/utils/network.d.ts +111 -0
  295. package/dist/utils/network.d.ts.map +1 -0
  296. package/dist/utils/network.js +96 -5
  297. package/dist/utils/network.js.map +1 -0
  298. package/dist/utils/spawn.d.ts +33 -0
  299. package/dist/utils/spawn.d.ts.map +1 -0
  300. package/dist/utils/spawn.js +71 -1
  301. package/dist/utils/spawn.js.map +1 -0
  302. package/dist/utils/tracker.d.ts +108 -0
  303. package/dist/utils/tracker.d.ts.map +1 -0
  304. package/dist/utils/tracker.js +64 -1
  305. package/dist/utils/tracker.js.map +1 -0
  306. package/dist/utils/wait.d.ts +54 -0
  307. package/dist/utils/wait.d.ts.map +1 -0
  308. package/dist/utils/wait.js +60 -8
  309. package/dist/utils/wait.js.map +1 -0
  310. package/dist/workerGlobalPrefix.d.ts +25 -0
  311. package/dist/workerGlobalPrefix.d.ts.map +1 -0
  312. package/dist/workerGlobalPrefix.js +37 -5
  313. package/dist/workerGlobalPrefix.js.map +1 -0
  314. package/dist/workerTypes.d.ts +52 -0
  315. package/dist/workerTypes.d.ts.map +1 -0
  316. package/dist/workerTypes.js +24 -0
  317. package/dist/workerTypes.js.map +1 -0
  318. package/dist/workers.d.ts +69 -0
  319. package/dist/workers.d.ts.map +1 -0
  320. package/dist/workers.js +68 -4
  321. package/dist/workers.js.map +1 -0
  322. package/npm-shrinkwrap.json +2 -2
  323. package/package.json +2 -1
  324. package/scripts/data_model.mjs +2058 -0
@@ -1,4 +1,28 @@
1
+ /**
2
+ * @description This file contains the class Mdns.
3
+ * @file mdns.ts
4
+ * @author Luca Liguori
5
+ * @created 2025-03-22
6
+ * @version 1.0.0
7
+ * @license Apache-2.0
8
+ *
9
+ * Copyright 2025, 2026, 2027 Luca Liguori.
10
+ *
11
+ * Licensed under the Apache License, Version 2.0 (the "License");
12
+ * you may not use this file except in compliance with the License.
13
+ * You may obtain a copy of the License at
14
+ *
15
+ * http://www.apache.org/licenses/LICENSE-2.0
16
+ *
17
+ * Unless required by applicable law or agreed to in writing, software
18
+ * distributed under the License is distributed on an "AS IS" BASIS,
19
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
20
+ * See the License for the specific language governing permissions and
21
+ * limitations under the License.
22
+ */
23
+ // AnsiLogger imports
1
24
  import { BLUE, CYAN, db, er, GREEN, idn, MAGENTA, nf, rs } from 'node-ansi-logger';
25
+ // Net imports
2
26
  import { Multicast } from './multicast.js';
3
27
  export var DnsRecordType;
4
28
  (function (DnsRecordType) {
@@ -90,6 +114,7 @@ export var DnsRecordType;
90
114
  DnsRecordType[DnsRecordType["DOA"] = 259] = "DOA";
91
115
  DnsRecordType[DnsRecordType["AMTRELAY"] = 260] = "AMTRELAY";
92
116
  DnsRecordType[DnsRecordType["ZONEVERSION"] = 261] = "ZONEVERSION";
117
+ // 262-32767 are unassigned/reserved
93
118
  DnsRecordType[DnsRecordType["TA"] = 32768] = "TA";
94
119
  DnsRecordType[DnsRecordType["DLV"] = 32769] = "DLV";
95
120
  })(DnsRecordType || (DnsRecordType = {}));
@@ -103,12 +128,25 @@ export var DnsClass;
103
128
  export var DnsClassFlag;
104
129
  (function (DnsClassFlag) {
105
130
  DnsClassFlag[DnsClassFlag["FLUSH"] = 32768] = "FLUSH";
131
+ // eslint-disable-next-line @typescript-eslint/no-duplicate-enum-values
106
132
  DnsClassFlag[DnsClassFlag["QU"] = 32768] = "QU";
107
133
  })(DnsClassFlag || (DnsClassFlag = {}));
108
134
  export class Mdns extends Multicast {
109
135
  deviceQueries = new Map();
110
136
  deviceResponses = new Map();
111
137
  filters = [];
138
+ /**
139
+ * Creates an instance of the Mdns class.
140
+ *
141
+ * @param {string} name - The internal name of the mDNS server for the logs.
142
+ * @param {string} multicastAddress - The multicast address for mDNS (i.e. 224.0.0.251 for udp4 or ff02::fb for udp6).
143
+ * @param {number} multicastPort - The port for mDNS (i.e. 5353).
144
+ * @param {('udp4' | 'udp6')} socketType - The type of socket to create (either 'udp4' or 'udp6').
145
+ * @param {boolean} [reuseAddr] - Whether to reuse the address. Defaults to true.
146
+ * @param {string} [interfaceName] - The optional name of the network interface to use.
147
+ * @param {string} [interfaceAddress] - The optional IP address of the network interface to use.
148
+ * @param {string} [outgoingInterfaceAddress] - The address of the outgoing network interface.
149
+ */
112
150
  constructor(name, multicastAddress, multicastPort, socketType, reuseAddr = true, interfaceName, interfaceAddress, outgoingInterfaceAddress) {
113
151
  super(name, multicastAddress, multicastPort, socketType, reuseAddr, interfaceName, interfaceAddress, outgoingInterfaceAddress);
114
152
  }
@@ -128,14 +166,14 @@ export class Mdns extends Multicast {
128
166
  this.onQuery(rinfo, result);
129
167
  }
130
168
  else {
131
- const ptr = result.answers?.find((record) => record.name === '_shelly._tcp.local' && record.type === 12) ||
132
- result.answers?.find((record) => record.name === '_http._tcp.local' && record.type === 12) ||
133
- result.answers?.find((record) => record.type === 12) ||
134
- result.answers?.find((record) => record.type === 16) ||
169
+ const ptr = result.answers?.find((record) => record.name === '_shelly._tcp.local' && record.type === 12 /* DnsRecordType.PTR */) ||
170
+ result.answers?.find((record) => record.name === '_http._tcp.local' && record.type === 12 /* DnsRecordType.PTR */) ||
171
+ result.answers?.find((record) => record.type === 12 /* DnsRecordType.PTR */) ||
172
+ result.answers?.find((record) => record.type === 16 /* DnsRecordType.TXT */) ||
135
173
  result.answers
136
174
  ? result.answers[0]
137
- : undefined;
138
- this.deviceResponses.set(rinfo.address, { rinfo, response: result, dataPTR: ptr?.type === 12 ? ptr?.data : ptr?.name });
175
+ : undefined; // Fallback to the first answer if no PTR or TXT found
176
+ this.deviceResponses.set(rinfo.address, { rinfo, response: result, dataPTR: ptr?.type === 12 /* DnsRecordType.PTR */ ? ptr?.data : ptr?.name });
139
177
  this.onResponse(rinfo, result);
140
178
  }
141
179
  if (this.filters.length > 0) {
@@ -159,20 +197,28 @@ export class Mdns extends Multicast {
159
197
  this.log.error(`Error decoding mDNS message: ${error instanceof Error ? error.message : error}`);
160
198
  }
161
199
  }
200
+ /**
201
+ * Decodes an mDNS message, including the header, question section, answer section,
202
+ * authority section, and additional section.
203
+ *
204
+ * @param {Buffer} msg - The raw mDNS message buffer.
205
+ * @returns {MdnsMessage} An object representing the decoded mDNS message.
206
+ * @throws {Error} if the message is too short.
207
+ */
162
208
  decodeMdnsMessage(msg) {
163
209
  if (msg.length < 12) {
164
210
  throw new Error('mDNS message too short');
165
211
  }
166
212
  const id = msg.readUInt16BE(0);
167
213
  const flags = msg.readUInt16BE(2);
168
- const qr = (flags & 0x8000) >> 15;
169
- const opcode = (flags & 0x7800) >> 11;
170
- const aa = Boolean(flags & 0x0400);
171
- const tc = Boolean(flags & 0x0200);
172
- const rd = Boolean(flags & 0x0100);
173
- const ra = Boolean(flags & 0x0080);
174
- const z = (flags & 0x0070) >> 4;
175
- const rcode = flags & 0x000f;
214
+ const qr = (flags & 0x8000) >> 15; // Bit 15: 0=query, 1=response.
215
+ const opcode = (flags & 0x7800) >> 11; // Bits 14-11.
216
+ const aa = Boolean(flags & 0x0400); // Bit 10.
217
+ const tc = Boolean(flags & 0x0200); // Bit 9.
218
+ const rd = Boolean(flags & 0x0100); // Bit 8.
219
+ const ra = Boolean(flags & 0x0080); // Bit 7.
220
+ const z = (flags & 0x0070) >> 4; // Bits 6-4.
221
+ const rcode = flags & 0x000f; // Bits 3-0.
176
222
  const qdCount = msg.readUInt16BE(4);
177
223
  const anCount = msg.readUInt16BE(6);
178
224
  const nsCount = msg.readUInt16BE(8);
@@ -197,6 +243,7 @@ export class Mdns extends Multicast {
197
243
  additionals: [],
198
244
  };
199
245
  let offset = 12;
246
+ // Decode the question section.
200
247
  for (let i = 0; i < qdCount; i++) {
201
248
  const qnameResult = this.decodeDnsName(msg, offset);
202
249
  const qname = qnameResult.name;
@@ -207,16 +254,19 @@ export class Mdns extends Multicast {
207
254
  offset += 2;
208
255
  mdnsMessage.questions?.push({ name: qname, type: qtype, class: qclass });
209
256
  }
257
+ // Decode the answer section.
210
258
  for (let i = 0; i < anCount; i++) {
211
259
  const rrResult = this.decodeResourceRecord(msg, offset);
212
260
  mdnsMessage.answers?.push(rrResult.record);
213
261
  offset = rrResult.newOffset;
214
262
  }
263
+ // Decode the authority (NS) section.
215
264
  for (let i = 0; i < nsCount; i++) {
216
265
  const rrResult = this.decodeResourceRecord(msg, offset);
217
266
  mdnsMessage.authorities?.push(rrResult.record);
218
267
  offset = rrResult.newOffset;
219
268
  }
269
+ // Decode the additional records section.
220
270
  for (let i = 0; i < arCount; i++) {
221
271
  const rrResult = this.decodeResourceRecord(msg, offset);
222
272
  mdnsMessage.additionals?.push(rrResult.record);
@@ -224,15 +274,25 @@ export class Mdns extends Multicast {
224
274
  }
225
275
  return mdnsMessage;
226
276
  }
277
+ /**
278
+ * Decodes a DNS name from a buffer, handling compression.
279
+ *
280
+ * @param {Buffer} msg - The full mDNS message buffer.
281
+ * @param {number} offset - The offset at which the DNS name starts.
282
+ * @returns {{ name: string; newOffset: number }} An object with the decoded name and the new offset.
283
+ * @throws {Error} if the offset exceeds the buffer length or too many iterations are performed.
284
+ */
227
285
  decodeDnsName(msg, offset) {
228
286
  const labels = [];
229
287
  let jumped = false;
230
288
  let originalOffset = offset;
231
- let iterations = 0;
289
+ let iterations = 0; // Prevent infinite loops
232
290
  while (true) {
291
+ // Safety guard: prevent infinite loops in malformed messages.
233
292
  if (iterations++ > 1000) {
234
293
  throw new Error('Too many iterations while decoding DNS name. Possible malformed message.');
235
294
  }
295
+ // Check that offset is within buffer bounds.
236
296
  if (offset >= msg.length) {
237
297
  throw new Error('Offset exceeds buffer length while decoding DNS name.');
238
298
  }
@@ -241,7 +301,9 @@ export class Mdns extends Multicast {
241
301
  offset++;
242
302
  break;
243
303
  }
304
+ // Check for pointer (first two bits are 11)
244
305
  if ((len & 0xc0) === 0xc0) {
306
+ // Ensure the pointer has two bytes available.
245
307
  if (offset + 1 >= msg.length) {
246
308
  throw new Error('Incomplete pointer encountered while decoding DNS name.');
247
309
  }
@@ -254,6 +316,7 @@ export class Mdns extends Multicast {
254
316
  continue;
255
317
  }
256
318
  offset++;
319
+ // Check that the label length doesn't go beyond the buffer.
257
320
  if (offset + len > msg.length) {
258
321
  throw new Error('Label length exceeds buffer bounds while decoding DNS name.');
259
322
  }
@@ -262,6 +325,15 @@ export class Mdns extends Multicast {
262
325
  }
263
326
  return { name: labels.join('.'), newOffset: jumped ? originalOffset : offset };
264
327
  }
328
+ /**
329
+ * Encodes a domain name into the DNS label format.
330
+ *
331
+ * For example, "example.local" becomes:
332
+ * [7] "example" [5] "local" [0]
333
+ *
334
+ * @param {string} name - The domain name to encode.
335
+ * @returns {Buffer} The encoded domain name as a Buffer.
336
+ */
265
337
  encodeDnsName(name) {
266
338
  const labels = name.split('.');
267
339
  const buffers = labels.map((label) => {
@@ -269,12 +341,22 @@ export class Mdns extends Multicast {
269
341
  lenBuf.writeUInt8(label.length, 0);
270
342
  return Buffer.concat([lenBuf, Buffer.from(label)]);
271
343
  });
344
+ // Append the null byte to terminate the name.
272
345
  return Buffer.concat([...buffers, Buffer.from([0])]);
273
346
  }
347
+ /**
348
+ * Decodes a DNS resource record.
349
+ *
350
+ * @param {Buffer} msg - The full mDNS message buffer.
351
+ * @param {number} offset - The offset at which the resource record starts.
352
+ * @returns {{ record: MdnsRecord; newOffset: number }} An object containing the decoded record and the new offset.
353
+ */
274
354
  decodeResourceRecord(msg, offset) {
355
+ // Decode the NAME field (which may be compressed)
275
356
  const nameResult = this.decodeDnsName(msg, offset);
276
357
  const name = nameResult.name;
277
358
  offset = nameResult.newOffset;
359
+ // Read TYPE (16 bits), CLASS (16 bits), TTL (32 bits), and RDLENGTH (16 bits)
278
360
  const type = msg.readUInt16BE(offset);
279
361
  offset += 2;
280
362
  const rrclass = msg.readUInt16BE(offset);
@@ -284,12 +366,14 @@ export class Mdns extends Multicast {
284
366
  const rdlength = msg.readUInt16BE(offset);
285
367
  offset += 2;
286
368
  let data = '';
287
- if (type === 12) {
369
+ if (type === 12 /* DnsRecordType.PTR */) {
370
+ // PTR record (type 12): decode its RDATA as a domain name.
288
371
  const ptrResult = this.decodeDnsName(msg, offset);
289
372
  data = ptrResult.name;
290
373
  offset += rdlength;
291
374
  }
292
- else if (type === 16) {
375
+ else if (type === 16 /* DnsRecordType.TXT */) {
376
+ // TXT record: may consist of one or more length-prefixed strings.
293
377
  const txtStrings = [];
294
378
  const end = offset + rdlength;
295
379
  while (offset < end) {
@@ -301,7 +385,8 @@ export class Mdns extends Multicast {
301
385
  }
302
386
  data = txtStrings.join(', ');
303
387
  }
304
- else if (type === 33) {
388
+ else if (type === 33 /* DnsRecordType.SRV */) {
389
+ // SRV record (type === 33): consists of 2 bytes for priority, 2 for weight, 2 for port, followed by the target domain name.
305
390
  const priority = msg.readUInt16BE(offset);
306
391
  const weight = msg.readUInt16BE(offset + 2);
307
392
  const port = msg.readUInt16BE(offset + 4);
@@ -315,13 +400,16 @@ export class Mdns extends Multicast {
315
400
  });
316
401
  offset = srvTargetResult.newOffset;
317
402
  }
318
- else if (type === 1) {
403
+ else if (type === 1 /* DnsRecordType.A */) {
404
+ // A record (type 1): an IPv4 address stored in 4 bytes.
319
405
  const ipBytes = msg.slice(offset, offset + 4);
320
406
  data = Array.from(ipBytes).join('.');
321
407
  offset += 4;
322
408
  }
323
- else if (type === 28) {
409
+ else if (type === 28 /* DnsRecordType.AAAA */) {
410
+ // AAAA record (type 28): IPv6 address stored in 16 bytes.
324
411
  const ipBytes = msg.slice(offset, offset + 16);
412
+ // Convert the 16 bytes into an IPv6 address string (colon-separated)
325
413
  const ipv6Parts = [];
326
414
  for (let i = 0; i < 16; i += 2) {
327
415
  ipv6Parts.push(ipBytes.readUInt16BE(i).toString(16));
@@ -329,10 +417,14 @@ export class Mdns extends Multicast {
329
417
  data = ipv6Parts.join(':');
330
418
  offset += 16;
331
419
  }
332
- else if (type === 47) {
420
+ else if (type === 47 /* DnsRecordType.NSEC */) {
421
+ // NSEC record: RDATA consists of:
422
+ // - Next Domain Name (in DNS label format)
423
+ // - Type Bit Maps (variable length)
333
424
  const { name: nextDomain, newOffset } = this.decodeDnsName(msg, offset);
334
425
  const nextDomainLength = newOffset - offset;
335
426
  offset = newOffset;
427
+ // Calculate the remaining length for the type bit maps.
336
428
  const bitmapLength = rdlength - nextDomainLength;
337
429
  const bitmapData = msg.slice(offset, offset + bitmapLength);
338
430
  const types = [];
@@ -359,6 +451,7 @@ export class Mdns extends Multicast {
359
451
  offset += bitmapLength;
360
452
  }
361
453
  else {
454
+ // Fall back
362
455
  data = msg.slice(offset, offset + rdlength).toString('hex');
363
456
  offset += rdlength;
364
457
  }
@@ -367,19 +460,28 @@ export class Mdns extends Multicast {
367
460
  newOffset: offset,
368
461
  };
369
462
  }
463
+ /**
464
+ * Sends a DNS query with multiple questions.
465
+ *
466
+ * @param {Array<{ name: string; type: number; class: number; unicastResponse?: boolean }>} questions - Array of questions
467
+ *
468
+ * @remarks
469
+ * Each question should have a name (e.g., "_http._tcp.local"), type (e.g., DnsRecordType.PTR), class (e.g., DnsClass.IN),
470
+ * and an optional unicastResponse flag (this will add the DnsClassFlag.QU flag to the query).
471
+ */
370
472
  sendQuery(questions) {
371
473
  const header = Buffer.alloc(12);
372
- header.writeUInt16BE(0, 0);
373
- header.writeUInt16BE(0, 2);
374
- header.writeUInt16BE(questions.length, 4);
375
- header.writeUInt16BE(0, 6);
376
- header.writeUInt16BE(0, 8);
377
- header.writeUInt16BE(0, 10);
474
+ header.writeUInt16BE(0, 0); // ID
475
+ header.writeUInt16BE(0, 2); // Flags
476
+ header.writeUInt16BE(questions.length, 4); // QDCOUNT
477
+ header.writeUInt16BE(0, 6); // ANCOUNT
478
+ header.writeUInt16BE(0, 8); // NSCOUNT
479
+ header.writeUInt16BE(0, 10); // ARCOUNT
378
480
  const questionBuffers = questions.map(({ name, type: qtype, class: qclass, unicastResponse = false }) => {
379
481
  const qname = this.encodeDnsName(name);
380
482
  const qfields = Buffer.alloc(4);
381
483
  qfields.writeUInt16BE(qtype, 0);
382
- qfields.writeUInt16BE(unicastResponse ? qclass | 32768 : qclass, 2);
484
+ qfields.writeUInt16BE(unicastResponse ? qclass | 32768 /* DnsClassFlag.QU */ : qclass, 2);
383
485
  return Buffer.concat([qname, qfields]);
384
486
  });
385
487
  const query = Buffer.concat([header, ...questionBuffers]);
@@ -399,22 +501,46 @@ export class Mdns extends Multicast {
399
501
  }
400
502
  });
401
503
  }
504
+ /**
505
+ * Constructs an mDNS response packet and sends it to the multicast address and port.
506
+ *
507
+ * @param {string} name - The domain name being responded to (e.g., "example.local").
508
+ * @param {number} rtype - The response type (e.g., 1 for A, 28 for AAAA, etc.).
509
+ * @param {number} rclass - The response class (typically 1 for IN).
510
+ * @param {number} ttl - The time-to-live for the answer record.
511
+ * @param {Buffer} rdata - The resource data for the response (e.g., 4 bytes for an A record IPv4 address).
512
+ *
513
+ * @example
514
+ * const ptrRdata = mdnsIpv4.encodeDnsName('matterbridge._http._tcp.local');
515
+ * mdnsIpv4.sendResponse('_http._tcp.local', DnsRecordType.PTR, DnsClass.IN, 120, ptrRdata);
516
+ */
402
517
  sendResponse(name, rtype, rclass, ttl, rdata) {
518
+ // Create a 12-byte DNS header.
403
519
  const header = Buffer.alloc(12);
404
- header.writeUInt16BE(0, 0);
520
+ header.writeUInt16BE(0, 0); // ID is set to 0 in mDNS.
521
+ // Set flags: QR (response) bit and AA (authoritative answer) bit.
405
522
  header.writeUInt16BE(0x8400, 2);
406
- header.writeUInt16BE(0, 4);
407
- header.writeUInt16BE(1, 6);
408
- header.writeUInt16BE(0, 8);
409
- header.writeUInt16BE(0, 10);
523
+ header.writeUInt16BE(0, 4); // QDCOUNT: 0 questions in response.
524
+ header.writeUInt16BE(1, 6); // ANCOUNT: 1 answer record.
525
+ header.writeUInt16BE(0, 8); // NSCOUNT: 0 authority records.
526
+ header.writeUInt16BE(0, 10); // ARCOUNT: 0 additional records.
527
+ // Encode the domain name in DNS label format.
410
528
  const aname = this.encodeDnsName(name);
529
+ // Prepare the fixed part of the answer record:
530
+ // - 2 bytes for qtype,
531
+ // - 2 bytes for qclass,
532
+ // - 4 bytes for TTL,
533
+ // - 2 bytes for RDLENGTH (length of the rdata).
411
534
  const answerFixed = Buffer.alloc(10);
412
- answerFixed.writeUInt16BE(rtype, 0);
413
- answerFixed.writeUInt16BE(rclass, 2);
414
- answerFixed.writeUInt32BE(ttl, 4);
415
- answerFixed.writeUInt16BE(rdata.length, 8);
535
+ answerFixed.writeUInt16BE(rtype, 0); // Record type.
536
+ answerFixed.writeUInt16BE(rclass, 2); // Record class.
537
+ answerFixed.writeUInt32BE(ttl, 4); // Time-to-live.
538
+ answerFixed.writeUInt16BE(rdata.length, 8); // RDLENGTH.
539
+ // Concatenate the answer: encoded name, fixed fields, and resource data.
416
540
  const answer = Buffer.concat([aname, answerFixed, rdata]);
541
+ // Concatenate header and answer to form the complete mDNS response packet.
417
542
  const response = Buffer.concat([header, answer]);
543
+ // Send the response packet via the socket.
418
544
  this.socket.send(response, 0, response.length, this.multicastPort, this.multicastAddress, (error) => {
419
545
  if (error) {
420
546
  this.log.error(`Dgram mDNS server failed to send response message for ${MAGENTA}${name}${er} type ${MAGENTA}${this.dnsTypeToString(rtype)}${er} class ${MAGENTA}${this.dnsResponseClassToString(rclass)}${er} ttl ${MAGENTA}${ttl}${er}: ${error instanceof Error ? error.message : error}`);
@@ -426,116 +552,128 @@ export class Mdns extends Multicast {
426
552
  }
427
553
  });
428
554
  }
555
+ /**
556
+ * Converts a DNS record type numeric value to its string representation.
557
+ *
558
+ * @param {number} type - The numeric DNS record type.
559
+ * @returns {string} The string representation of the record type.
560
+ */
429
561
  dnsTypeToString(type) {
430
562
  const typeMap = {
431
- [1]: 'A',
432
- [2]: 'NS',
433
- [3]: 'MD',
434
- [4]: 'MF',
435
- [5]: 'CNAME',
436
- [6]: 'SOA',
437
- [7]: 'MB',
438
- [8]: 'MG',
439
- [9]: 'MR',
440
- [10]: 'NULL',
441
- [11]: 'WKS',
442
- [12]: 'PTR',
443
- [13]: 'HINFO',
444
- [14]: 'MINFO',
445
- [15]: 'MX',
446
- [16]: 'TXT',
447
- [17]: 'RP',
448
- [18]: 'AFSDB',
449
- [19]: 'X25',
450
- [20]: 'ISDN',
451
- [21]: 'RT',
452
- [22]: 'NSAP',
453
- [23]: 'NSAP_PTR',
454
- [24]: 'SIG',
455
- [25]: 'KEY',
456
- [26]: 'PX',
457
- [27]: 'GPOS',
458
- [28]: 'AAAA',
459
- [29]: 'LOC',
460
- [30]: 'NXT',
461
- [31]: 'EID',
462
- [32]: 'NIMLOC',
463
- [33]: 'SRV',
464
- [34]: 'ATMA',
465
- [35]: 'NAPTR',
466
- [36]: 'KX',
467
- [37]: 'CERT',
468
- [38]: 'A6',
469
- [39]: 'DNAME',
470
- [40]: 'SINK',
471
- [41]: 'OPT',
472
- [42]: 'APL',
473
- [43]: 'DS',
474
- [44]: 'SSHFP',
475
- [45]: 'IPSECKEY',
476
- [46]: 'RRSIG',
477
- [47]: 'NSEC',
478
- [48]: 'DNSKEY',
479
- [49]: 'DHCID',
480
- [50]: 'NSEC3',
481
- [51]: 'NSEC3PARAM',
482
- [52]: 'TLSA',
483
- [53]: 'SMIMEA',
484
- [55]: 'HIP',
485
- [56]: 'NINFO',
486
- [57]: 'RKEY',
487
- [58]: 'TALINK',
488
- [59]: 'CDS',
489
- [60]: 'CDNSKEY',
490
- [61]: 'OPENPGPKEY',
491
- [62]: 'CSYNC',
492
- [63]: 'ZONEMD',
493
- [64]: 'SVCB',
494
- [65]: 'HTTPS',
495
- [99]: 'SPF',
496
- [100]: 'UINFO',
497
- [101]: 'UID',
498
- [102]: 'GID',
499
- [103]: 'UNSPEC',
500
- [104]: 'NID',
501
- [105]: 'L32',
502
- [106]: 'L64',
503
- [107]: 'LP',
504
- [108]: 'EUI48',
505
- [109]: 'EUI64',
506
- [249]: 'TKEY',
507
- [250]: 'TSIG',
508
- [251]: 'IXFR',
509
- [252]: 'AXFR',
510
- [253]: 'MAILB',
511
- [254]: 'MAILA',
512
- [255]: 'ANY',
513
- [256]: 'URI',
514
- [257]: 'CAA',
515
- [258]: 'AVC',
516
- [259]: 'DOA',
517
- [260]: 'AMTRELAY',
518
- [261]: 'ZONEVERSION',
519
- [32768]: 'TA',
520
- [32769]: 'DLV',
563
+ [1 /* DnsRecordType.A */]: 'A',
564
+ [2 /* DnsRecordType.NS */]: 'NS',
565
+ [3 /* DnsRecordType.MD */]: 'MD',
566
+ [4 /* DnsRecordType.MF */]: 'MF',
567
+ [5 /* DnsRecordType.CNAME */]: 'CNAME',
568
+ [6 /* DnsRecordType.SOA */]: 'SOA',
569
+ [7 /* DnsRecordType.MB */]: 'MB',
570
+ [8 /* DnsRecordType.MG */]: 'MG',
571
+ [9 /* DnsRecordType.MR */]: 'MR',
572
+ [10 /* DnsRecordType.NULL */]: 'NULL',
573
+ [11 /* DnsRecordType.WKS */]: 'WKS',
574
+ [12 /* DnsRecordType.PTR */]: 'PTR',
575
+ [13 /* DnsRecordType.HINFO */]: 'HINFO',
576
+ [14 /* DnsRecordType.MINFO */]: 'MINFO',
577
+ [15 /* DnsRecordType.MX */]: 'MX',
578
+ [16 /* DnsRecordType.TXT */]: 'TXT',
579
+ [17 /* DnsRecordType.RP */]: 'RP',
580
+ [18 /* DnsRecordType.AFSDB */]: 'AFSDB',
581
+ [19 /* DnsRecordType.X25 */]: 'X25',
582
+ [20 /* DnsRecordType.ISDN */]: 'ISDN',
583
+ [21 /* DnsRecordType.RT */]: 'RT',
584
+ [22 /* DnsRecordType.NSAP */]: 'NSAP',
585
+ [23 /* DnsRecordType.NSAP_PTR */]: 'NSAP_PTR',
586
+ [24 /* DnsRecordType.SIG */]: 'SIG',
587
+ [25 /* DnsRecordType.KEY */]: 'KEY',
588
+ [26 /* DnsRecordType.PX */]: 'PX',
589
+ [27 /* DnsRecordType.GPOS */]: 'GPOS',
590
+ [28 /* DnsRecordType.AAAA */]: 'AAAA',
591
+ [29 /* DnsRecordType.LOC */]: 'LOC',
592
+ [30 /* DnsRecordType.NXT */]: 'NXT',
593
+ [31 /* DnsRecordType.EID */]: 'EID',
594
+ [32 /* DnsRecordType.NIMLOC */]: 'NIMLOC',
595
+ [33 /* DnsRecordType.SRV */]: 'SRV',
596
+ [34 /* DnsRecordType.ATMA */]: 'ATMA',
597
+ [35 /* DnsRecordType.NAPTR */]: 'NAPTR',
598
+ [36 /* DnsRecordType.KX */]: 'KX',
599
+ [37 /* DnsRecordType.CERT */]: 'CERT',
600
+ [38 /* DnsRecordType.A6 */]: 'A6',
601
+ [39 /* DnsRecordType.DNAME */]: 'DNAME',
602
+ [40 /* DnsRecordType.SINK */]: 'SINK',
603
+ [41 /* DnsRecordType.OPT */]: 'OPT',
604
+ [42 /* DnsRecordType.APL */]: 'APL',
605
+ [43 /* DnsRecordType.DS */]: 'DS',
606
+ [44 /* DnsRecordType.SSHFP */]: 'SSHFP',
607
+ [45 /* DnsRecordType.IPSECKEY */]: 'IPSECKEY',
608
+ [46 /* DnsRecordType.RRSIG */]: 'RRSIG',
609
+ [47 /* DnsRecordType.NSEC */]: 'NSEC',
610
+ [48 /* DnsRecordType.DNSKEY */]: 'DNSKEY',
611
+ [49 /* DnsRecordType.DHCID */]: 'DHCID',
612
+ [50 /* DnsRecordType.NSEC3 */]: 'NSEC3',
613
+ [51 /* DnsRecordType.NSEC3PARAM */]: 'NSEC3PARAM',
614
+ [52 /* DnsRecordType.TLSA */]: 'TLSA',
615
+ [53 /* DnsRecordType.SMIMEA */]: 'SMIMEA',
616
+ [55 /* DnsRecordType.HIP */]: 'HIP',
617
+ [56 /* DnsRecordType.NINFO */]: 'NINFO',
618
+ [57 /* DnsRecordType.RKEY */]: 'RKEY',
619
+ [58 /* DnsRecordType.TALINK */]: 'TALINK',
620
+ [59 /* DnsRecordType.CDS */]: 'CDS',
621
+ [60 /* DnsRecordType.CDNSKEY */]: 'CDNSKEY',
622
+ [61 /* DnsRecordType.OPENPGPKEY */]: 'OPENPGPKEY',
623
+ [62 /* DnsRecordType.CSYNC */]: 'CSYNC',
624
+ [63 /* DnsRecordType.ZONEMD */]: 'ZONEMD',
625
+ [64 /* DnsRecordType.SVCB */]: 'SVCB',
626
+ [65 /* DnsRecordType.HTTPS */]: 'HTTPS',
627
+ [99 /* DnsRecordType.SPF */]: 'SPF',
628
+ [100 /* DnsRecordType.UINFO */]: 'UINFO',
629
+ [101 /* DnsRecordType.UID */]: 'UID',
630
+ [102 /* DnsRecordType.GID */]: 'GID',
631
+ [103 /* DnsRecordType.UNSPEC */]: 'UNSPEC',
632
+ [104 /* DnsRecordType.NID */]: 'NID',
633
+ [105 /* DnsRecordType.L32 */]: 'L32',
634
+ [106 /* DnsRecordType.L64 */]: 'L64',
635
+ [107 /* DnsRecordType.LP */]: 'LP',
636
+ [108 /* DnsRecordType.EUI48 */]: 'EUI48',
637
+ [109 /* DnsRecordType.EUI64 */]: 'EUI64',
638
+ [249 /* DnsRecordType.TKEY */]: 'TKEY',
639
+ [250 /* DnsRecordType.TSIG */]: 'TSIG',
640
+ [251 /* DnsRecordType.IXFR */]: 'IXFR',
641
+ [252 /* DnsRecordType.AXFR */]: 'AXFR',
642
+ [253 /* DnsRecordType.MAILB */]: 'MAILB',
643
+ [254 /* DnsRecordType.MAILA */]: 'MAILA',
644
+ [255 /* DnsRecordType.ANY */]: 'ANY',
645
+ [256 /* DnsRecordType.URI */]: 'URI',
646
+ [257 /* DnsRecordType.CAA */]: 'CAA',
647
+ [258 /* DnsRecordType.AVC */]: 'AVC',
648
+ [259 /* DnsRecordType.DOA */]: 'DOA',
649
+ [260 /* DnsRecordType.AMTRELAY */]: 'AMTRELAY',
650
+ [261 /* DnsRecordType.ZONEVERSION */]: 'ZONEVERSION',
651
+ [32768 /* DnsRecordType.TA */]: 'TA',
652
+ [32769 /* DnsRecordType.DLV */]: 'DLV',
521
653
  };
522
654
  return typeMap[type] ?? `TYPE${type}`;
523
655
  }
656
+ /**
657
+ * Converts a DNS response class numeric value to its string representation.
658
+ *
659
+ * @param {number} cls - The numeric DNS class.
660
+ * @returns {string} The string representation of the DNS class.
661
+ */
524
662
  dnsResponseClassToString(cls) {
525
- const isFlush = !!(cls & 32768);
663
+ const isFlush = !!(cls & 32768 /* DnsClassFlag.FLUSH */);
526
664
  const baseClass = cls & 0x7fff;
527
665
  let classStr;
528
666
  switch (baseClass) {
529
- case 1:
667
+ case 1 /* DnsClass.IN */:
530
668
  classStr = 'IN';
531
669
  break;
532
- case 3:
670
+ case 3 /* DnsClass.CH */:
533
671
  classStr = 'CH';
534
672
  break;
535
- case 4:
673
+ case 4 /* DnsClass.HS */:
536
674
  classStr = 'HS';
537
675
  break;
538
- case 255:
676
+ case 255 /* DnsClass.ANY */:
539
677
  classStr = 'ANY';
540
678
  break;
541
679
  default:
@@ -543,21 +681,28 @@ export class Mdns extends Multicast {
543
681
  }
544
682
  return isFlush ? `${classStr}|FLUSH` : classStr;
545
683
  }
684
+ /**
685
+ * Converts a DNS question class to a human-readable string.
686
+ * Adds support for mDNS QU (unicast-response) bit.
687
+ *
688
+ * @param {number} cls - The numeric question class.
689
+ * @returns {string} The string representation, e.g. "IN|QU"
690
+ */
546
691
  dnsQuestionClassToString(cls) {
547
- const isQU = !!(cls & 32768);
692
+ const isQU = !!(cls & 32768 /* DnsClassFlag.QU */);
548
693
  const baseClass = cls & 0x7fff;
549
694
  let classStr;
550
695
  switch (baseClass) {
551
- case 1:
696
+ case 1 /* DnsClass.IN */:
552
697
  classStr = 'IN';
553
698
  break;
554
- case 3:
699
+ case 3 /* DnsClass.CH */:
555
700
  classStr = 'CH';
556
701
  break;
557
- case 4:
702
+ case 4 /* DnsClass.HS */:
558
703
  classStr = 'HS';
559
704
  break;
560
- case 255:
705
+ case 255 /* DnsClass.ANY */:
561
706
  classStr = 'ANY';
562
707
  break;
563
708
  default:
@@ -565,6 +710,11 @@ export class Mdns extends Multicast {
565
710
  }
566
711
  return isQU ? `${classStr}|QU` : classStr;
567
712
  }
713
+ /**
714
+ * Logs the decoded mDNS message header.
715
+ *
716
+ * @param {MdnsMessage} msg - The mDNS message header object.
717
+ */
568
718
  logMdnsMessage(msg) {
569
719
  this.log.info(`Decoded mDNS message: ID ${MAGENTA}${msg.id}${nf}, QR ${GREEN}${msg.qr === 0 ? 'Query' : 'Response'}${nf}, OPCODE ${MAGENTA}${msg.opcode}${nf}, AA ${MAGENTA}${msg.aa}${nf}, TC ${MAGENTA}${msg.tc}${nf}, RD ${MAGENTA}${msg.rd}${nf}, RA ${MAGENTA}${msg.ra}${nf}, Z ${MAGENTA}${msg.z}${nf}, RCODE ${MAGENTA}${msg.rcode}${nf}, QDCount ${MAGENTA}${msg.qdCount}${nf}, ANCount ${MAGENTA}${msg.anCount}${nf}, NSCount ${MAGENTA}${msg.nsCount}${nf}, ARCount ${MAGENTA}${msg.arCount}${nf}`);
570
720
  msg.questions?.forEach((question) => {
@@ -581,9 +731,14 @@ export class Mdns extends Multicast {
581
731
  });
582
732
  this.log.info(`---\n`);
583
733
  }
734
+ /**
735
+ * Logs the discovered devices from the mDNS queries and responses.
736
+ */
584
737
  logDevices() {
585
738
  this.log.info(`Discovered query devices: ${MAGENTA}${this.deviceQueries.size}${nf}`);
739
+ // Collect devices into an array
586
740
  const deviceQueryArray = Array.from(this.deviceQueries.entries());
741
+ // Sort the array by numeric value of the IP address
587
742
  deviceQueryArray.sort(([addressA], [addressB]) => {
588
743
  const partsA = addressA.split('.').map(Number);
589
744
  const partsB = addressB.split('.').map(Number);
@@ -592,13 +747,17 @@ export class Mdns extends Multicast {
592
747
  if (diff !== 0)
593
748
  return diff;
594
749
  }
750
+ // istanbul ignore next
595
751
  return 0;
596
752
  });
753
+ // Log the sorted devices
597
754
  deviceQueryArray.forEach(([rinfo, response]) => {
598
755
  this.log.info(`- ${MAGENTA}${rinfo}${nf} family ${BLUE}${response.rinfo.family}${nf} address ${BLUE}${response.rinfo.address}${nf} port ${BLUE}${response.rinfo.port}${nf}`);
599
756
  });
600
757
  this.log.info(`Discovered response devices: ${MAGENTA}${this.deviceResponses.size}${nf}`);
758
+ // Collect devices into an array
601
759
  const deviceResponseArray = Array.from(this.deviceResponses.entries());
760
+ // Sort the array by numeric value of the IP address
602
761
  deviceResponseArray.sort(([addressA], [addressB]) => {
603
762
  const partsA = addressA.split(/[:.]/).map((part) => parseInt(part, 16));
604
763
  const partsB = addressB.split(/[:.]/).map((part) => parseInt(part, 16));
@@ -607,10 +766,13 @@ export class Mdns extends Multicast {
607
766
  if (diff !== 0)
608
767
  return diff;
609
768
  }
769
+ // istanbul ignore next
610
770
  return 0;
611
771
  });
772
+ // Log the sorted devices
612
773
  deviceResponseArray.forEach(([rinfo, response]) => {
613
774
  this.log.info(`- ${MAGENTA}${rinfo}${nf} family ${BLUE}${response.rinfo.family}${nf} address ${BLUE}${response.rinfo.address}${nf} port ${BLUE}${response.rinfo.port}${nf} PTR ${GREEN}${response.dataPTR}${nf}`);
614
775
  });
615
776
  }
616
777
  }
778
+ //# sourceMappingURL=mdns.js.map