matterbridge 3.4.5 → 3.4.6-dev-20251228-76bd627

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 (335) hide show
  1. package/CHANGELOG.md +12 -0
  2. package/dist/broadcastServer.js +0 -117
  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 +25 -77
  31. package/dist/dgram/mdns.js +172 -366
  32. package/dist/dgram/mdnsReflectorClient.js +79 -39
  33. package/dist/dgram/mdnsReflectorServer.js +41 -56
  34. package/dist/dgram/mdnsReflectorTypes.js +1 -24
  35. package/dist/dgram/multicast.js +1 -62
  36. package/dist/dgram/unicast.js +0 -60
  37. package/dist/frontend.js +38 -485
  38. package/dist/frontendTypes.js +0 -45
  39. package/dist/helpers.js +0 -53
  40. package/dist/index.js +0 -25
  41. package/dist/jestutils/export.js +0 -1
  42. package/dist/jestutils/jestHelpers.js +14 -371
  43. package/dist/logger/export.js +0 -1
  44. package/dist/matter/behaviors.js +0 -2
  45. package/dist/matter/clusters.js +0 -2
  46. package/dist/matter/devices.js +0 -2
  47. package/dist/matter/endpoints.js +0 -2
  48. package/dist/matter/export.js +0 -3
  49. package/dist/matter/types.js +0 -3
  50. package/dist/matterNode.js +8 -369
  51. package/dist/matterbridge.js +46 -824
  52. package/dist/matterbridgeAccessoryPlatform.js +0 -38
  53. package/dist/matterbridgeBehaviors.js +5 -68
  54. package/dist/matterbridgeDeviceTypes.js +14 -635
  55. package/dist/matterbridgeDynamicPlatform.js +0 -38
  56. package/dist/matterbridgeEndpoint.js +53 -1457
  57. package/dist/matterbridgeEndpointHelpers.js +20 -483
  58. package/dist/matterbridgeEndpointTypes.js +0 -25
  59. package/dist/matterbridgePlatform.js +1 -451
  60. package/dist/matterbridgeTypes.js +0 -26
  61. package/dist/pluginManager.js +5 -341
  62. package/dist/shelly.js +7 -178
  63. package/dist/storage/export.js +0 -1
  64. package/dist/update.js +1 -93
  65. package/dist/utils/colorUtils.js +2 -97
  66. package/dist/utils/commandLine.js +0 -60
  67. package/dist/utils/copyDirectory.js +0 -37
  68. package/dist/utils/createDirectory.js +0 -33
  69. package/dist/utils/createZip.js +2 -47
  70. package/dist/utils/deepCopy.js +0 -39
  71. package/dist/utils/deepEqual.js +1 -72
  72. package/dist/utils/error.js +0 -42
  73. package/dist/utils/export.js +0 -1
  74. package/dist/utils/format.js +0 -49
  75. package/dist/utils/hex.js +0 -124
  76. package/dist/utils/inspector.js +1 -69
  77. package/dist/utils/isvalid.js +0 -101
  78. package/dist/utils/network.js +5 -103
  79. package/dist/utils/spawn.js +1 -71
  80. package/dist/utils/tracker.js +1 -64
  81. package/dist/utils/wait.js +8 -60
  82. package/dist/workerGlobalPrefix.js +5 -37
  83. package/dist/workerTypes.js +0 -24
  84. package/dist/workers.js +4 -68
  85. package/npm-shrinkwrap.json +2 -2
  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 -143
  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 -350
  175. package/dist/dgram/mdns.d.ts.map +0 -1
  176. package/dist/dgram/mdns.js.map +0 -1
  177. package/dist/dgram/mdnsReflectorClient.d.ts +0 -39
  178. package/dist/dgram/mdnsReflectorClient.d.ts.map +0 -1
  179. package/dist/dgram/mdnsReflectorClient.js.map +0 -1
  180. package/dist/dgram/mdnsReflectorServer.d.ts +0 -54
  181. package/dist/dgram/mdnsReflectorServer.d.ts.map +0 -1
  182. package/dist/dgram/mdnsReflectorServer.js.map +0 -1
  183. package/dist/dgram/mdnsReflectorTypes.d.ts +0 -28
  184. package/dist/dgram/mdnsReflectorTypes.d.ts.map +0 -1
  185. package/dist/dgram/mdnsReflectorTypes.js.map +0 -1
  186. package/dist/dgram/multicast.d.ts +0 -67
  187. package/dist/dgram/multicast.d.ts.map +0 -1
  188. package/dist/dgram/multicast.js.map +0 -1
  189. package/dist/dgram/unicast.d.ts +0 -64
  190. package/dist/dgram/unicast.d.ts.map +0 -1
  191. package/dist/dgram/unicast.js.map +0 -1
  192. package/dist/frontend.d.ts +0 -245
  193. package/dist/frontend.d.ts.map +0 -1
  194. package/dist/frontend.js.map +0 -1
  195. package/dist/frontendTypes.d.ts +0 -529
  196. package/dist/frontendTypes.d.ts.map +0 -1
  197. package/dist/frontendTypes.js.map +0 -1
  198. package/dist/helpers.d.ts +0 -48
  199. package/dist/helpers.d.ts.map +0 -1
  200. package/dist/helpers.js.map +0 -1
  201. package/dist/index.d.ts +0 -34
  202. package/dist/index.d.ts.map +0 -1
  203. package/dist/index.js.map +0 -1
  204. package/dist/jestutils/export.d.ts +0 -2
  205. package/dist/jestutils/export.d.ts.map +0 -1
  206. package/dist/jestutils/export.js.map +0 -1
  207. package/dist/jestutils/jestHelpers.d.ts +0 -345
  208. package/dist/jestutils/jestHelpers.d.ts.map +0 -1
  209. package/dist/jestutils/jestHelpers.js.map +0 -1
  210. package/dist/logger/export.d.ts +0 -2
  211. package/dist/logger/export.d.ts.map +0 -1
  212. package/dist/logger/export.js.map +0 -1
  213. package/dist/matter/behaviors.d.ts +0 -2
  214. package/dist/matter/behaviors.d.ts.map +0 -1
  215. package/dist/matter/behaviors.js.map +0 -1
  216. package/dist/matter/clusters.d.ts +0 -2
  217. package/dist/matter/clusters.d.ts.map +0 -1
  218. package/dist/matter/clusters.js.map +0 -1
  219. package/dist/matter/devices.d.ts +0 -2
  220. package/dist/matter/devices.d.ts.map +0 -1
  221. package/dist/matter/devices.js.map +0 -1
  222. package/dist/matter/endpoints.d.ts +0 -2
  223. package/dist/matter/endpoints.d.ts.map +0 -1
  224. package/dist/matter/endpoints.js.map +0 -1
  225. package/dist/matter/export.d.ts +0 -5
  226. package/dist/matter/export.d.ts.map +0 -1
  227. package/dist/matter/export.js.map +0 -1
  228. package/dist/matter/types.d.ts +0 -3
  229. package/dist/matter/types.d.ts.map +0 -1
  230. package/dist/matter/types.js.map +0 -1
  231. package/dist/matterNode.d.ts +0 -342
  232. package/dist/matterNode.d.ts.map +0 -1
  233. package/dist/matterNode.js.map +0 -1
  234. package/dist/matterbridge.d.ts +0 -505
  235. package/dist/matterbridge.d.ts.map +0 -1
  236. package/dist/matterbridge.js.map +0 -1
  237. package/dist/matterbridgeAccessoryPlatform.d.ts +0 -41
  238. package/dist/matterbridgeAccessoryPlatform.d.ts.map +0 -1
  239. package/dist/matterbridgeAccessoryPlatform.js.map +0 -1
  240. package/dist/matterbridgeBehaviors.d.ts +0 -2404
  241. package/dist/matterbridgeBehaviors.d.ts.map +0 -1
  242. package/dist/matterbridgeBehaviors.js.map +0 -1
  243. package/dist/matterbridgeDeviceTypes.d.ts +0 -698
  244. package/dist/matterbridgeDeviceTypes.d.ts.map +0 -1
  245. package/dist/matterbridgeDeviceTypes.js.map +0 -1
  246. package/dist/matterbridgeDynamicPlatform.d.ts +0 -41
  247. package/dist/matterbridgeDynamicPlatform.d.ts.map +0 -1
  248. package/dist/matterbridgeDynamicPlatform.js.map +0 -1
  249. package/dist/matterbridgeEndpoint.d.ts +0 -1507
  250. package/dist/matterbridgeEndpoint.d.ts.map +0 -1
  251. package/dist/matterbridgeEndpoint.js.map +0 -1
  252. package/dist/matterbridgeEndpointHelpers.d.ts +0 -787
  253. package/dist/matterbridgeEndpointHelpers.d.ts.map +0 -1
  254. package/dist/matterbridgeEndpointHelpers.js.map +0 -1
  255. package/dist/matterbridgeEndpointTypes.d.ts +0 -166
  256. package/dist/matterbridgeEndpointTypes.d.ts.map +0 -1
  257. package/dist/matterbridgeEndpointTypes.js.map +0 -1
  258. package/dist/matterbridgePlatform.d.ts +0 -539
  259. package/dist/matterbridgePlatform.d.ts.map +0 -1
  260. package/dist/matterbridgePlatform.js.map +0 -1
  261. package/dist/matterbridgeTypes.d.ts +0 -252
  262. package/dist/matterbridgeTypes.d.ts.map +0 -1
  263. package/dist/matterbridgeTypes.js.map +0 -1
  264. package/dist/pluginManager.d.ts +0 -372
  265. package/dist/pluginManager.d.ts.map +0 -1
  266. package/dist/pluginManager.js.map +0 -1
  267. package/dist/shelly.d.ts +0 -181
  268. package/dist/shelly.d.ts.map +0 -1
  269. package/dist/shelly.js.map +0 -1
  270. package/dist/storage/export.d.ts +0 -2
  271. package/dist/storage/export.d.ts.map +0 -1
  272. package/dist/storage/export.js.map +0 -1
  273. package/dist/update.d.ts +0 -84
  274. package/dist/update.d.ts.map +0 -1
  275. package/dist/update.js.map +0 -1
  276. package/dist/utils/colorUtils.d.ts +0 -101
  277. package/dist/utils/colorUtils.d.ts.map +0 -1
  278. package/dist/utils/colorUtils.js.map +0 -1
  279. package/dist/utils/commandLine.d.ts +0 -66
  280. package/dist/utils/commandLine.d.ts.map +0 -1
  281. package/dist/utils/commandLine.js.map +0 -1
  282. package/dist/utils/copyDirectory.d.ts +0 -35
  283. package/dist/utils/copyDirectory.d.ts.map +0 -1
  284. package/dist/utils/copyDirectory.js.map +0 -1
  285. package/dist/utils/createDirectory.d.ts +0 -34
  286. package/dist/utils/createDirectory.d.ts.map +0 -1
  287. package/dist/utils/createDirectory.js.map +0 -1
  288. package/dist/utils/createZip.d.ts +0 -39
  289. package/dist/utils/createZip.d.ts.map +0 -1
  290. package/dist/utils/createZip.js.map +0 -1
  291. package/dist/utils/deepCopy.d.ts +0 -32
  292. package/dist/utils/deepCopy.d.ts.map +0 -1
  293. package/dist/utils/deepCopy.js.map +0 -1
  294. package/dist/utils/deepEqual.d.ts +0 -54
  295. package/dist/utils/deepEqual.d.ts.map +0 -1
  296. package/dist/utils/deepEqual.js.map +0 -1
  297. package/dist/utils/error.d.ts +0 -45
  298. package/dist/utils/error.d.ts.map +0 -1
  299. package/dist/utils/error.js.map +0 -1
  300. package/dist/utils/export.d.ts +0 -13
  301. package/dist/utils/export.d.ts.map +0 -1
  302. package/dist/utils/export.js.map +0 -1
  303. package/dist/utils/format.d.ts +0 -53
  304. package/dist/utils/format.d.ts.map +0 -1
  305. package/dist/utils/format.js.map +0 -1
  306. package/dist/utils/hex.d.ts +0 -89
  307. package/dist/utils/hex.d.ts.map +0 -1
  308. package/dist/utils/hex.js.map +0 -1
  309. package/dist/utils/inspector.d.ts +0 -87
  310. package/dist/utils/inspector.d.ts.map +0 -1
  311. package/dist/utils/inspector.js.map +0 -1
  312. package/dist/utils/isvalid.d.ts +0 -103
  313. package/dist/utils/isvalid.d.ts.map +0 -1
  314. package/dist/utils/isvalid.js.map +0 -1
  315. package/dist/utils/network.d.ts +0 -117
  316. package/dist/utils/network.d.ts.map +0 -1
  317. package/dist/utils/network.js.map +0 -1
  318. package/dist/utils/spawn.d.ts +0 -33
  319. package/dist/utils/spawn.d.ts.map +0 -1
  320. package/dist/utils/spawn.js.map +0 -1
  321. package/dist/utils/tracker.d.ts +0 -108
  322. package/dist/utils/tracker.d.ts.map +0 -1
  323. package/dist/utils/tracker.js.map +0 -1
  324. package/dist/utils/wait.d.ts +0 -54
  325. package/dist/utils/wait.d.ts.map +0 -1
  326. package/dist/utils/wait.js.map +0 -1
  327. package/dist/workerGlobalPrefix.d.ts +0 -25
  328. package/dist/workerGlobalPrefix.d.ts.map +0 -1
  329. package/dist/workerGlobalPrefix.js.map +0 -1
  330. package/dist/workerTypes.d.ts +0 -52
  331. package/dist/workerTypes.d.ts.map +0 -1
  332. package/dist/workerTypes.js.map +0 -1
  333. package/dist/workers.d.ts +0 -69
  334. package/dist/workers.d.ts.map +0 -1
  335. package/dist/workers.js.map +0 -1
