matterbridge 3.4.3 → 3.4.4-dev-20251214-37296cc

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 (326) hide show
  1. package/CHANGELOG.md +20 -0
  2. package/dist/broadcastServer.js +0 -119
  3. package/dist/broadcastServerTypes.js +0 -24
  4. package/dist/cli.js +1 -97
  5. package/dist/cliEmitter.js +0 -37
  6. package/dist/cliHistory.js +0 -38
  7. package/dist/clusters/export.js +0 -2
  8. package/dist/deviceManager.js +1 -113
  9. package/dist/devices/airConditioner.js +0 -57
  10. package/dist/devices/batteryStorage.js +1 -48
  11. package/dist/devices/cooktop.js +0 -56
  12. package/dist/devices/dishwasher.js +0 -57
  13. package/dist/devices/evse.js +10 -74
  14. package/dist/devices/export.js +0 -5
  15. package/dist/devices/extractorHood.js +0 -43
  16. package/dist/devices/heatPump.js +2 -50
  17. package/dist/devices/laundryDryer.js +3 -62
  18. package/dist/devices/laundryWasher.js +4 -70
  19. package/dist/devices/microwaveOven.js +5 -88
  20. package/dist/devices/oven.js +0 -85
  21. package/dist/devices/refrigerator.js +0 -102
  22. package/dist/devices/roboticVacuumCleaner.js +9 -100
  23. package/dist/devices/solarPower.js +0 -38
  24. package/dist/devices/speaker.js +0 -84
  25. package/dist/devices/temperatureControl.js +3 -24
  26. package/dist/devices/waterHeater.js +2 -82
  27. package/dist/dgram/coap.js +13 -126
  28. package/dist/dgram/dgram.js +2 -114
  29. package/dist/dgram/mb_coap.js +3 -41
  30. package/dist/dgram/mb_mdns.js +15 -80
  31. package/dist/dgram/mdns.js +137 -299
  32. package/dist/dgram/multicast.js +1 -62
  33. package/dist/dgram/unicast.js +0 -54
  34. package/dist/frontend.js +35 -455
  35. package/dist/frontendTypes.js +0 -45
  36. package/dist/helpers.js +0 -53
  37. package/dist/index.js +0 -25
  38. package/dist/jestutils/export.js +0 -1
  39. package/dist/jestutils/jestHelpers.js +14 -371
  40. package/dist/logger/export.js +0 -1
  41. package/dist/matter/behaviors.js +0 -2
  42. package/dist/matter/clusters.js +0 -2
  43. package/dist/matter/devices.js +0 -2
  44. package/dist/matter/endpoints.js +0 -2
  45. package/dist/matter/export.js +0 -3
  46. package/dist/matter/types.js +0 -3
  47. package/dist/matterNode.js +8 -369
  48. package/dist/matterbridge.js +46 -811
  49. package/dist/matterbridgeAccessoryPlatform.js +0 -38
  50. package/dist/matterbridgeBehaviors.js +5 -68
  51. package/dist/matterbridgeDeviceTypes.js +14 -635
  52. package/dist/matterbridgeDynamicPlatform.js +0 -38
  53. package/dist/matterbridgeEndpoint.js +54 -1445
  54. package/dist/matterbridgeEndpointHelpers.js +20 -483
  55. package/dist/matterbridgeEndpointTypes.js +0 -25
  56. package/dist/matterbridgePlatform.js +1 -451
  57. package/dist/matterbridgeTypes.js +0 -26
  58. package/dist/pluginManager.js +5 -341
  59. package/dist/shelly.js +7 -178
  60. package/dist/storage/export.js +0 -1
  61. package/dist/update.js +1 -93
  62. package/dist/utils/colorUtils.js +2 -97
  63. package/dist/utils/commandLine.js +0 -60
  64. package/dist/utils/copyDirectory.js +0 -37
  65. package/dist/utils/createDirectory.js +0 -33
  66. package/dist/utils/createZip.js +2 -47
  67. package/dist/utils/deepCopy.js +0 -39
  68. package/dist/utils/deepEqual.js +1 -72
  69. package/dist/utils/error.js +0 -42
  70. package/dist/utils/export.js +0 -1
  71. package/dist/utils/format.js +0 -49
  72. package/dist/utils/hex.js +0 -124
  73. package/dist/utils/inspector.js +1 -69
  74. package/dist/utils/isvalid.js +0 -101
  75. package/dist/utils/network.js +5 -96
  76. package/dist/utils/spawn.js +1 -71
  77. package/dist/utils/tracker.js +1 -64
  78. package/dist/utils/wait.js +8 -60
  79. package/dist/workerGlobalPrefix.js +5 -37
  80. package/dist/workerTypes.js +0 -24
  81. package/dist/workers.js +4 -68
  82. package/frontend/build/assets/index.js +4 -4
  83. package/frontend/build/assets/vendor_node_modules.js +1 -1
  84. package/frontend/package.json +1 -1
  85. package/npm-shrinkwrap.json +5 -5
  86. package/package.json +1 -2
  87. package/dist/broadcastServer.d.ts +0 -144
  88. package/dist/broadcastServer.d.ts.map +0 -1
  89. package/dist/broadcastServer.js.map +0 -1
  90. package/dist/broadcastServerTypes.d.ts +0 -841
  91. package/dist/broadcastServerTypes.d.ts.map +0 -1
  92. package/dist/broadcastServerTypes.js.map +0 -1
  93. package/dist/cli.d.ts +0 -30
  94. package/dist/cli.d.ts.map +0 -1
  95. package/dist/cli.js.map +0 -1
  96. package/dist/cliEmitter.d.ts +0 -50
  97. package/dist/cliEmitter.d.ts.map +0 -1
  98. package/dist/cliEmitter.js.map +0 -1
  99. package/dist/cliHistory.d.ts +0 -48
  100. package/dist/cliHistory.d.ts.map +0 -1
  101. package/dist/cliHistory.js.map +0 -1
  102. package/dist/clusters/export.d.ts +0 -2
  103. package/dist/clusters/export.d.ts.map +0 -1
  104. package/dist/clusters/export.js.map +0 -1
  105. package/dist/deviceManager.d.ts +0 -135
  106. package/dist/deviceManager.d.ts.map +0 -1
  107. package/dist/deviceManager.js.map +0 -1
  108. package/dist/devices/airConditioner.d.ts +0 -98
  109. package/dist/devices/airConditioner.d.ts.map +0 -1
  110. package/dist/devices/airConditioner.js.map +0 -1
  111. package/dist/devices/batteryStorage.d.ts +0 -48
  112. package/dist/devices/batteryStorage.d.ts.map +0 -1
  113. package/dist/devices/batteryStorage.js.map +0 -1
  114. package/dist/devices/cooktop.d.ts +0 -61
  115. package/dist/devices/cooktop.d.ts.map +0 -1
  116. package/dist/devices/cooktop.js.map +0 -1
  117. package/dist/devices/dishwasher.d.ts +0 -71
  118. package/dist/devices/dishwasher.d.ts.map +0 -1
  119. package/dist/devices/dishwasher.js.map +0 -1
  120. package/dist/devices/evse.d.ts +0 -76
  121. package/dist/devices/evse.d.ts.map +0 -1
  122. package/dist/devices/evse.js.map +0 -1
  123. package/dist/devices/export.d.ts +0 -17
  124. package/dist/devices/export.d.ts.map +0 -1
  125. package/dist/devices/export.js.map +0 -1
  126. package/dist/devices/extractorHood.d.ts +0 -46
  127. package/dist/devices/extractorHood.d.ts.map +0 -1
  128. package/dist/devices/extractorHood.js.map +0 -1
  129. package/dist/devices/heatPump.d.ts +0 -47
  130. package/dist/devices/heatPump.d.ts.map +0 -1
  131. package/dist/devices/heatPump.js.map +0 -1
  132. package/dist/devices/laundryDryer.d.ts +0 -67
  133. package/dist/devices/laundryDryer.d.ts.map +0 -1
  134. package/dist/devices/laundryDryer.js.map +0 -1
  135. package/dist/devices/laundryWasher.d.ts +0 -81
  136. package/dist/devices/laundryWasher.d.ts.map +0 -1
  137. package/dist/devices/laundryWasher.js.map +0 -1
  138. package/dist/devices/microwaveOven.d.ts +0 -168
  139. package/dist/devices/microwaveOven.d.ts.map +0 -1
  140. package/dist/devices/microwaveOven.js.map +0 -1
  141. package/dist/devices/oven.d.ts +0 -105
  142. package/dist/devices/oven.d.ts.map +0 -1
  143. package/dist/devices/oven.js.map +0 -1
  144. package/dist/devices/refrigerator.d.ts +0 -118
  145. package/dist/devices/refrigerator.d.ts.map +0 -1
  146. package/dist/devices/refrigerator.js.map +0 -1
  147. package/dist/devices/roboticVacuumCleaner.d.ts +0 -112
  148. package/dist/devices/roboticVacuumCleaner.d.ts.map +0 -1
  149. package/dist/devices/roboticVacuumCleaner.js.map +0 -1
  150. package/dist/devices/solarPower.d.ts +0 -40
  151. package/dist/devices/solarPower.d.ts.map +0 -1
  152. package/dist/devices/solarPower.js.map +0 -1
  153. package/dist/devices/speaker.d.ts +0 -87
  154. package/dist/devices/speaker.d.ts.map +0 -1
  155. package/dist/devices/speaker.js.map +0 -1
  156. package/dist/devices/temperatureControl.d.ts +0 -166
  157. package/dist/devices/temperatureControl.d.ts.map +0 -1
  158. package/dist/devices/temperatureControl.js.map +0 -1
  159. package/dist/devices/waterHeater.d.ts +0 -111
  160. package/dist/devices/waterHeater.d.ts.map +0 -1
  161. package/dist/devices/waterHeater.js.map +0 -1
  162. package/dist/dgram/coap.d.ts +0 -205
  163. package/dist/dgram/coap.d.ts.map +0 -1
  164. package/dist/dgram/coap.js.map +0 -1
  165. package/dist/dgram/dgram.d.ts +0 -141
  166. package/dist/dgram/dgram.d.ts.map +0 -1
  167. package/dist/dgram/dgram.js.map +0 -1
  168. package/dist/dgram/mb_coap.d.ts +0 -24
  169. package/dist/dgram/mb_coap.d.ts.map +0 -1
  170. package/dist/dgram/mb_coap.js.map +0 -1
  171. package/dist/dgram/mb_mdns.d.ts +0 -24
  172. package/dist/dgram/mb_mdns.d.ts.map +0 -1
  173. package/dist/dgram/mb_mdns.js.map +0 -1
  174. package/dist/dgram/mdns.d.ts +0 -290
  175. package/dist/dgram/mdns.d.ts.map +0 -1
  176. package/dist/dgram/mdns.js.map +0 -1
  177. package/dist/dgram/multicast.d.ts +0 -67
  178. package/dist/dgram/multicast.d.ts.map +0 -1
  179. package/dist/dgram/multicast.js.map +0 -1
  180. package/dist/dgram/unicast.d.ts +0 -56
  181. package/dist/dgram/unicast.d.ts.map +0 -1
  182. package/dist/dgram/unicast.js.map +0 -1
  183. package/dist/frontend.d.ts +0 -238
  184. package/dist/frontend.d.ts.map +0 -1
  185. package/dist/frontend.js.map +0 -1
  186. package/dist/frontendTypes.d.ts +0 -529
  187. package/dist/frontendTypes.d.ts.map +0 -1
  188. package/dist/frontendTypes.js.map +0 -1
  189. package/dist/helpers.d.ts +0 -48
  190. package/dist/helpers.d.ts.map +0 -1
  191. package/dist/helpers.js.map +0 -1
  192. package/dist/index.d.ts +0 -34
  193. package/dist/index.d.ts.map +0 -1
  194. package/dist/index.js.map +0 -1
  195. package/dist/jestutils/export.d.ts +0 -2
  196. package/dist/jestutils/export.d.ts.map +0 -1
  197. package/dist/jestutils/export.js.map +0 -1
  198. package/dist/jestutils/jestHelpers.d.ts +0 -345
  199. package/dist/jestutils/jestHelpers.d.ts.map +0 -1
  200. package/dist/jestutils/jestHelpers.js.map +0 -1
  201. package/dist/logger/export.d.ts +0 -2
  202. package/dist/logger/export.d.ts.map +0 -1
  203. package/dist/logger/export.js.map +0 -1
  204. package/dist/matter/behaviors.d.ts +0 -2
  205. package/dist/matter/behaviors.d.ts.map +0 -1
  206. package/dist/matter/behaviors.js.map +0 -1
  207. package/dist/matter/clusters.d.ts +0 -2
  208. package/dist/matter/clusters.d.ts.map +0 -1
  209. package/dist/matter/clusters.js.map +0 -1
  210. package/dist/matter/devices.d.ts +0 -2
  211. package/dist/matter/devices.d.ts.map +0 -1
  212. package/dist/matter/devices.js.map +0 -1
  213. package/dist/matter/endpoints.d.ts +0 -2
  214. package/dist/matter/endpoints.d.ts.map +0 -1
  215. package/dist/matter/endpoints.js.map +0 -1
  216. package/dist/matter/export.d.ts +0 -5
  217. package/dist/matter/export.d.ts.map +0 -1
  218. package/dist/matter/export.js.map +0 -1
  219. package/dist/matter/types.d.ts +0 -3
  220. package/dist/matter/types.d.ts.map +0 -1
  221. package/dist/matter/types.js.map +0 -1
  222. package/dist/matterNode.d.ts +0 -342
  223. package/dist/matterNode.d.ts.map +0 -1
  224. package/dist/matterNode.js.map +0 -1
  225. package/dist/matterbridge.d.ts +0 -492
  226. package/dist/matterbridge.d.ts.map +0 -1
  227. package/dist/matterbridge.js.map +0 -1
  228. package/dist/matterbridgeAccessoryPlatform.d.ts +0 -41
  229. package/dist/matterbridgeAccessoryPlatform.d.ts.map +0 -1
  230. package/dist/matterbridgeAccessoryPlatform.js.map +0 -1
  231. package/dist/matterbridgeBehaviors.d.ts +0 -2404
  232. package/dist/matterbridgeBehaviors.d.ts.map +0 -1
  233. package/dist/matterbridgeBehaviors.js.map +0 -1
  234. package/dist/matterbridgeDeviceTypes.d.ts +0 -698
  235. package/dist/matterbridgeDeviceTypes.d.ts.map +0 -1
  236. package/dist/matterbridgeDeviceTypes.js.map +0 -1
  237. package/dist/matterbridgeDynamicPlatform.d.ts +0 -41
  238. package/dist/matterbridgeDynamicPlatform.d.ts.map +0 -1
  239. package/dist/matterbridgeDynamicPlatform.js.map +0 -1
  240. package/dist/matterbridgeEndpoint.d.ts +0 -1507
  241. package/dist/matterbridgeEndpoint.d.ts.map +0 -1
  242. package/dist/matterbridgeEndpoint.js.map +0 -1
  243. package/dist/matterbridgeEndpointHelpers.d.ts +0 -787
  244. package/dist/matterbridgeEndpointHelpers.d.ts.map +0 -1
  245. package/dist/matterbridgeEndpointHelpers.js.map +0 -1
  246. package/dist/matterbridgeEndpointTypes.d.ts +0 -166
  247. package/dist/matterbridgeEndpointTypes.d.ts.map +0 -1
  248. package/dist/matterbridgeEndpointTypes.js.map +0 -1
  249. package/dist/matterbridgePlatform.d.ts +0 -539
  250. package/dist/matterbridgePlatform.d.ts.map +0 -1
  251. package/dist/matterbridgePlatform.js.map +0 -1
  252. package/dist/matterbridgeTypes.d.ts +0 -251
  253. package/dist/matterbridgeTypes.d.ts.map +0 -1
  254. package/dist/matterbridgeTypes.js.map +0 -1
  255. package/dist/pluginManager.d.ts +0 -372
  256. package/dist/pluginManager.d.ts.map +0 -1
  257. package/dist/pluginManager.js.map +0 -1
  258. package/dist/shelly.d.ts +0 -181
  259. package/dist/shelly.d.ts.map +0 -1
  260. package/dist/shelly.js.map +0 -1
  261. package/dist/storage/export.d.ts +0 -2
  262. package/dist/storage/export.d.ts.map +0 -1
  263. package/dist/storage/export.js.map +0 -1
  264. package/dist/update.d.ts +0 -84
  265. package/dist/update.d.ts.map +0 -1
  266. package/dist/update.js.map +0 -1
  267. package/dist/utils/colorUtils.d.ts +0 -101
  268. package/dist/utils/colorUtils.d.ts.map +0 -1
  269. package/dist/utils/colorUtils.js.map +0 -1
  270. package/dist/utils/commandLine.d.ts +0 -66
  271. package/dist/utils/commandLine.d.ts.map +0 -1
  272. package/dist/utils/commandLine.js.map +0 -1
  273. package/dist/utils/copyDirectory.d.ts +0 -35
  274. package/dist/utils/copyDirectory.d.ts.map +0 -1
  275. package/dist/utils/copyDirectory.js.map +0 -1
  276. package/dist/utils/createDirectory.d.ts +0 -34
  277. package/dist/utils/createDirectory.d.ts.map +0 -1
  278. package/dist/utils/createDirectory.js.map +0 -1
  279. package/dist/utils/createZip.d.ts +0 -39
  280. package/dist/utils/createZip.d.ts.map +0 -1
  281. package/dist/utils/createZip.js.map +0 -1
  282. package/dist/utils/deepCopy.d.ts +0 -32
  283. package/dist/utils/deepCopy.d.ts.map +0 -1
  284. package/dist/utils/deepCopy.js.map +0 -1
  285. package/dist/utils/deepEqual.d.ts +0 -54
  286. package/dist/utils/deepEqual.d.ts.map +0 -1
  287. package/dist/utils/deepEqual.js.map +0 -1
  288. package/dist/utils/error.d.ts +0 -45
  289. package/dist/utils/error.d.ts.map +0 -1
  290. package/dist/utils/error.js.map +0 -1
  291. package/dist/utils/export.d.ts +0 -13
  292. package/dist/utils/export.d.ts.map +0 -1
  293. package/dist/utils/export.js.map +0 -1
  294. package/dist/utils/format.d.ts +0 -53
  295. package/dist/utils/format.d.ts.map +0 -1
  296. package/dist/utils/format.js.map +0 -1
  297. package/dist/utils/hex.d.ts +0 -89
  298. package/dist/utils/hex.d.ts.map +0 -1
  299. package/dist/utils/hex.js.map +0 -1
  300. package/dist/utils/inspector.d.ts +0 -87
  301. package/dist/utils/inspector.d.ts.map +0 -1
  302. package/dist/utils/inspector.js.map +0 -1
  303. package/dist/utils/isvalid.d.ts +0 -103
  304. package/dist/utils/isvalid.d.ts.map +0 -1
  305. package/dist/utils/isvalid.js.map +0 -1
  306. package/dist/utils/network.d.ts +0 -111
  307. package/dist/utils/network.d.ts.map +0 -1
  308. package/dist/utils/network.js.map +0 -1
  309. package/dist/utils/spawn.d.ts +0 -33
  310. package/dist/utils/spawn.d.ts.map +0 -1
  311. package/dist/utils/spawn.js.map +0 -1
  312. package/dist/utils/tracker.d.ts +0 -108
  313. package/dist/utils/tracker.d.ts.map +0 -1
  314. package/dist/utils/tracker.js.map +0 -1
  315. package/dist/utils/wait.d.ts +0 -54
  316. package/dist/utils/wait.d.ts.map +0 -1
  317. package/dist/utils/wait.js.map +0 -1
  318. package/dist/workerGlobalPrefix.d.ts +0 -25
  319. package/dist/workerGlobalPrefix.d.ts.map +0 -1
  320. package/dist/workerGlobalPrefix.js.map +0 -1
  321. package/dist/workerTypes.d.ts +0 -52
  322. package/dist/workerTypes.d.ts.map +0 -1
  323. package/dist/workerTypes.js.map +0 -1
  324. package/dist/workers.d.ts +0 -69
  325. package/dist/workers.d.ts.map +0 -1
  326. package/dist/workers.js.map +0 -1