@@ -1,28 +1,7 @@
1
- /**
2
- * @description This file contains the class MdnsReflectorClient.
3
- * @file src/dgram/mdnsReflectorClient.ts
4
- * @author Luca Liguori
5
- * @created 2025-12-25
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
- import { AnsiLogger, BLUE, nt } from 'node-ansi-logger';
1
+ import crypto from 'node:crypto';
2
+ import { AnsiLogger, BLUE, nt, nf } from 'node-ansi-logger';
24
3
  import { getStringArrayParameter, hasParameter } from '../utils/commandLine.js';
25
- import { Mdns } from './mdns.js';
4
+ import { isMdns, isMdnsQuery, Mdns } from './mdns.js';
26
5
  import { MDNS_MULTICAST_IPV4_ADDRESS, MDNS_MULTICAST_IPV6_ADDRESS, MDNS_MULTICAST_PORT } from './multicast.js';
27
6
  import { Unicast } from './unicast.js';
28
7
  import { MDNS_REFLECTOR_ADDRESS, MDNS_REFLECTOR_BIND_ADDRESS_IPV4, MDNS_REFLECTOR_BIND_ADDRESS_IPV6, MDNS_REFLECTOR_HOST_DOCKER, MDNS_REFLECTOR_PORT } from './mdnsReflectorTypes.js';
@@ -30,28 +9,56 @@ export class MdnsReflectorClient {
30
9
  verbose = hasParameter('v') || hasParameter('verbose');
31
10
  debug = hasParameter('d') || hasParameter('debug') || hasParameter('v') || hasParameter('verbose');
32
11
  silent = hasParameter('s') || hasParameter('silent');
33
- log = new AnsiLogger({ logName: 'MdnsReflectorClient', logTimestampFormat: 4 /* TimestampFormat.TIME_MILLIS */, logLevel: this.debug ? "debug" /* LogLevel.DEBUG */ : this.silent ? "notice" /* LogLevel.NOTICE */ : "info" /* LogLevel.INFO */ });
12
+ log = new AnsiLogger({ logName: 'MdnsReflectorClient', logTimestampFormat: 4, logLevel: this.debug ? "debug" : this.silent ? "notice" : "info" });
34
13
  mdnsIpv4 = new Mdns('mDNS udp4 Server', MDNS_MULTICAST_IPV4_ADDRESS, MDNS_MULTICAST_PORT, 'udp4', true, undefined, MDNS_REFLECTOR_BIND_ADDRESS_IPV4);
35
14
  mdnsIpv6 = new Mdns('mDNS udp6 Server', MDNS_MULTICAST_IPV6_ADDRESS, MDNS_MULTICAST_PORT, 'udp6', true, undefined, MDNS_REFLECTOR_BIND_ADDRESS_IPV6);
36
15
  unicastIpv4 = new Unicast('mDNS udp4 Reflector Client', 'udp4', false, undefined, MDNS_REFLECTOR_BIND_ADDRESS_IPV4);
37
16
  unicastIpv6 = new Unicast('mDNS udp6 Reflector Client', 'udp6', false, undefined, MDNS_REFLECTOR_BIND_ADDRESS_IPV6);
17
+ reflectedIpv4 = new Map();
18
+ reflectedIpv6 = new Map();
19
+ TTL_MS = 1500;
38
20
  constructor() {
39
21
  this.log.logNameColor = '\x1b[38;5;97m';
40
22
  this.mdnsIpv4.log.logNameColor = '\x1b[38;5;97m';
41
- this.mdnsIpv4.log.logLevel = "warn" /* LogLevel.WARN */;
23
+ if (!this.debug && !this.verbose && !this.silent)
24
+ this.mdnsIpv4.log.logLevel = "warn";
42
25
  this.mdnsIpv6.log.logNameColor = '\x1b[38;5;97m';
43
- this.mdnsIpv6.log.logLevel = "warn" /* LogLevel.WARN */;
26
+ if (!this.debug && !this.verbose && !this.silent)
27
+ this.mdnsIpv6.log.logLevel = "warn";
44
28
  this.unicastIpv4.log.logNameColor = '\x1b[38;5;97m';
45
- this.unicastIpv4.log.logLevel = "warn" /* LogLevel.WARN */;
29
+ if (!this.debug && !this.verbose && !this.silent)
30
+ this.unicastIpv4.log.logLevel = "warn";
46
31
  this.unicastIpv6.log.logNameColor = '\x1b[38;5;97m';
47
- this.unicastIpv6.log.logLevel = "warn" /* LogLevel.WARN */;
48
- // Apply filters if any
32
+ if (!this.debug && !this.verbose && !this.silent)
33
+ this.unicastIpv6.log.logLevel = "warn";
49
34
  const filters = getStringArrayParameter('filter');
50
35
  if (filters)
51
36
  this.mdnsIpv4.filters.push(...filters);
52
37
  if (filters)
53
38
  this.mdnsIpv6.filters.push(...filters);
54
39
  }