@@ -1,28 +1,4 @@
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
24
1
  import { BLUE, CYAN, db, er, GREEN, idn, MAGENTA, nf, rs } from 'node-ansi-logger';
25
- // Net imports
26
2
  import { Multicast } from './multicast.js';
27
3
  export var DnsRecordType;
28
4
  (function (DnsRecordType) {
@@ -114,7 +90,6 @@ export var DnsRecordType;
114
90
  DnsRecordType[DnsRecordType["DOA"] = 259] = "DOA";
115
91
  DnsRecordType[DnsRecordType["AMTRELAY"] = 260] = "AMTRELAY";
116
92
  DnsRecordType[DnsRecordType["ZONEVERSION"] = 261] = "ZONEVERSION";
117
- // 262-32767 are unassigned/reserved
118
93
  DnsRecordType[DnsRecordType["TA"] = 32768] = "TA";
119
94
  DnsRecordType[DnsRecordType["DLV"] = 32769] = "DLV";
120
95
  })(DnsRecordType || (DnsRecordType = {}));
@@ -128,25 +103,12 @@ export var DnsClass;
128
103
  export var DnsClassFlag;
129
104
  (function (DnsClassFlag) {
130
105
  DnsClassFlag[DnsClassFlag["FLUSH"] = 32768] = "FLUSH";
131
- // eslint-disable-next-line @typescript-eslint/no-duplicate-enum-values
132
106
  DnsClassFlag[DnsClassFlag["QU"] = 32768] = "QU";
133
107
  })(DnsClassFlag || (DnsClassFlag = {}));