40
+ fingerprint(buf) {
41
+ return crypto.createHash('sha1').update(buf).digest('hex');
42
+ }
43
+ remember(cache, key, ttlMs) {
44
+ cache.set(key, Date.now() + ttlMs);
45
+ }
46
+ seenRecently(cache, key) {
47
+ const exp = cache.get(key);
48
+ if (!exp)
49
+ return false;
50
+ if (exp < Date.now()) {
51
+ cache.delete(key);
52
+ return false;
53
+ }
54
+ return true;
55
+ }
56
+ prune(cache) {
57
+ const now = Date.now();
58
+ for (const [k, exp] of cache)
59
+ if (exp < now)
60
+ cache.delete(k);
61
+ }
55
62
  async start() {
56
63
  this.log.notice('mDNS Reflector Client starting...');
57
64
  this.mdnsIpv4.on('error', (err) => {
@@ -84,21 +91,55 @@ export class MdnsReflectorClient {
84
91
  this.unicastIpv6.start();
85
92
  });
86
93
  await Promise.all(promises);
94
+ this.mdnsIpv4.socket.setMulticastLoopback(false);
95
+ this.mdnsIpv6.socket.setMulticastLoopback(false);
87
96
  this.mdnsIpv4.on('message', (msg, rinfo) => {
88
- this.log.notice(`Sending message from mDNS ipv4 multicast ${BLUE}${rinfo.address}${nt}:${BLUE}${rinfo.port}${nt} to unicast ipv4 reflector`);
97
+ if (this.seenRecently(this.reflectedIpv4, this.fingerprint(msg))) {
98
+ this.log.info(`Ignoring recently reflected ${isMdnsQuery(msg) ? 'query' : 'response'} message from mDNS ipv4 multicast ${BLUE}${rinfo.address}${nf}:${BLUE}${rinfo.port}${nf}`);
99
+ return;
100
+ }
101
+ this.log.notice(`Sending ${isMdnsQuery(msg) ? 'query' : 'response'} message from mDNS ipv4 multicast ${BLUE}${rinfo.address}${nt}:${BLUE}${rinfo.port}${nt} to unicast ipv4 reflector`);
89
102
  this.unicastIpv4.send(msg, MDNS_REFLECTOR_HOST_DOCKER, MDNS_REFLECTOR_PORT);
90
103
  this.unicastIpv4.send(msg, MDNS_REFLECTOR_ADDRESS, MDNS_REFLECTOR_PORT);
91
104
  });
92
105
  this.mdnsIpv6.on('message', (msg, rinfo) => {
93
- this.log.notice(`Sending message from mDNS ipv6 multicast ${BLUE}${rinfo.address}${nt}:${BLUE}${rinfo.port}${nt} to unicast ipv6 reflector`);
106
+ if (this.seenRecently(this.reflectedIpv6, this.fingerprint(msg))) {
107
+ this.log.info(`Ignoring recently reflected ${isMdnsQuery(msg) ? 'query' : 'response'} message from mDNS ipv6 multicast ${BLUE}${rinfo.address}${nf}:${BLUE}${rinfo.port}${nf}`);
108
+ return;
109
+ }
110
+ this.log.notice(`Sending ${isMdnsQuery(msg) ? 'query' : 'response'} message from mDNS ipv6 multicast ${BLUE}${rinfo.address}${nt}:${BLUE}${rinfo.port}${nt} to unicast ipv6 reflector`);
94
111
  this.unicastIpv6.send(msg, MDNS_REFLECTOR_HOST_DOCKER, MDNS_REFLECTOR_PORT);
95
112
  this.unicastIpv6.send(msg, MDNS_REFLECTOR_ADDRESS, MDNS_REFLECTOR_PORT);
96
113
  });
97
114
  this.unicastIpv4.on('message', (msg, rinfo) => {
98
- this.log.notice(`Received message from unicast reflector on ipv4 ${BLUE}${rinfo.address}${nt}:${BLUE}${rinfo.port}${nt}: ${msg.toString()}`);
115
+ if (isMdns(msg)) {
116
+ this.remember(this.reflectedIpv4, this.fingerprint(msg), this.TTL_MS);
117
+ this.prune(this.reflectedIpv4);
118
+ this.log.notice(`Reflecting ${isMdnsQuery(msg) ? 'query' : 'response'} message from reflector on ipv4 ${BLUE}${rinfo.address}${nt}:${BLUE}${rinfo.port}${nt} to mDNS ipv4 multicast`);
119
+ this.mdnsIpv4.send(msg, MDNS_MULTICAST_IPV4_ADDRESS, MDNS_MULTICAST_PORT);
120
+ if (hasParameter('localhost')) {
121
+ this.log.notice(`Reflecting ${isMdnsQuery(msg) ? 'query' : 'response'} message from reflector on ipv4 ${BLUE}${rinfo.address}${nt}:${BLUE}${rinfo.port}${nt} to mDNS ipv4 localhost`);
122
+ this.mdnsIpv4.send(msg, 'localhost', MDNS_MULTICAST_PORT);
123
+ }
124
+ }
125
+ else {
126
+ this.log.info(`Received message from unicast reflector on ipv4 ${BLUE}${rinfo.address}${nf}:${BLUE}${rinfo.port}${nf}: ${msg.toString()}`);
127
+ }
99
128
  });
100
129
  this.unicastIpv6.on('message', (msg, rinfo) => {
101
- this.log.notice(`Received message from unicast reflector on ipv6 ${BLUE}${rinfo.address}${nt}:${BLUE}${rinfo.port}${nt}: ${msg.toString()}`);
130
+ if (isMdns(msg)) {
131
+ this.remember(this.reflectedIpv6, this.fingerprint(msg), this.TTL_MS);
132
+ this.prune(this.reflectedIpv6);
133
+ this.log.notice(`Reflecting ${isMdnsQuery(msg) ? 'query' : 'response'} message from reflector on ipv6 ${BLUE}${rinfo.address}${nt}:${BLUE}${rinfo.port}${nt} to mDNS ipv6 multicast`);
134
+ this.mdnsIpv6.send(msg, MDNS_MULTICAST_IPV6_ADDRESS, MDNS_MULTICAST_PORT);
135
+ if (hasParameter('localhost')) {
136
+ this.log.notice(`Reflecting ${isMdnsQuery(msg) ? 'query' : 'response'} message from reflector on ipv6 ${BLUE}${rinfo.address}${nt}:${BLUE}${rinfo.port}${nt} to mDNS ipv6 localhost`);
137
+ this.mdnsIpv6.send(msg, 'localhost', MDNS_MULTICAST_PORT);
138
+ }
139
+ }
140
+ else {
141
+ this.log.info(`Received message from unicast reflector on ipv6 ${BLUE}${rinfo.address}${nf}:${BLUE}${rinfo.port}${nf}: ${msg.toString()}`);
142
+ }
102
143
  });
103
144
  this.log.notice('mDNS Reflector Client started.');
104
145
  }
@@ -106,19 +147,19 @@ export class MdnsReflectorClient {
106
147
  this.log.notice('mDNS Reflector Client stopping...');
107
148
  const promises = [];
108
149
  promises[0] = new Promise((resolve) => {
109
- this.mdnsIpv4.once('closed', () => resolve());
150
+ this.mdnsIpv4.once('close', () => resolve());
110
151
  this.mdnsIpv4.stop();
111
152
  });
112
153
  promises[1] = new Promise((resolve) => {
113
- this.mdnsIpv6.once('closed', () => resolve());
154
+ this.mdnsIpv6.once('close', () => resolve());
114
155
  this.mdnsIpv6.stop();
115
156
  });
116
157
  promises[2] = new Promise((resolve) => {
117
- this.unicastIpv4.once('closed', () => resolve());
158
+ this.unicastIpv4.once('close', () => resolve());
118
159
  this.unicastIpv4.stop();
119
160
  });
120
161
  promises[3] = new Promise((resolve) => {
121
- this.unicastIpv6.once('closed', () => resolve());
162
+ this.unicastIpv6.once('close', () => resolve());
122
163
  this.unicastIpv6.stop();
123
164
  });
124
165
  await Promise.all(promises);
@@ -129,4 +170,3 @@ export class MdnsReflectorClient {
129
170
  this.log.notice('mDNS Reflector Client stopped.');
130
171
  }
131
172
  }
132
- //# sourceMappingURL=mdnsReflectorClient.js.map
@@ -1,29 +1,7 @@
1
- /**
2
- * @description This file contains the class MdnsReflectorServer.
3
- * @file src/dgram/mdnsReflectorServer.ts
4
- * @author Luca Liguori
5
- * @created 2025-12-25
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
1
  import os from 'node:os';
24
2
  import { AnsiLogger, BLUE, nt } from 'node-ansi-logger';
25
3
  import { hasParameter, getStringArrayParameter } from '../utils/commandLine.js';
26
- import { Mdns } from './mdns.js';
4
+ import { isMdns, isMdnsQuery, isMdnsResponse, Mdns } from './mdns.js';
27
5
  import { MDNS_MULTICAST_IPV4_ADDRESS, MDNS_MULTICAST_IPV6_ADDRESS, MDNS_MULTICAST_PORT } from './multicast.js';
28
6
  import { Unicast } from './unicast.js';
29
7
  import { MDNS_REFLECTOR_BIND_ADDRESS_IPV4, MDNS_REFLECTOR_BIND_ADDRESS_IPV6, MDNS_REFLECTOR_PORT } from './mdnsReflectorTypes.js';
@@ -31,7 +9,7 @@ export class MdnsReflectorServer {
31
9
  verbose = hasParameter('v') || hasParameter('verbose');
32
10
  debug = hasParameter('d') || hasParameter('debug') || hasParameter('v') || hasParameter('verbose');
33
11
  silent = hasParameter('s') || hasParameter('silent');
34
- log = new AnsiLogger({ logName: 'MdnsReflectorServer', logTimestampFormat: 4 /* TimestampFormat.TIME_MILLIS */, logLevel: this.debug ? "debug" /* LogLevel.DEBUG */ : this.silent ? "notice" /* LogLevel.NOTICE */ : "info" /* LogLevel.INFO */ });
12
+ log = new AnsiLogger({ logName: 'MdnsReflectorServer', logTimestampFormat: 4, logLevel: this.debug ? "debug" : this.silent ? "notice" : "info" });
35
13
  mdnsIpv4 = new Mdns('mDNS udp4 Server', MDNS_MULTICAST_IPV4_ADDRESS, MDNS_MULTICAST_PORT, 'udp4', true, undefined, MDNS_REFLECTOR_BIND_ADDRESS_IPV4);