134
108
  export class Mdns extends Multicast {
135
109
  deviceQueries = new Map();
136
110
  deviceResponses = new Map();
137
111
  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
- */
150
112
  constructor(name, multicastAddress, multicastPort, socketType, reuseAddr = true, interfaceName, interfaceAddress, outgoingInterfaceAddress) {
151
113
  super(name, multicastAddress, multicastPort, socketType, reuseAddr, interfaceName, interfaceAddress, outgoingInterfaceAddress);
152
114
  }
@@ -166,14 +128,14 @@ export class Mdns extends Multicast {
166
128
  this.onQuery(rinfo, result);
167
129
  }
168
130
  else {
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 */) ||
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) ||
173
135
  result.answers
174
136
  ? result.answers[0]
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 });
137
+ : undefined;
138
+ this.deviceResponses.set(rinfo.address, { rinfo, response: result, dataPTR: ptr?.type === 12 ? ptr?.data : ptr?.name });
177
139
  this.onResponse(rinfo, result);
178
140
  }
179
141
  if (this.filters.length > 0) {
@@ -197,28 +159,20 @@ export class Mdns extends Multicast {
197
159
  this.log.error(`Error decoding mDNS message: ${error instanceof Error ? error.message : error}`);
198
160
  }
199
161
  }
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
- */
208
162
  decodeMdnsMessage(msg) {
209
163
  if (msg.length < 12) {
210
164
  throw new Error('mDNS message too short');
211
165
  }
212
166
  const id = msg.readUInt16BE(0);
213
167
  const flags = msg.readUInt16BE(2);
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.
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;
222
176
  const qdCount = msg.readUInt16BE(4);
223
177
  const anCount = msg.readUInt16BE(6);
224
178
  const nsCount = msg.readUInt16BE(8);
@@ -243,7 +197,6 @@ export class Mdns extends Multicast {
243
197
  additionals: [],
244
198
  };
245
199
  let offset = 12;
246
- // Decode the question section.
247
200
  for (let i = 0; i < qdCount; i++) {
248
201
  const qnameResult = this.decodeDnsName(msg, offset);
249
202
  const qname = qnameResult.name;
@@ -254,19 +207,16 @@ export class Mdns extends Multicast {
254
207
  offset += 2;
255
208
  mdnsMessage.questions?.push({ name: qname, type: qtype, class: qclass });
256
209
  }
257
- // Decode the answer section.
258
210
  for (let i = 0; i < anCount; i++) {
259
211
  const rrResult = this.decodeResourceRecord(msg, offset);
260
212
  mdnsMessage.answers?.push(rrResult.record);
261
213
  offset = rrResult.newOffset;
262
214
  }
263
- // Decode the authority (NS) section.
264
215
  for (let i = 0; i < nsCount; i++) {
265
216
  const rrResult = this.decodeResourceRecord(msg, offset);
266
217
  mdnsMessage.authorities?.push(rrResult.record);
267
218
  offset = rrResult.newOffset;
268
219
  }
269
- // Decode the additional records section.
270
220
  for (let i = 0; i < arCount; i++) {
271
221
  const rrResult = this.decodeResourceRecord(msg, offset);
272
222
  mdnsMessage.additionals?.push(rrResult.record);
@@ -274,25 +224,15 @@ export class Mdns extends Multicast {
274
224
  }
275
225
  return mdnsMessage;
276
226
  }
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
- */
285
227
  decodeDnsName(msg, offset) {
286
228
  const labels = [];
287
229
  let jumped = false;
288
230
  let originalOffset = offset;
289
- let iterations = 0; // Prevent infinite loops
231
+ let iterations = 0;
290
232
  while (true) {
291
- // Safety guard: prevent infinite loops in malformed messages.
292
233
  if (iterations++ > 1000) {
293
234
  throw new Error('Too many iterations while decoding DNS name. Possible malformed message.');
294
235
  }
295
- // Check that offset is within buffer bounds.
296
236
  if (offset >= msg.length) {
297
237
  throw new Error('Offset exceeds buffer length while decoding DNS name.');
298
238
  }
@@ -301,9 +241,7 @@ export class Mdns extends Multicast {
301
241
  offset++;
302
242
  break;
303
243
  }
304
- // Check for pointer (first two bits are 11)
305
244
  if ((len & 0xc0) === 0xc0) {
306
- // Ensure the pointer has two bytes available.
307
245
  if (offset + 1 >= msg.length) {
308
246
  throw new Error('Incomplete pointer encountered while decoding DNS name.');
309
247
  }
@@ -316,7 +254,6 @@ export class Mdns extends Multicast {
316
254
  continue;
317
255
  }
318
256
  offset++;
319
- // Check that the label length doesn't go beyond the buffer.
320
257
  if (offset + len > msg.length) {
321
258
  throw new Error('Label length exceeds buffer bounds while decoding DNS name.');
322
259
  }
@@ -325,15 +262,6 @@ export class Mdns extends Multicast {
325
262
  }
326
263
  return { name: labels.join('.'), newOffset: jumped ? originalOffset : offset };
327
264
  }
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
- */
337
265
  encodeDnsName(name) {
338
266
  const labels = name.split('.');
339
267
  const buffers = labels.map((label) => {
@@ -341,22 +269,12 @@ export class Mdns extends Multicast {
341
269
  lenBuf.writeUInt8(label.length, 0);
342
270
  return Buffer.concat([lenBuf, Buffer.from(label)]);
343
271
  });
344
- // Append the null byte to terminate the name.
345
272
  return Buffer.concat([...buffers, Buffer.from([0])]);
346
273
  }
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
- */
354
274
  decodeResourceRecord(msg, offset) {
355
- // Decode the NAME field (which may be compressed)
356
275
  const nameResult = this.decodeDnsName(msg, offset);
357
276
  const name = nameResult.name;
358
277
  offset = nameResult.newOffset;
359
- // Read TYPE (16 bits), CLASS (16 bits), TTL (32 bits), and RDLENGTH (16 bits)
360
278
  const type = msg.readUInt16BE(offset);
361
279
  offset += 2;
362
280
  const rrclass = msg.readUInt16BE(offset);
@@ -366,14 +284,12 @@ export class Mdns extends Multicast {
366
284
  const rdlength = msg.readUInt16BE(offset);
367
285
  offset += 2;
368
286
  let data = '';
369
- if (type === 12 /* DnsRecordType.PTR */) {
370
- // PTR record (type 12): decode its RDATA as a domain name.
287
+ if (type === 12) {
371
288
  const ptrResult = this.decodeDnsName(msg, offset);
372
289
  data = ptrResult.name;
373
290
  offset += rdlength;
374
291
  }
375
- else if (type === 16 /* DnsRecordType.TXT */) {
376
- // TXT record: may consist of one or more length-prefixed strings.
292
+ else if (type === 16) {
377
293
  const txtStrings = [];
378
294
  const end = offset + rdlength;
379
295
  while (offset < end) {
@@ -385,8 +301,7 @@ export class Mdns extends Multicast {
385
301
  }
386
302
  data = txtStrings.join(', ');
387
303
  }
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.
304
+ else if (type === 33) {
390
305
  const priority = msg.readUInt16BE(offset);
391
306
  const weight = msg.readUInt16BE(offset + 2);
392
307
  const port = msg.readUInt16BE(offset + 4);
@@ -400,16 +315,13 @@ export class Mdns extends Multicast {
400
315
  });
401
316
  offset = srvTargetResult.newOffset;
402
317
  }
403
- else if (type === 1 /* DnsRecordType.A */) {
404
- // A record (type 1): an IPv4 address stored in 4 bytes.
318
+ else if (type === 1) {
405
319
  const ipBytes = msg.slice(offset, offset + 4);
406
320
  data = Array.from(ipBytes).join('.');
407
321
  offset += 4;
408
322
  }
409
- else if (type === 28 /* DnsRecordType.AAAA */) {
410
- // AAAA record (type 28): IPv6 address stored in 16 bytes.
323
+ else if (type === 28) {
411
324
  const ipBytes = msg.slice(offset, offset + 16);
412
- // Convert the 16 bytes into an IPv6 address string (colon-separated)
413
325
  const ipv6Parts = [];
414
326
  for (let i = 0; i < 16; i += 2) {
415
327
  ipv6Parts.push(ipBytes.readUInt16BE(i).toString(16));
@@ -417,14 +329,10 @@ export class Mdns extends Multicast {
417
329
  data = ipv6Parts.join(':');
418
330
  offset += 16;
419
331
  }
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)
332
+ else if (type === 47) {
424
333
  const { name: nextDomain, newOffset } = this.decodeDnsName(msg, offset);
425
334
  const nextDomainLength = newOffset - offset;
426
335
  offset = newOffset;
427
- // Calculate the remaining length for the type bit maps.
428
336
  const bitmapLength = rdlength - nextDomainLength;
429
337
  const bitmapData = msg.slice(offset, offset + bitmapLength);
430
338
  const types = [];
@@ -451,7 +359,6 @@ export class Mdns extends Multicast {
451
359
  offset += bitmapLength;
452
360
  }
453
361
  else {
454
- // Fall back
455
362
  data = msg.slice(offset, offset + rdlength).toString('hex');
456
363
  offset += rdlength;
457
364
  }
@@ -460,28 +367,19 @@ export class Mdns extends Multicast {
460
367
  newOffset: offset,
461
368
  };
462
369
  }
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
- */
472
370
  sendQuery(questions) {
473
371
  const header = Buffer.alloc(12);
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
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);
480
378
  const questionBuffers = questions.map(({ name, type: qtype, class: qclass, unicastResponse = false }) => {
481
379
  const qname = this.encodeDnsName(name);
482
380
  const qfields = Buffer.alloc(4);
483
381
  qfields.writeUInt16BE(qtype, 0);
484
- qfields.writeUInt16BE(unicastResponse ? qclass | 32768 /* DnsClassFlag.QU */ : qclass, 2);
382
+ qfields.writeUInt16BE(unicastResponse ? qclass | 32768 : qclass, 2);
485
383
  return Buffer.concat([qname, qfields]);
486
384
  });
487
385
  const query = Buffer.concat([header, ...questionBuffers]);
@@ -501,46 +399,22 @@ export class Mdns extends Multicast {
501
399
  }
502
400
  });
503
401
  }
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
- */
517
402
  sendResponse(name, rtype, rclass, ttl, rdata) {
518
- // Create a 12-byte DNS header.
519
403
  const header = Buffer.alloc(12);
520
- header.writeUInt16BE(0, 0); // ID is set to 0 in mDNS.
521
- // Set flags: QR (response) bit and AA (authoritative answer) bit.
404
+ header.writeUInt16BE(0, 0);
522
405
  header.writeUInt16BE(0x8400, 2);
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.
406
+ header.writeUInt16BE(0, 4);
407
+ header.writeUInt16BE(1, 6);
408
+ header.writeUInt16BE(0, 8);
409
+ header.writeUInt16BE(0, 10);
528
410
  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).
534
411
  const answerFixed = Buffer.alloc(10);
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.
412
+ answerFixed.writeUInt16BE(rtype, 0);
413
+ answerFixed.writeUInt16BE(rclass, 2);
414
+ answerFixed.writeUInt32BE(ttl, 4);
415
+ answerFixed.writeUInt16BE(rdata.length, 8);
540
416
  const answer = Buffer.concat([aname, answerFixed, rdata]);
541
- // Concatenate header and answer to form the complete mDNS response packet.
542
417
  const response = Buffer.concat([header, answer]);
543
- // Send the response packet via the socket.
544
418
  this.socket.send(response, 0, response.length, this.multicastPort, this.multicastAddress, (error) => {
545
419
  if (error) {
546
420
  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}`);
@@ -552,128 +426,116 @@ export class Mdns extends Multicast {
552
426
  }
553
427
  });
554
428
  }
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
- */
561
429
  dnsTypeToString(type) {
562
430
  const typeMap = {
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',
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',
653
521
  };
654
522
  return typeMap[type] ?? `TYPE${type}`;
655
523
  }
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
- */
662
524
  dnsResponseClassToString(cls) {
663
- const isFlush = !!(cls & 32768 /* DnsClassFlag.FLUSH */);
525
+ const isFlush = !!(cls & 32768);
664
526
  const baseClass = cls & 0x7fff;
665
527
  let classStr;
666
528
  switch (baseClass) {
667
- case 1 /* DnsClass.IN */:
529
+ case 1:
668
530
  classStr = 'IN';
669
531
  break;
670
- case 3 /* DnsClass.CH */:
532
+ case 3:
671
533
  classStr = 'CH';
672
534
  break;
673
- case 4 /* DnsClass.HS */:
535
+ case 4:
674
536
  classStr = 'HS';
675
537
  break;
676
- case 255 /* DnsClass.ANY */:
538
+ case 255:
677
539
  classStr = 'ANY';
678
540
  break;
679
541
  default:
@@ -681,28 +543,21 @@ export class Mdns extends Multicast {
681
543
  }
682
544
  return isFlush ? `${classStr}|FLUSH` : classStr;
683
545
  }
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
- */
691
546
  dnsQuestionClassToString(cls) {
692
- const isQU = !!(cls & 32768 /* DnsClassFlag.QU */);
547
+ const isQU = !!(cls & 32768);
693
548
  const baseClass = cls & 0x7fff;
694
549
  let classStr;
695
550
  switch (baseClass) {
696
- case 1 /* DnsClass.IN */:
551
+ case 1:
697
552
  classStr = 'IN';
698
553
  break;
699
- case 3 /* DnsClass.CH */:
554
+ case 3:
700
555
  classStr = 'CH';
701
556
  break;
702
- case 4 /* DnsClass.HS */:
557
+ case 4:
703
558
  classStr = 'HS';
704
559
  break;
705
- case 255 /* DnsClass.ANY */:
560
+ case 255:
706
561
  classStr = 'ANY';
707
562
  break;
708
563
  default:
@@ -710,11 +565,6 @@ export class Mdns extends Multicast {
710
565
  }
711
566
  return isQU ? `${classStr}|QU` : classStr;
712
567
  }
713
- /**
714
- * Logs the decoded mDNS message header.
715
- *
716
- * @param {MdnsMessage} msg - The mDNS message header object.
717
- */
718
568
  logMdnsMessage(msg) {
719
569
  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}`);
720
570
  msg.questions?.forEach((question) => {
@@ -731,14 +581,9 @@ export class Mdns extends Multicast {
731
581
  });
732
582
  this.log.info(`---\n`);
733
583
  }
734
- /**
735
- * Logs the discovered devices from the mDNS queries and responses.
736
- */
737
584
  logDevices() {
738
585
  this.log.info(`Discovered query devices: ${MAGENTA}${this.deviceQueries.size}${nf}`);
739
- // Collect devices into an array
740
586
  const deviceQueryArray = Array.from(this.deviceQueries.entries());
741
- // Sort the array by numeric value of the IP address
742
587
  deviceQueryArray.sort(([addressA], [addressB]) => {
743
588
  const partsA = addressA.split('.').map(Number);
744
589
  const partsB = addressB.split('.').map(Number);
@@ -747,17 +592,13 @@ export class Mdns extends Multicast {
747
592
  if (diff !== 0)
748
593
  return diff;
749
594
  }
750
- // istanbul ignore next
751
595
  return 0;
752
596
  });
753
- // Log the sorted devices
754
597
  deviceQueryArray.forEach(([rinfo, response]) => {
755
598
  this.log.info(`- ${MAGENTA}${rinfo}${nf} family ${BLUE}${response.rinfo.family}${nf} address ${BLUE}${response.rinfo.address}${nf} port ${BLUE}${response.rinfo.port}${nf}`);
756
599
  });
757
600
  this.log.info(`Discovered response devices: ${MAGENTA}${this.deviceResponses.size}${nf}`);
758
- // Collect devices into an array
759
601
  const deviceResponseArray = Array.from(this.deviceResponses.entries());
760
- // Sort the array by numeric value of the IP address
761
602
  deviceResponseArray.sort(([addressA], [addressB]) => {
762
603
  const partsA = addressA.split(/[:.]/).map((part) => parseInt(part, 16));
763
604
  const partsB = addressB.split(/[:.]/).map((part) => parseInt(part, 16));
@@ -766,13 +607,10 @@ export class Mdns extends Multicast {
766
607
  if (diff !== 0)
767
608
  return diff;
768
609
  }
769
- // istanbul ignore next
770
610
  return 0;
771
611
  });
772
- // Log the sorted devices
773
612
  deviceResponseArray.forEach(([rinfo, response]) => {
774
613
  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}`);
775
614
  });
776
615
  }
777
616
  }
778
- //# sourceMappingURL=mdns.js.map