36
14
  mdnsIpv6 = new Mdns('mDNS udp6 Server', MDNS_MULTICAST_IPV6_ADDRESS, MDNS_MULTICAST_PORT, 'udp6', true, undefined, MDNS_REFLECTOR_BIND_ADDRESS_IPV6);
37
15
  unicastIpv4 = new Unicast('mDNS udp4 Reflector Server', 'udp4', true, undefined, MDNS_REFLECTOR_BIND_ADDRESS_IPV4, MDNS_REFLECTOR_PORT);
@@ -41,14 +19,17 @@ export class MdnsReflectorServer {
41
19
  constructor() {
42
20
  this.log.logNameColor = '\x1b[38;5;115m';
43
21
  this.mdnsIpv4.log.logNameColor = '\x1b[38;5;115m';
44
- this.mdnsIpv4.log.logLevel = "warn" /* LogLevel.WARN */;
22
+ if (!this.debug && !this.verbose && !this.silent)
23
+ this.mdnsIpv4.log.logLevel = "warn";
45
24
  this.mdnsIpv6.log.logNameColor = '\x1b[38;5;115m';
46
- this.mdnsIpv6.log.logLevel = "warn" /* LogLevel.WARN */;
25
+ if (!this.debug && !this.verbose && !this.silent)
26
+ this.mdnsIpv6.log.logLevel = "warn";
47
27
  this.unicastIpv4.log.logNameColor = '\x1b[38;5;115m';
48
- this.unicastIpv4.log.logLevel = "warn" /* LogLevel.WARN */;
28
+ if (!this.debug && !this.verbose && !this.silent)
29
+ this.unicastIpv4.log.logLevel = "warn";
49
30
  this.unicastIpv6.log.logNameColor = '\x1b[38;5;115m';
50
- this.unicastIpv6.log.logLevel = "warn" /* LogLevel.WARN */;
51
- // Apply filters if any
31
+ if (!this.debug && !this.verbose && !this.silent)
32
+ this.unicastIpv6.log.logLevel = "warn";
52
33
  const filters = getStringArrayParameter('filter');
53
34
  if (filters)
54
35
  this.mdnsIpv4.filters.push(...filters);
@@ -66,18 +47,7 @@ export class MdnsReflectorServer {
66
47
  mdns.log.error(`Error getting broadcast address: ${error.message}`);
67
48
  }
68
49
  }
69
- /**
70
- * Decode and upgrade the A and AAAA records from Docker environment to point the host machine.
71
- * Matterbridge running inside Docker Desktop containers register mDNS records with the container's IP address,
72
- * which is not reachable from outside the Docker network.
73
- * To make these services reachable, we need to upgrade the A and AAAA records using the host machine IP addresses.
74
- * The reflector server runs on the host, while mDNS advertisements come from containers.
75
- *
76
- * @param {Buffer<ArrayBufferLike>} msg - The mDNS message buffer.
77
- * @returns {Buffer<ArrayBufferLike>} The upgraded mDNS message buffer.
78
- */
79
50
  upgradeAddress(msg) {
80
- // Safety: if it's not even a DNS header, do nothing.
81
51
  if (!msg || msg.length < 12)
82
52
  return msg;
83
53
  const preferredInterfaceName = this.mdnsIpv4.interfaceName ?? this.mdnsIpv6.interfaceName;
@@ -113,7 +83,6 @@ export class MdnsReflectorServer {
113
83
  this.log.info(`**UpgradeAddress Host IPv6 for address upgrade: ${hostIpv6List.length > 0 ? hostIpv6List.join(', ') : 'N/A'}`);
114
84
  if (!hostIpv4 && hostIpv6List.length === 0)
115
85
  return msg;
116
- // Copy the message so callers can safely re-use the original buffer.
117
86
  const upgradedMsg = Buffer.from(msg);
118
87
  const qdCount = upgradedMsg.readUInt16BE(4);
119
88
  const anCount = upgradedMsg.readUInt16BE(6);
@@ -121,11 +90,9 @@ export class MdnsReflectorServer {
121
90
  const arCount = upgradedMsg.readUInt16BE(10);
122
91
  let offset = 12;
123
92
  try {
124
- // Skip questions
125
93
  for (let i = 0; i < qdCount; i++) {
126
94
  const qnameResult = this.mdnsIpv4.decodeDnsName(upgradedMsg, offset);
127
95
  offset = qnameResult.newOffset;
128
- // QTYPE + QCLASS
129
96
  offset += 4;
130
97
  if (offset > upgradedMsg.length)
131
98
  return msg;
@@ -141,9 +108,7 @@ export class MdnsReflectorServer {
141
108
  return;
142
109
  const type = upgradedMsg.readUInt16BE(offset);
143
110
  offset += 2;
144
- // class (unused)
145
111
  offset += 2;
146
- // ttl (unused)
147
112
  offset += 4;
148
113
  const rdlength = upgradedMsg.readUInt16BE(offset);
149
114
  offset += 2;
@@ -151,10 +116,10 @@ export class MdnsReflectorServer {
151
116
  const endOfRdata = rdataOffset + rdlength;
152
117
  if (endOfRdata > upgradedMsg.length)
153
118
  return;
154
- if (type === 1 /* DnsRecordType.A */ && rdlength === 4 && hostA) {
119
+ if (type === 1 && rdlength === 4 && hostA) {
155
120
  hostA.copy(upgradedMsg, rdataOffset);
156
121
  }
157
- else if (type === 28 /* DnsRecordType.AAAA */ && rdlength === 16 && hostAAAAs.length > 0) {
122
+ else if (type === 28 && rdlength === 16 && hostAAAAs.length > 0) {
158
123
  const hostAAAA = hostAAAAs[Math.min(hostAAAAIndex, hostAAAAs.length - 1)];
159
124
  hostAAAA.copy(upgradedMsg, rdataOffset);
160
125
  hostAAAAIndex++;
@@ -162,7 +127,6 @@ export class MdnsReflectorServer {
162
127
  offset = endOfRdata;
163
128
  }
164
129
  };
165
- // Walk RR sections and patch A/AAAA in-place.
166
130
  upgradeResourceRecords(anCount);
167
131
  upgradeResourceRecords(nsCount);
168
132
  upgradeResourceRecords(arCount);
@@ -217,10 +181,30 @@ export class MdnsReflectorServer {
217
181
  this.unicastIpv6.start();
218
182
  });
219
183
  await Promise.all(promises);
184
+ this.mdnsIpv4.socket.setMulticastLoopback(false);
185
+ this.mdnsIpv6.socket.setMulticastLoopback(false);
186
+ this.mdnsIpv4.on('message', (msg, rinfo) => {
187
+ if (this.ipv4Clients.size === 0)
188
+ return;
189
+ this.log.notice(`Sending ${isMdnsQuery(msg) ? 'query' : 'response'} message from mDNS ipv4 multicast ${BLUE}${rinfo.address}${nt}:${BLUE}${rinfo.port}${nt} to ${this.ipv4Clients.size} ipv4 reflector clients`);
190
+ for (const client of this.ipv4Clients.values()) {
191
+ this.unicastIpv4.send(msg, client.address, client.port);
192
+ }
193
+ });
194
+ this.mdnsIpv6.on('message', (msg, rinfo) => {
195
+ if (this.ipv6Clients.size === 0)
196
+ return;
197
+ this.log.notice(`Sending ${isMdnsQuery(msg) ? 'query' : 'response'} message from mDNS ipv6 multicast ${BLUE}${rinfo.address}${nt}:${BLUE}${rinfo.port}${nt} to ${this.ipv6Clients.size} ipv6 reflector clients`);
198
+ for (const client of this.ipv6Clients.values()) {
199
+ this.unicastIpv6.send(msg, client.address, client.port);
200
+ }
201
+ });
220
202
  this.unicastIpv4.on('message', (msg, rinfo) => {
221
203
  this.ipv4Clients.set(`${rinfo.address}:${rinfo.port}`, rinfo);
204
+ if (!isMdns(msg))
205
+ return;
222
206
  this.log.notice(`Reflecting message from unicast client ipv4 ${BLUE}${rinfo.address}${nt}:${BLUE}${rinfo.port}${nt} to mDNS ipv4 multicast`);
223
- const upgradedMsg = this.upgradeAddress(msg);
207
+ const upgradedMsg = isMdnsResponse(msg) ? this.upgradeAddress(msg) : msg;
224
208
  this.mdnsIpv4.send(upgradedMsg, MDNS_MULTICAST_IPV4_ADDRESS, MDNS_MULTICAST_PORT);
225
209
  if (hasParameter('broadcast')) {
226
210
  const broadcastAddress = this.getBroadcastAddress(this.mdnsIpv4);
@@ -237,8 +221,10 @@ export class MdnsReflectorServer {
237
221
  });
238
222
  this.unicastIpv6.on('message', (msg, rinfo) => {
239
223
  this.ipv6Clients.set(`${rinfo.address}:${rinfo.port}`, rinfo);
224
+ if (!isMdns(msg))
225
+ return;
240
226
  this.log.notice(`Reflecting message from unicast client ipv6 ${BLUE}${rinfo.address}${nt}:${BLUE}${rinfo.port}${nt} to mDNS ipv6 multicast`);
241
- const upgradedMsg = this.upgradeAddress(msg);
227
+ const upgradedMsg = isMdnsResponse(msg) ? this.upgradeAddress(msg) : msg;
242
228
  this.mdnsIpv6.send(upgradedMsg, MDNS_MULTICAST_IPV6_ADDRESS, MDNS_MULTICAST_PORT);
243
229
  if (hasParameter('broadcast')) {
244
230
  const broadcastAddress = this.getBroadcastAddress(this.mdnsIpv6);
@@ -265,22 +251,22 @@ export class MdnsReflectorServer {
265
251
  this.log.debug(`Notifying ipv6 client ${client.address}:${client.port} about server stopping`);
266
252
  this.unicastIpv6.send(Buffer.from('mDNS Reflector Server is stopping'), client.address, client.port);
267
253
  }
268
- await new Promise((resolve) => setTimeout(resolve, 100)); // Wait a bit to allow messages to be sent
254
+ await new Promise((resolve) => setTimeout(resolve, 100));
269
255
  const promises = [];
270
256
  promises[0] = new Promise((resolve) => {
271
- this.mdnsIpv4.once('closed', () => resolve());
257
+ this.mdnsIpv4.once('close', () => resolve());
272
258
  this.mdnsIpv4.stop();
273
259
  });
274
260
  promises[1] = new Promise((resolve) => {
275
- this.mdnsIpv6.once('closed', () => resolve());
261
+ this.mdnsIpv6.once('close', () => resolve());
276
262
  this.mdnsIpv6.stop();
277
263
  });
278
264
  promises[2] = new Promise((resolve) => {
279
- this.unicastIpv4.once('closed', () => resolve());
265
+ this.unicastIpv4.once('close', () => resolve());
280
266
  this.unicastIpv4.stop();
281
267
  });
282
268
  promises[3] = new Promise((resolve) => {
283
- this.unicastIpv6.once('closed', () => resolve());
269
+ this.unicastIpv6.once('close', () => resolve());
284
270
  this.unicastIpv6.stop();
285
271
  });
286
272
  await Promise.all(promises);
@@ -291,4 +277,3 @@ export class MdnsReflectorServer {
291
277
  this.log.notice('mDNS Reflector Server stopped.');
292
278
  }
293
279
  }
294
- //# sourceMappingURL=mdnsReflectorServer.js.map
@@ -1,28 +1,5 @@
1
- /**
2
- * @description This file contains the definitions for the mDNS reflector classes.
3
- * @file src/dgram/mdnsReflectorTypes.ts
4
- * @author Luca Liguori
5
- * @created 2025-12-25
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
1
  export const MDNS_REFLECTOR_BIND_ADDRESS_IPV4 = '0.0.0.0';
24
2
  export const MDNS_REFLECTOR_BIND_ADDRESS_IPV6 = '::';
25
- export const MDNS_REFLECTOR_ADDRESS = 'localhost'; // Use 'localhost' to support both IPv4 and IPv6 and to avoid issues in Docker with EPERM
3
+ export const MDNS_REFLECTOR_ADDRESS = 'localhost';
26
4
  export const MDNS_REFLECTOR_HOST_DOCKER = 'host.docker.internal';
27
5
  export const MDNS_REFLECTOR_PORT = 15353;
28
- //# sourceMappingURL=mdnsReflectorTypes.js.map
@@ -1,29 +1,5 @@
1
- /**
2
- * @description This file contains the class Multicast.
3
- * @file multicast.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
1
  import os from 'node:os';
24
- // AnsiLogger imports
25
2
  import { BLUE, CYAN, db, RED, YELLOW } from 'node-ansi-logger';
26
- // Dgram imports
27
3
  import { Dgram } from './dgram.js';
28
4
  export const MDNS_MULTICAST_IPV4_ADDRESS = '224.0.0.251';
29
5
  export const MDNS_MULTICAST_IPV6_ADDRESS = 'ff02::fb';
@@ -31,37 +7,18 @@ export const MDNS_MULTICAST_PORT = 5353;
31
7
  export const COAP_MULTICAST_IPV4_ADDRESS = '224.0.1.187';
32
8
  export const COAP_MULTICAST_IPV6_ADDRESS = 'ff02::fd';
33
9
  export const COAP_MULTICAST_PORT = 5683;
34
- /**
35
- * This class implements a multicast dgram socket.
36
- */
37
10
  export class Multicast extends Dgram {
38
11
  multicastAddress;
39
12
  multicastPort;
40
13
  outgoingInterfaceAddress;
41
14
  joinedInterfaces = [];
42
- /**
43
- * Creates an instance of Multicast.
44
- *
45
- * @param {string} name - The name of the socket.
46
- * @param {string} multicastAddress - The multicast address to join.
47
- * @param {number} multicastPort - The port number to bind to.
48
- * @param {'udp4' | 'udp6'} socketType - The type of the socket (IPv4 or IPv6).
49
- * @param {boolean | undefined} reuseAddr - Whether to allow address reuse. Defaults to true.
50
- * @param {string} [interfaceName] - The name of the network interface to bind to. If provided, the interfaceAddress will be determined based on this name if not explicitly provided.
51
- * @param {string} [interfaceAddress] - The address of the network interface to bind to. If not provided, it will be determined based on the interfaceName.
52
- * @param {string} [outgoingInterfaceAddress] - The address of the outgoing network interface. If not provided, it will use the interfaceAddress.
53
- */
54
15
  constructor(name, multicastAddress, multicastPort, socketType, reuseAddr = true, interfaceName, interfaceAddress, outgoingInterfaceAddress) {
55
16
  super(name, socketType, reuseAddr, interfaceName, interfaceAddress);
56
17
  this.multicastAddress = multicastAddress;
57
18
  this.multicastPort = multicastPort;
58
19
  this.outgoingInterfaceAddress = outgoingInterfaceAddress;
59
20
  }
60
- /**
61
- * Starts the dgram multicast socket.
62
- */
63
21
  start() {
64
- // Get the local ipv4 or ipv6 address to bind to.
65
22
  if (this.socketType === 'udp4') {
66
23
  this.log.debug(`Starting ipv4 dgram multicast socket...`);
67
24
  this.interfaceAddress = this.interfaceAddress ?? this.getIpv4InterfaceAddress(this.interfaceName);
@@ -77,11 +34,6 @@ export class Multicast extends Dgram {
77
34
  this.emit('bound', address);
78
35
  });
79
36
  }
80
- /**
81
- * Event handler for the 'listening' event. This event is emitted when the socket starts listening for datagram messages.
82
- *
83
- * @param {AddressInfo} [address] - The address info.
84
- */
85
37
  onListening(address) {
86
38
  this.log.debug(`Dgram multicast socket listening on ${BLUE}${address.family}${db} ${BLUE}${address.address}${db}:${BLUE}${address.port}${db}`);
87
39
  this.socket.setBroadcast(true);
@@ -92,46 +44,39 @@ export class Multicast extends Dgram {
92
44
  this.log.debug(`Dgram multicast socket multicast TTL set to 255`);
93
45
  this.socket.setMulticastLoopback(true);
94
46
  this.log.debug(`Dgram multicast socket multicast loopback enabled`);
95
- // Find the correct network interfaces and join the multicast group on each interface. For IPv6, we will use the scope ID if available. If not available, we will use the Unique Local Address.
96
47
  Object.entries(os.networkInterfaces()).forEach(([name, interfaces]) => {
97
48
  this.log.debug(`Dgram multicast socket processing interface ${CYAN}${name}${db}`);
98
49
  if (!interfaces)
99
50
  return;
100
51
  if (this.interfaceName && name !== this.interfaceName)
101
- return; // Only process the specified interface
52
+ return;
102
53
  let iface;
103
54
  let membershipInterface;
104
- // Find the first ipv4 interface
105
55
  const ifaceIpv4 = interfaces.find((iface) => iface.family === 'IPv4' && this.socketType === 'udp4');
106
56
  if (ifaceIpv4) {
107
57
  iface = ifaceIpv4;
108
58
  membershipInterface = ifaceIpv4.address;
109
59
  }
110
- // Find the first IPv6 Address
111
60
  const ifaceIpv6 = interfaces.find((iface) => iface.family === 'IPv6' && this.socketType === 'udp6');
112
61
  if (ifaceIpv6) {
113
62
  iface = ifaceIpv6;
114
63
  membershipInterface = ifaceIpv6.address + (ifaceIpv6.scopeid !== undefined ? (process.platform === 'win32' ? '%' + String(ifaceIpv6.scopeid) : '%' + name) : '');
115
64
  }
116
- // Find the first Unique Local Address (ULA) IPv6
117
65
  const ifaceUla = interfaces.find((iface) => iface.family === 'IPv6' && this.socketType === 'udp6' && iface.address.startsWith('fd'));
118
66
  if (ifaceUla) {
119
67
  iface = ifaceUla;
120
68
  membershipInterface = ifaceUla.address + (ifaceUla.scopeid !== undefined ? (process.platform === 'win32' ? '%' + String(ifaceUla.scopeid) : '%' + name) : '');
121
69
  }
122
- // Find the first Unique Local Address (ULA) IPv6 with prefix length /64 (netmask ffff:ffff:ffff:ffff::)
123
70
  const ifaceUla64 = interfaces.find((iface) => iface.family === 'IPv6' && this.socketType === 'udp6' && iface.address.startsWith('fd') && iface.netmask === 'ffff:ffff:ffff:ffff::');
124
71
  if (ifaceUla64) {
125
72
  iface = ifaceUla64;
126
73
  membershipInterface = ifaceUla64.address + (ifaceUla64.scopeid !== undefined ? (process.platform === 'win32' ? '%' + String(ifaceUla64.scopeid) : '%' + name) : '');
127
74
  }
128
- // Find the first Link-local IPv6 Address
129
75
  const ifaceLinkLocal = interfaces.find((iface) => iface.family === 'IPv6' && this.socketType === 'udp6' && iface.address.startsWith('fe80'));
130
76
  if (ifaceLinkLocal) {
131
77
  iface = ifaceLinkLocal;
132
78
  membershipInterface = ifaceLinkLocal.address + (ifaceLinkLocal.scopeid !== undefined ? (process.platform === 'win32' ? '%' + String(ifaceLinkLocal.scopeid) : '%' + name) : '');
133
79
  }
134
- // Add the interface address to the multicast group
135
80
  if (iface && membershipInterface) {
136
81
  try {
137
82
  this.socket.addMembership(this.multicastAddress, membershipInterface);
@@ -144,11 +89,9 @@ export class Multicast extends Dgram {
144
89
  }
145
90
  });
146
91
  let interfaceAddress = this.outgoingInterfaceAddress || this.interfaceAddress;
147
- // If the interfaceAddress is 0.0.0.0, we need to set the default outgoing multicast interface to the first found IPv4 address.
148
92
  if (!this.outgoingInterfaceAddress && this.socketType === 'udp4' && this.interfaceAddress === '0.0.0.0') {
149
93
  interfaceAddress = this.getIpv4InterfaceAddress(this.interfaceName);
150
94
  }
151
- // If the interfaceAddress is '::', we need to set the default outgoing multicast interface to '::' + the scope ID.
152
95
  if (!this.outgoingInterfaceAddress && this.socketType === 'udp6' && this.interfaceAddress === '::') {
153
96
  interfaceAddress = '::' + this.getIpv6ScopeId(this.interfaceName);
154
97
  }
@@ -157,9 +100,6 @@ export class Multicast extends Dgram {
157
100
  this.log.debug(`Dgram multicast socket multicastInterface set to ${BLUE}${interfaceAddress}${db}`);
158
101
  this.emit('ready', address);
159
102
  }
160
- /**
161
- * Stops the dgram multicast socket.
162
- */
163
103
  stop() {
164
104
  this.log.debug('Stopping dgram multicast socket...');
165
105
  this.joinedInterfaces.forEach((membershipInterface) => {
@@ -176,4 +116,3 @@ export class Multicast extends Dgram {
176
116
  this.log.debug('Stopped dgram multicast socket.');
177
117
  }
178
118
  }
179
- //# sourceMappingURL=multicast.js.map