matterbridge 3.4.6 → 3.4.7-dev-20260104-6b10cee

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 (354) hide show
  1. package/CHANGELOG.md +17 -0
  2. package/README-DOCKER.md +8 -0
  3. package/dist/broadcastServer.js +0 -117
  4. package/dist/broadcastServerTypes.js +0 -24
  5. package/dist/cli.js +1 -97
  6. package/dist/cliEmitter.js +0 -37
  7. package/dist/cliHistory.js +0 -38
  8. package/dist/clusters/export.js +0 -2
  9. package/dist/deviceManager.js +1 -113
  10. package/dist/devices/airConditioner.js +0 -57
  11. package/dist/devices/batteryStorage.js +1 -48
  12. package/dist/devices/cooktop.js +0 -56
  13. package/dist/devices/dishwasher.js +0 -57
  14. package/dist/devices/evse.js +10 -74
  15. package/dist/devices/export.js +0 -5
  16. package/dist/devices/extractorHood.js +0 -43
  17. package/dist/devices/heatPump.js +2 -50
  18. package/dist/devices/laundryDryer.js +3 -62
  19. package/dist/devices/laundryWasher.js +4 -70
  20. package/dist/devices/microwaveOven.js +5 -88
  21. package/dist/devices/oven.js +0 -85
  22. package/dist/devices/refrigerator.js +0 -102
  23. package/dist/devices/roboticVacuumCleaner.js +9 -100
  24. package/dist/devices/solarPower.js +0 -38
  25. package/dist/devices/speaker.js +0 -84
  26. package/dist/devices/temperatureControl.js +3 -24
  27. package/dist/devices/waterHeater.js +2 -82
  28. package/dist/dgram/coap.js +13 -126
  29. package/dist/dgram/dgram.js +6 -114
  30. package/dist/dgram/mb_coap.js +3 -41
  31. package/dist/dgram/mb_mdns.js +23 -77
  32. package/dist/dgram/mdns.js +139 -371
  33. package/dist/dgram/mdnsReflectorClient.js +5 -71
  34. package/dist/dgram/mdnsReflectorServer.js +8 -73
  35. package/dist/dgram/mdnsReflectorTypes.js +1 -24
  36. package/dist/dgram/multicast.js +1 -62
  37. package/dist/dgram/unicast.js +0 -60
  38. package/dist/frontend.js +38 -485
  39. package/dist/frontendTypes.js +0 -45
  40. package/dist/helpers.js +0 -53
  41. package/dist/index.js +0 -25
  42. package/dist/jestutils/export.js +0 -1
  43. package/dist/jestutils/jestHelpers.js +14 -371
  44. package/dist/logger/export.js +0 -1
  45. package/dist/matter/behaviors.js +0 -2
  46. package/dist/matter/clusters.js +0 -2
  47. package/dist/matter/devices.js +0 -2
  48. package/dist/matter/endpoints.js +0 -2
  49. package/dist/matter/export.js +0 -3
  50. package/dist/matter/types.js +0 -3
  51. package/dist/matterNode.js +8 -369
  52. package/dist/matterbridge.js +46 -824
  53. package/dist/matterbridgeAccessoryPlatform.js +0 -38
  54. package/dist/matterbridgeBehaviors.js +5 -68
  55. package/dist/matterbridgeDeviceTypes.js +14 -635
  56. package/dist/matterbridgeDynamicPlatform.js +0 -38
  57. package/dist/matterbridgeEndpoint.js +53 -1457
  58. package/dist/matterbridgeEndpointHelpers.js +20 -483
  59. package/dist/matterbridgeEndpointTypes.js +0 -25
  60. package/dist/matterbridgePlatform.js +1 -451
  61. package/dist/matterbridgeTypes.js +0 -26
  62. package/dist/pluginManager.js +5 -341
  63. package/dist/shelly.js +7 -178
  64. package/dist/storage/export.js +0 -1
  65. package/dist/update.js +1 -93
  66. package/dist/utils/colorUtils.js +2 -97
  67. package/dist/utils/commandLine.js +0 -60
  68. package/dist/utils/copyDirectory.js +0 -37
  69. package/dist/utils/createDirectory.js +0 -33
  70. package/dist/utils/createZip.js +2 -47
  71. package/dist/utils/deepCopy.js +0 -39
  72. package/dist/utils/deepEqual.js +1 -72
  73. package/dist/utils/error.js +0 -42
  74. package/dist/utils/export.js +0 -1
  75. package/dist/utils/format.js +0 -49
  76. package/dist/utils/hex.js +0 -124
  77. package/dist/utils/inspector.js +1 -69
  78. package/dist/utils/isValid.js +0 -93
  79. package/dist/utils/network.js +5 -125
  80. package/dist/utils/spawn.js +1 -71
  81. package/dist/utils/tracker.js +1 -64
  82. package/dist/utils/wait.js +8 -60
  83. package/dist/workerGlobalPrefix.js +5 -37
  84. package/dist/workerTypes.js +0 -24
  85. package/dist/workers.js +4 -68
  86. package/npm-shrinkwrap.json +25 -25
  87. package/package.json +1 -2
  88. package/packages/mb-lib-test/dist/jestutils/jestHelpers.d.ts +21 -0
  89. package/packages/mb-lib-test/dist/jestutils/jestHelpers.js +77 -0
  90. package/packages/mb-lib-test/dist/module.d.ts +2 -0
  91. package/packages/mb-lib-test/dist/module.js +2 -0
  92. package/packages/mb-lib-test/dist/vitestutils/vitestHelpers.d.ts +21 -0
  93. package/packages/mb-lib-test/dist/vitestutils/vitestHelpers.js +77 -0
  94. package/packages/mb-lib-test/package.json +12 -11
  95. package/reflector/DockerDesktopSetup.png +0 -0
  96. package/reflector/Reflector.md +158 -0
  97. package/reflector/ReflectorClient.png +0 -0
  98. package/reflector/ReflectorServer.png +0 -0
  99. package/reflector/docker-compose.yml +32 -0
  100. package/reflector/mDnsPacket.png +0 -0
  101. package/dist/broadcastServer.d.ts +0 -144
  102. package/dist/broadcastServer.d.ts.map +0 -1
  103. package/dist/broadcastServer.js.map +0 -1
  104. package/dist/broadcastServerTypes.d.ts +0 -841
  105. package/dist/broadcastServerTypes.d.ts.map +0 -1
  106. package/dist/broadcastServerTypes.js.map +0 -1
  107. package/dist/cli.d.ts +0 -30
  108. package/dist/cli.d.ts.map +0 -1
  109. package/dist/cli.js.map +0 -1
  110. package/dist/cliEmitter.d.ts +0 -50
  111. package/dist/cliEmitter.d.ts.map +0 -1
  112. package/dist/cliEmitter.js.map +0 -1
  113. package/dist/cliHistory.d.ts +0 -48
  114. package/dist/cliHistory.d.ts.map +0 -1
  115. package/dist/cliHistory.js.map +0 -1
  116. package/dist/clusters/export.d.ts +0 -2
  117. package/dist/clusters/export.d.ts.map +0 -1
  118. package/dist/clusters/export.js.map +0 -1
  119. package/dist/deviceManager.d.ts +0 -135
  120. package/dist/deviceManager.d.ts.map +0 -1
  121. package/dist/deviceManager.js.map +0 -1
  122. package/dist/devices/airConditioner.d.ts +0 -98
  123. package/dist/devices/airConditioner.d.ts.map +0 -1
  124. package/dist/devices/airConditioner.js.map +0 -1
  125. package/dist/devices/batteryStorage.d.ts +0 -48
  126. package/dist/devices/batteryStorage.d.ts.map +0 -1
  127. package/dist/devices/batteryStorage.js.map +0 -1
  128. package/dist/devices/cooktop.d.ts +0 -61
  129. package/dist/devices/cooktop.d.ts.map +0 -1
  130. package/dist/devices/cooktop.js.map +0 -1
  131. package/dist/devices/dishwasher.d.ts +0 -71
  132. package/dist/devices/dishwasher.d.ts.map +0 -1
  133. package/dist/devices/dishwasher.js.map +0 -1
  134. package/dist/devices/evse.d.ts +0 -76
  135. package/dist/devices/evse.d.ts.map +0 -1
  136. package/dist/devices/evse.js.map +0 -1
  137. package/dist/devices/export.d.ts +0 -17
  138. package/dist/devices/export.d.ts.map +0 -1
  139. package/dist/devices/export.js.map +0 -1
  140. package/dist/devices/extractorHood.d.ts +0 -46
  141. package/dist/devices/extractorHood.d.ts.map +0 -1
  142. package/dist/devices/extractorHood.js.map +0 -1
  143. package/dist/devices/heatPump.d.ts +0 -47
  144. package/dist/devices/heatPump.d.ts.map +0 -1
  145. package/dist/devices/heatPump.js.map +0 -1
  146. package/dist/devices/laundryDryer.d.ts +0 -67
  147. package/dist/devices/laundryDryer.d.ts.map +0 -1
  148. package/dist/devices/laundryDryer.js.map +0 -1
  149. package/dist/devices/laundryWasher.d.ts +0 -81
  150. package/dist/devices/laundryWasher.d.ts.map +0 -1
  151. package/dist/devices/laundryWasher.js.map +0 -1
  152. package/dist/devices/microwaveOven.d.ts +0 -168
  153. package/dist/devices/microwaveOven.d.ts.map +0 -1
  154. package/dist/devices/microwaveOven.js.map +0 -1
  155. package/dist/devices/oven.d.ts +0 -105
  156. package/dist/devices/oven.d.ts.map +0 -1
  157. package/dist/devices/oven.js.map +0 -1
  158. package/dist/devices/refrigerator.d.ts +0 -118
  159. package/dist/devices/refrigerator.d.ts.map +0 -1
  160. package/dist/devices/refrigerator.js.map +0 -1
  161. package/dist/devices/roboticVacuumCleaner.d.ts +0 -112
  162. package/dist/devices/roboticVacuumCleaner.d.ts.map +0 -1
  163. package/dist/devices/roboticVacuumCleaner.js.map +0 -1
  164. package/dist/devices/solarPower.d.ts +0 -40
  165. package/dist/devices/solarPower.d.ts.map +0 -1
  166. package/dist/devices/solarPower.js.map +0 -1
  167. package/dist/devices/speaker.d.ts +0 -87
  168. package/dist/devices/speaker.d.ts.map +0 -1
  169. package/dist/devices/speaker.js.map +0 -1
  170. package/dist/devices/temperatureControl.d.ts +0 -166
  171. package/dist/devices/temperatureControl.d.ts.map +0 -1
  172. package/dist/devices/temperatureControl.js.map +0 -1
  173. package/dist/devices/waterHeater.d.ts +0 -111
  174. package/dist/devices/waterHeater.d.ts.map +0 -1
  175. package/dist/devices/waterHeater.js.map +0 -1
  176. package/dist/dgram/coap.d.ts +0 -205
  177. package/dist/dgram/coap.d.ts.map +0 -1
  178. package/dist/dgram/coap.js.map +0 -1
  179. package/dist/dgram/dgram.d.ts +0 -143
  180. package/dist/dgram/dgram.d.ts.map +0 -1
  181. package/dist/dgram/dgram.js.map +0 -1
  182. package/dist/dgram/mb_coap.d.ts +0 -24
  183. package/dist/dgram/mb_coap.d.ts.map +0 -1
  184. package/dist/dgram/mb_coap.js.map +0 -1
  185. package/dist/dgram/mb_mdns.d.ts +0 -24
  186. package/dist/dgram/mb_mdns.d.ts.map +0 -1
  187. package/dist/dgram/mb_mdns.js.map +0 -1
  188. package/dist/dgram/mdns.d.ts +0 -371
  189. package/dist/dgram/mdns.d.ts.map +0 -1
  190. package/dist/dgram/mdns.js.map +0 -1
  191. package/dist/dgram/mdnsReflectorClient.d.ts +0 -88
  192. package/dist/dgram/mdnsReflectorClient.d.ts.map +0 -1
  193. package/dist/dgram/mdnsReflectorClient.js.map +0 -1
  194. package/dist/dgram/mdnsReflectorServer.d.ts +0 -78
  195. package/dist/dgram/mdnsReflectorServer.d.ts.map +0 -1
  196. package/dist/dgram/mdnsReflectorServer.js.map +0 -1
  197. package/dist/dgram/mdnsReflectorTypes.d.ts +0 -28
  198. package/dist/dgram/mdnsReflectorTypes.d.ts.map +0 -1
  199. package/dist/dgram/mdnsReflectorTypes.js.map +0 -1
  200. package/dist/dgram/multicast.d.ts +0 -67
  201. package/dist/dgram/multicast.d.ts.map +0 -1
  202. package/dist/dgram/multicast.js.map +0 -1
  203. package/dist/dgram/unicast.d.ts +0 -64
  204. package/dist/dgram/unicast.d.ts.map +0 -1
  205. package/dist/dgram/unicast.js.map +0 -1
  206. package/dist/frontend.d.ts +0 -245
  207. package/dist/frontend.d.ts.map +0 -1
  208. package/dist/frontend.js.map +0 -1
  209. package/dist/frontendTypes.d.ts +0 -529
  210. package/dist/frontendTypes.d.ts.map +0 -1
  211. package/dist/frontendTypes.js.map +0 -1
  212. package/dist/helpers.d.ts +0 -48
  213. package/dist/helpers.d.ts.map +0 -1
  214. package/dist/helpers.js.map +0 -1
  215. package/dist/index.d.ts +0 -34
  216. package/dist/index.d.ts.map +0 -1
  217. package/dist/index.js.map +0 -1
  218. package/dist/jestutils/export.d.ts +0 -2
  219. package/dist/jestutils/export.d.ts.map +0 -1
  220. package/dist/jestutils/export.js.map +0 -1
  221. package/dist/jestutils/jestHelpers.d.ts +0 -345
  222. package/dist/jestutils/jestHelpers.d.ts.map +0 -1
  223. package/dist/jestutils/jestHelpers.js.map +0 -1
  224. package/dist/logger/export.d.ts +0 -2
  225. package/dist/logger/export.d.ts.map +0 -1
  226. package/dist/logger/export.js.map +0 -1
  227. package/dist/matter/behaviors.d.ts +0 -2
  228. package/dist/matter/behaviors.d.ts.map +0 -1
  229. package/dist/matter/behaviors.js.map +0 -1
  230. package/dist/matter/clusters.d.ts +0 -2
  231. package/dist/matter/clusters.d.ts.map +0 -1
  232. package/dist/matter/clusters.js.map +0 -1
  233. package/dist/matter/devices.d.ts +0 -2
  234. package/dist/matter/devices.d.ts.map +0 -1
  235. package/dist/matter/devices.js.map +0 -1
  236. package/dist/matter/endpoints.d.ts +0 -2
  237. package/dist/matter/endpoints.d.ts.map +0 -1
  238. package/dist/matter/endpoints.js.map +0 -1
  239. package/dist/matter/export.d.ts +0 -5
  240. package/dist/matter/export.d.ts.map +0 -1
  241. package/dist/matter/export.js.map +0 -1
  242. package/dist/matter/types.d.ts +0 -3
  243. package/dist/matter/types.d.ts.map +0 -1
  244. package/dist/matter/types.js.map +0 -1
  245. package/dist/matterNode.d.ts +0 -342
  246. package/dist/matterNode.d.ts.map +0 -1
  247. package/dist/matterNode.js.map +0 -1
  248. package/dist/matterbridge.d.ts +0 -505
  249. package/dist/matterbridge.d.ts.map +0 -1
  250. package/dist/matterbridge.js.map +0 -1
  251. package/dist/matterbridgeAccessoryPlatform.d.ts +0 -41
  252. package/dist/matterbridgeAccessoryPlatform.d.ts.map +0 -1
  253. package/dist/matterbridgeAccessoryPlatform.js.map +0 -1
  254. package/dist/matterbridgeBehaviors.d.ts +0 -2404
  255. package/dist/matterbridgeBehaviors.d.ts.map +0 -1
  256. package/dist/matterbridgeBehaviors.js.map +0 -1
  257. package/dist/matterbridgeDeviceTypes.d.ts +0 -698
  258. package/dist/matterbridgeDeviceTypes.d.ts.map +0 -1
  259. package/dist/matterbridgeDeviceTypes.js.map +0 -1
  260. package/dist/matterbridgeDynamicPlatform.d.ts +0 -41
  261. package/dist/matterbridgeDynamicPlatform.d.ts.map +0 -1
  262. package/dist/matterbridgeDynamicPlatform.js.map +0 -1
  263. package/dist/matterbridgeEndpoint.d.ts +0 -1507
  264. package/dist/matterbridgeEndpoint.d.ts.map +0 -1
  265. package/dist/matterbridgeEndpoint.js.map +0 -1
  266. package/dist/matterbridgeEndpointHelpers.d.ts +0 -787
  267. package/dist/matterbridgeEndpointHelpers.d.ts.map +0 -1
  268. package/dist/matterbridgeEndpointHelpers.js.map +0 -1
  269. package/dist/matterbridgeEndpointTypes.d.ts +0 -166
  270. package/dist/matterbridgeEndpointTypes.d.ts.map +0 -1
  271. package/dist/matterbridgeEndpointTypes.js.map +0 -1
  272. package/dist/matterbridgePlatform.d.ts +0 -539
  273. package/dist/matterbridgePlatform.d.ts.map +0 -1
  274. package/dist/matterbridgePlatform.js.map +0 -1
  275. package/dist/matterbridgeTypes.d.ts +0 -252
  276. package/dist/matterbridgeTypes.d.ts.map +0 -1
  277. package/dist/matterbridgeTypes.js.map +0 -1
  278. package/dist/pluginManager.d.ts +0 -372
  279. package/dist/pluginManager.d.ts.map +0 -1
  280. package/dist/pluginManager.js.map +0 -1
  281. package/dist/shelly.d.ts +0 -181
  282. package/dist/shelly.d.ts.map +0 -1
  283. package/dist/shelly.js.map +0 -1
  284. package/dist/storage/export.d.ts +0 -2
  285. package/dist/storage/export.d.ts.map +0 -1
  286. package/dist/storage/export.js.map +0 -1
  287. package/dist/update.d.ts +0 -84
  288. package/dist/update.d.ts.map +0 -1
  289. package/dist/update.js.map +0 -1
  290. package/dist/utils/colorUtils.d.ts +0 -101
  291. package/dist/utils/colorUtils.d.ts.map +0 -1
  292. package/dist/utils/colorUtils.js.map +0 -1
  293. package/dist/utils/commandLine.d.ts +0 -66
  294. package/dist/utils/commandLine.d.ts.map +0 -1
  295. package/dist/utils/commandLine.js.map +0 -1
  296. package/dist/utils/copyDirectory.d.ts +0 -35
  297. package/dist/utils/copyDirectory.d.ts.map +0 -1
  298. package/dist/utils/copyDirectory.js.map +0 -1
  299. package/dist/utils/createDirectory.d.ts +0 -34
  300. package/dist/utils/createDirectory.d.ts.map +0 -1
  301. package/dist/utils/createDirectory.js.map +0 -1
  302. package/dist/utils/createZip.d.ts +0 -39
  303. package/dist/utils/createZip.d.ts.map +0 -1
  304. package/dist/utils/createZip.js.map +0 -1
  305. package/dist/utils/deepCopy.d.ts +0 -32
  306. package/dist/utils/deepCopy.d.ts.map +0 -1
  307. package/dist/utils/deepCopy.js.map +0 -1
  308. package/dist/utils/deepEqual.d.ts +0 -54
  309. package/dist/utils/deepEqual.d.ts.map +0 -1
  310. package/dist/utils/deepEqual.js.map +0 -1
  311. package/dist/utils/error.d.ts +0 -45
  312. package/dist/utils/error.d.ts.map +0 -1
  313. package/dist/utils/error.js.map +0 -1
  314. package/dist/utils/export.d.ts +0 -13
  315. package/dist/utils/export.d.ts.map +0 -1
  316. package/dist/utils/export.js.map +0 -1
  317. package/dist/utils/format.d.ts +0 -53
  318. package/dist/utils/format.d.ts.map +0 -1
  319. package/dist/utils/format.js.map +0 -1
  320. package/dist/utils/hex.d.ts +0 -89
  321. package/dist/utils/hex.d.ts.map +0 -1
  322. package/dist/utils/hex.js.map +0 -1
  323. package/dist/utils/inspector.d.ts +0 -87
  324. package/dist/utils/inspector.d.ts.map +0 -1
  325. package/dist/utils/inspector.js.map +0 -1
  326. package/dist/utils/isValid.d.ts +0 -103
  327. package/dist/utils/isValid.d.ts.map +0 -1
  328. package/dist/utils/isValid.js.map +0 -1
  329. package/dist/utils/network.d.ts +0 -140
  330. package/dist/utils/network.d.ts.map +0 -1
  331. package/dist/utils/network.js.map +0 -1
  332. package/dist/utils/spawn.d.ts +0 -33
  333. package/dist/utils/spawn.d.ts.map +0 -1
  334. package/dist/utils/spawn.js.map +0 -1
  335. package/dist/utils/tracker.d.ts +0 -108
  336. package/dist/utils/tracker.d.ts.map +0 -1
  337. package/dist/utils/tracker.js.map +0 -1
  338. package/dist/utils/wait.d.ts +0 -54
  339. package/dist/utils/wait.d.ts.map +0 -1
  340. package/dist/utils/wait.js.map +0 -1
  341. package/dist/workerGlobalPrefix.d.ts +0 -25
  342. package/dist/workerGlobalPrefix.d.ts.map +0 -1
  343. package/dist/workerGlobalPrefix.js.map +0 -1
  344. package/dist/workerTypes.d.ts +0 -52
  345. package/dist/workerTypes.d.ts.map +0 -1
  346. package/dist/workerTypes.js.map +0 -1
  347. package/dist/workers.d.ts +0 -69
  348. package/dist/workers.d.ts.map +0 -1
  349. package/dist/workers.js.map +0 -1
  350. package/scripts/data_model.mjs +0 -2058
  351. package/scripts/fetch-chip.mjs +0 -102
  352. package/scripts/marked.mjs +0 -133
  353. package/scripts/markedFooter.html +0 -42
  354. package/scripts/markedHeader.html +0 -78
@@ -1,25 +1,3 @@
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.1.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 crypto from 'node:crypto';
24
2
  import { AnsiLogger, BLUE, nt, nf } from 'node-ansi-logger';
25
3
  import { getStringArrayParameter, hasParameter } from '../utils/commandLine.js';
@@ -31,7 +9,7 @@ export class MdnsReflectorClient {
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: '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" });
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 Client', 'udp4', false, undefined, MDNS_REFLECTOR_BIND_ADDRESS_IPV4);
@@ -39,62 +17,32 @@ export class MdnsReflectorClient {
39
17
  reflectedIpv4 = new Map();
40
18
  reflectedIpv6 = new Map();
41
19
  TTL_MS = 1500;
42
- /**
43
- * Creates an instance of MdnsReflectorClient.
44
- * The MdnsReflectorClient must run inside a Docker container.
45
- * The MdnsReflectorClient sends mDNS messages from the container to the MdnsReflectorServer running on the host machine.
46
- * The MdnsReflectorClient also reflects mDNS messages from the MdnsReflectorServer to the container.
47
- * Parameters:
48
- * --filter <string[]> - filters to apply to incoming mDNS messages.
49
- * --localhost - use localhost addresses to send messages to the container.
50
- */
51
20
  constructor() {
52
21
  this.log.logNameColor = '\x1b[38;5;97m';
53
22
  this.mdnsIpv4.log.logNameColor = '\x1b[38;5;97m';
54
23
  if (!this.debug && !this.verbose && !this.silent)
55
- this.mdnsIpv4.log.logLevel = "warn" /* LogLevel.WARN */;
24
+ this.mdnsIpv4.log.logLevel = "warn";
56
25
  this.mdnsIpv6.log.logNameColor = '\x1b[38;5;97m';
57
26
  if (!this.debug && !this.verbose && !this.silent)
58
- this.mdnsIpv6.log.logLevel = "warn" /* LogLevel.WARN */;
27
+ this.mdnsIpv6.log.logLevel = "warn";
59
28
  this.unicastIpv4.log.logNameColor = '\x1b[38;5;97m';
60
29
  if (!this.debug && !this.verbose && !this.silent)
61
- this.unicastIpv4.log.logLevel = "warn" /* LogLevel.WARN */;
30
+ this.unicastIpv4.log.logLevel = "warn";
62
31
  this.unicastIpv6.log.logNameColor = '\x1b[38;5;97m';
63
32
  if (!this.debug && !this.verbose && !this.silent)
64
- this.unicastIpv6.log.logLevel = "warn" /* LogLevel.WARN */;
65
- // Apply filters if any
33
+ this.unicastIpv6.log.logLevel = "warn";
66
34
  const filters = getStringArrayParameter('filter');
67
35
  if (filters)
68
36
  this.mdnsIpv4.filters.push(...filters);
69
37
  if (filters)
70
38
  this.mdnsIpv6.filters.push(...filters);
71
39
  }
72
- /**
73
- * Generates a fingerprint for a given buffer using SHA1 hash.
74
- *
75
- * @param {Buffer} buf - The buffer to generate the fingerprint for.
76
- * @returns {string} The SHA1 hash of the buffer as a hexadecimal string.
77
- */
78
40
  fingerprint(buf) {
79
41
  return crypto.createHash('sha1').update(buf).digest('hex');
80
42
  }
81
- /**
82
- * Remembers a key in the cache with a time-to-live (TTL).
83
- *
84
- * @param {RecentCache} cache - The cache to store the key in.
85
- * @param {string} key - The key to remember.
86
- * @param {number} ttlMs - The time-to-live in milliseconds.
87
- */
88
43
  remember(cache, key, ttlMs) {
89
44
  cache.set(key, Date.now() + ttlMs);
90
45
  }
91
- /**
92
- * Checks if a key has been seen recently in the cache.
93
- *
94
- * @param {RecentCache} cache - The cache to check.
95
- * @param {string} key - The key to check.
96
- * @returns {boolean} True if the key has been seen recently, false otherwise.
97
- */
98
46
  seenRecently(cache, key) {
99
47
  const exp = cache.get(key);
100
48
  if (!exp)
@@ -105,20 +53,12 @@ export class MdnsReflectorClient {
105
53
  }
106
54
  return true;
107
55
  }
108
- /**
109
- * Prunes expired entries from the cache and limits its size.
110
- *
111
- * @param {RecentCache} cache - The cache to prune.
112
- */
113
56
  prune(cache) {
114
57
  const now = Date.now();
115
58
  for (const [k, exp] of cache)
116
59
  if (exp < now)
117
60
  cache.delete(k);
118
61
  }
119
- /**
120
- * Starts the mDNS Reflector Client.
121
- */
122
62
  async start() {
123
63
  this.log.notice('mDNS Reflector Client starting...');
124
64
  this.mdnsIpv4.on('error', (err) => {
@@ -158,7 +98,6 @@ export class MdnsReflectorClient {
158
98
  this.log.info(`Ignoring recently reflected ${isMdnsQuery(msg) ? 'query' : 'response'} message from mDNS ipv4 multicast ${BLUE}${rinfo.address}${nf}:${BLUE}${rinfo.port}${nf}`);
159
99
  return;
160
100
  }
161
- // if (rinfo.address === '127.0.0.1') return; // Ignore messages coming from the reflector itself
162
101
  this.log.notice(`Sending ${isMdnsQuery(msg) ? 'query' : 'response'} message from mDNS ipv4 multicast ${BLUE}${rinfo.address}${nt}:${BLUE}${rinfo.port}${nt} to ipv4 reflector server`);
163
102
  this.unicastIpv4.send(msg, MDNS_REFLECTOR_HOST_DOCKER, MDNS_REFLECTOR_PORT);
164
103
  this.unicastIpv4.send(msg, MDNS_REFLECTOR_ADDRESS, MDNS_REFLECTOR_PORT);
@@ -168,7 +107,6 @@ export class MdnsReflectorClient {
168
107
  this.log.info(`Ignoring recently reflected ${isMdnsQuery(msg) ? 'query' : 'response'} message from mDNS ipv6 multicast ${BLUE}${rinfo.address}${nf}:${BLUE}${rinfo.port}${nf}`);
169
108
  return;
170
109
  }
171
- // if (rinfo.address === '::1') return; // Ignore messages coming from the reflector itself
172
110
  this.log.notice(`Sending ${isMdnsQuery(msg) ? 'query' : 'response'} message from mDNS ipv6 multicast ${BLUE}${rinfo.address}${nt}:${BLUE}${rinfo.port}${nt} to ipv6 reflector server`);
173
111
  this.unicastIpv6.send(msg, MDNS_REFLECTOR_HOST_DOCKER, MDNS_REFLECTOR_PORT);
174
112
  this.unicastIpv6.send(msg, MDNS_REFLECTOR_ADDRESS, MDNS_REFLECTOR_PORT);
@@ -209,9 +147,6 @@ export class MdnsReflectorClient {
209
147
  this.unicastIpv6.send(Buffer.from('Ipv6 reflector client started'), MDNS_REFLECTOR_ADDRESS, MDNS_REFLECTOR_PORT);
210
148
  this.log.notice('mDNS Reflector Client started.');
211
149
  }
212
- /**
213
- * Stops the mDNS Reflector Client.
214
- */
215
150
  async stop() {
216
151
  this.log.notice('mDNS Reflector Client stopping...');
217
152
  const promises = [];
@@ -239,4 +174,3 @@ export class MdnsReflectorClient {
239
174
  this.log.notice('mDNS Reflector Client stopped.');
240
175
  }
241
176
  }
242
- //# sourceMappingURL=mdnsReflectorClient.js.map
@@ -1,25 +1,3 @@
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.1.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, nf } from 'node-ansi-logger';
25
3
  import { hasParameter, getStringArrayParameter } from '../utils/commandLine.js';
@@ -31,52 +9,33 @@ 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);
38
16
  unicastIpv6 = new Unicast('mDNS udp6 Reflector Server', 'udp6', true, undefined, MDNS_REFLECTOR_BIND_ADDRESS_IPV6, MDNS_REFLECTOR_PORT);
39
17
  ipv4Clients = new Map();
40
18
  ipv6Clients = new Map();
41
- /**
42
- * Creates an instance of MdnsReflectorServer.
43
- * The MdnsReflectorServer must run on the host machine.
44
- * The MdnsReflectorServer reflects mDNS messages from the lan to the Ipv4 and IPv6 reflector clients running inside Docker containers.
45
- * The MdnsReflectorServer also reflects mDNS messages from the Ipv4 and IPv6 reflector clients to the lan.
46
- * The MdnsReflectorServer also upgrades the A and AAAA records from the Docker environment to point to the host machine IP addresses.
47
- * Parameters:
48
- * --filter <string[]> - filters to apply to incoming mDNS messages.
49
- * --broadcast - use broadcast addresses to reflect messages to the lan.
50
- * --localhost - use localhost addresses to reflect messages to the lan.
51
- * --share-with-clients - share messages between reflector clients.
52
- */
53
19
  constructor() {
54
20
  this.log.logNameColor = '\x1b[38;5;115m';
55
21
  this.mdnsIpv4.log.logNameColor = '\x1b[38;5;115m';
56
22
  if (!this.debug && !this.verbose && !this.silent)
57
- this.mdnsIpv4.log.logLevel = "warn" /* LogLevel.WARN */;
23
+ this.mdnsIpv4.log.logLevel = "warn";
58
24
  this.mdnsIpv6.log.logNameColor = '\x1b[38;5;115m';
59
25
  if (!this.debug && !this.verbose && !this.silent)
60
- this.mdnsIpv6.log.logLevel = "warn" /* LogLevel.WARN */;
26
+ this.mdnsIpv6.log.logLevel = "warn";
61
27
  this.unicastIpv4.log.logNameColor = '\x1b[38;5;115m';
62
28
  if (!this.debug && !this.verbose && !this.silent)
63
- this.unicastIpv4.log.logLevel = "warn" /* LogLevel.WARN */;
29
+ this.unicastIpv4.log.logLevel = "warn";
64
30
  this.unicastIpv6.log.logNameColor = '\x1b[38;5;115m';
65
31
  if (!this.debug && !this.verbose && !this.silent)
66
- this.unicastIpv6.log.logLevel = "warn" /* LogLevel.WARN */;
67
- // Apply filters if any
32
+ this.unicastIpv6.log.logLevel = "warn";
68
33
  const filters = getStringArrayParameter('filter');
69
34
  if (filters)
70
35
  this.mdnsIpv4.filters.push(...filters);
71
36
  if (filters)
72
37
  this.mdnsIpv6.filters.push(...filters);
73
38
  }
74
- /**
75
- * Get the broadcast address for the given Mdns instance.
76
- *
77
- * @param {Mdns} mdns - The Mdns instance.
78
- * @returns {string | undefined} The broadcast address or undefined if not found.
79
- */
80
39
  getBroadcastAddress(mdns) {
81
40
  try {
82
41
  const address = mdns.socketType === 'udp4' ? mdns.getIpv4InterfaceAddress(mdns.interfaceName) : mdns.getIpv6InterfaceAddress(mdns.interfaceName);
@@ -88,18 +47,7 @@ export class MdnsReflectorServer {
88
47
  mdns.log.error(`Error getting broadcast address: ${error.message}`);
89
48
  }
90
49
  }
91
- /**
92
- * Decode and upgrade the A and AAAA records from Docker environment to point the host machine.
93
- * Matterbridge running inside Docker Desktop containers register mDNS records with the container's IP address,
94
- * which is not reachable from outside the Docker network.
95
- * To make these services reachable, we need to upgrade the A and AAAA records using the host machine IP addresses.
96
- * The reflector server runs on the host, while mDNS advertisements come from containers.
97
- *
98
- * @param {Buffer<ArrayBufferLike>} msg - The mDNS message buffer.
99
- * @returns {Buffer<ArrayBufferLike>} The upgraded mDNS message buffer.
100
- */
101
50
  upgradeAddress(msg) {
102
- // Safety: if it's not even a DNS header, do nothing.
103
51
  if (!msg || msg.length < 12)
104
52
  return msg;
105
53
  const preferredInterfaceName = this.mdnsIpv4.interfaceName ?? this.mdnsIpv6.interfaceName;
@@ -135,7 +83,6 @@ export class MdnsReflectorServer {
135
83
  this.log.debug(`UpgradeAddress Host IPv6 for address upgrade: ${hostIpv6List.length > 0 ? hostIpv6List.join(', ') : 'N/A'}`);
136
84
  if (!hostIpv4 && hostIpv6List.length === 0)
137
85
  return msg;
138
- // Copy the message so callers can safely re-use the original buffer.
139
86
  const upgradedMsg = Buffer.from(msg);
140
87
  const qdCount = upgradedMsg.readUInt16BE(4);
141
88
  const anCount = upgradedMsg.readUInt16BE(6);
@@ -143,11 +90,9 @@ export class MdnsReflectorServer {
143
90
  const arCount = upgradedMsg.readUInt16BE(10);
144
91
  let offset = 12;
145
92
  try {
146
- // Skip questions
147
93
  for (let i = 0; i < qdCount; i++) {
148
94
  const qnameResult = this.mdnsIpv4.decodeDnsName(upgradedMsg, offset);
149
95
  offset = qnameResult.newOffset;
150
- // QTYPE + QCLASS
151
96
  offset += 4;
152
97
  if (offset > upgradedMsg.length)
153
98
  return msg;
@@ -163,9 +108,7 @@ export class MdnsReflectorServer {
163
108
  return;
164
109
  const type = upgradedMsg.readUInt16BE(offset);
165
110
  offset += 2;
166
- // class (unused)
167
111
  offset += 2;
168
- // ttl (unused)
169
112
  offset += 4;
170
113
  const rdlength = upgradedMsg.readUInt16BE(offset);
171
114
  offset += 2;
@@ -173,10 +116,10 @@ export class MdnsReflectorServer {
173
116
  const endOfRdata = rdataOffset + rdlength;
174
117
  if (endOfRdata > upgradedMsg.length)
175
118
  return;
176
- if (type === 1 /* DnsRecordType.A */ && rdlength === 4 && hostA) {
119
+ if (type === 1 && rdlength === 4 && hostA) {
177
120
  hostA.copy(upgradedMsg, rdataOffset);
178
121
  }
179
- else if (type === 28 /* DnsRecordType.AAAA */ && rdlength === 16 && hostAAAAs.length > 0) {
122
+ else if (type === 28 && rdlength === 16 && hostAAAAs.length > 0) {
180
123
  const hostAAAA = hostAAAAs[Math.min(hostAAAAIndex, hostAAAAs.length - 1)];
181
124
  hostAAAA.copy(upgradedMsg, rdataOffset);
182
125
  hostAAAAIndex++;
@@ -184,7 +127,6 @@ export class MdnsReflectorServer {
184
127
  offset = endOfRdata;
185
128
  }
186
129
  };
187
- // Walk RR sections and patch A/AAAA in-place.
188
130
  upgradeResourceRecords(anCount);
189
131
  upgradeResourceRecords(nsCount);
190
132
  upgradeResourceRecords(arCount);
@@ -207,9 +149,6 @@ export class MdnsReflectorServer {
207
149
  }
208
150
  return upgradedMsg;
209
151
  }
210
- /**
211
- * Starts the mDNS Reflector Server.
212
- */
213
152
  async start() {
214
153
  this.log.notice('mDNS Reflector Server starting...');
215
154
  this.mdnsIpv4.on('error', (err) => {
@@ -324,9 +263,6 @@ export class MdnsReflectorServer {
324
263
  });
325
264
  this.log.notice('mDNS Reflector Server started.');
326
265
  }
327
- /**
328
- * Stops the mDNS Reflector Server.
329
- */
330
266
  async stop() {
331
267
  this.log.notice('mDNS Reflector Server stopping...');
332
268
  for (const client of this.ipv4Clients.values()) {
@@ -337,7 +273,7 @@ export class MdnsReflectorServer {
337
273
  this.log.debug(`Notifying ipv6 client ${client.address}:${client.port} about server stopping`);
338
274
  this.unicastIpv6.send(Buffer.from('mDNS Reflector Server is stopping'), client.address, client.port);
339
275
  }
340
- await new Promise((resolve) => setTimeout(resolve, 100)); // Wait a bit to allow messages to be sent
276
+ await new Promise((resolve) => setTimeout(resolve, 100));
341
277
  const promises = [];
342
278
  promises[0] = new Promise((resolve) => {
343
279
  this.mdnsIpv4.once('close', () => resolve());
@@ -363,4 +299,3 @@ export class MdnsReflectorServer {
363
299
  this.log.notice('mDNS Reflector Server stopped.');
364
300
  }
365
301
  }
366
- //# 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
@@ -1,54 +1,12 @@
1
- /**
2
- * @description This file contains the class Unicast.
3
- * @file unicast.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, db } from 'node-ansi-logger';
25
- // Net imports
26
2
  import { Dgram } from './dgram.js';
27
- /**
28
- * This class implements a unicast dgram socket.
29
- */
30
3
  export class Unicast extends Dgram {
31
4
  port;
32
- /**
33
- * Creates an instance of Unicast.
34
- *
35
- * @param {string} name - The name of the socket.
36
- * @param {'udp4' | 'udp6'} socketType - The type of the socket (IPv4 or IPv6).
37
- * @param {boolean | undefined} reuseAddr - Whether to allow address reuse. Defaults to true.
38
- * @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.
39
- * @param {string} [interfaceAddress] - The address of the network interface to bind to. If not provided, it will be determined based on the interfaceName.
40
- * @param {number} [port] - The port number to bind to. If not provided, it will bind to any available port.
41
- */
42
5
  constructor(name, socketType, reuseAddr = true, interfaceName, interfaceAddress, port) {
43
6
  super(name, socketType, reuseAddr, interfaceName, interfaceAddress);
44
7
  this.port = port;
45
8
  }
46
- /**
47
- * Starts the dgram unicast socket.
48
- */
49
9
  start() {
50
- // Get the local ipv4 or ipv6 interfaceAddress to bind to. If not provided and interfaceName has been provided, use the first one found.
51
- // If neither interfaceAddress nor interfaceName is provided, use undefined to bind to any available address. In this case broadcast will not work.
52
10
  if (this.socketType === 'udp4') {
53
11
  this.log.debug(`Starting ipv4 dgram unicast socket...`);
54
12
  this.interfaceAddress = this.interfaceAddress ?? (this.interfaceName ? this.getIpv4InterfaceAddress(this.interfaceName) : undefined);
@@ -58,9 +16,6 @@ export class Unicast extends Dgram {
58
16
  this.interfaceAddress = this.interfaceAddress ?? (this.interfaceName ? this.getIpv6InterfaceAddress(this.interfaceName) : undefined);
59
17
  }
60
18
  this.interfaceNetmask = this.interfaceAddress ? this.getNetmask(this.interfaceAddress) : undefined;
61
- // Bind to the local address and port:
62
- // port 0 or undefined means "assign any available port"
63
- // address 0.0.0.0 or :: means "bind to all available addresses"
64
19
  this.log.debug(`Binding dgram unicast socket to ${BLUE}${this.interfaceAddress || 'all available addresses'}${db} on port ${BLUE}${this.port || 'any available port'}${db}...`);
65
20
  this.socket.bind(this.port, this.interfaceAddress, () => {
66
21
  const address = this.socket.address();
@@ -68,33 +23,18 @@ export class Unicast extends Dgram {
68
23
  this.emit('bound', address);
69
24
  });
70
25
  }
71
- /**
72
- * Event handler for the 'listening' event. This event is emitted when the socket starts listening for datagram messages.
73
- *
74
- * @param {AddressInfo} [address] - The address info.
75
- */
76
26
  onListening(address) {
77
27
  this.log.debug(`Dgram unicast socket listening on ${BLUE}${address.family}${db} ${BLUE}${address.address}${db}:${BLUE}${address.port}${db}`);
78
28
  this.socket.setBroadcast(true);
79
29
  this.log.debug(`Dgram unicast socket broadcast enabled`);
80
30
  this.emit('ready', address);
81
31
  }
82
- /**
83
- * Event handler for the 'message' event. This event is emitted when a datagram message is received.
84
- *
85
- * @param {Buffer} msg - The message buffer.
86
- * @param {RemoteInfo} rinfo - The remote info.
87
- */
88
32
  onMessage(msg, rinfo) {
89
33
  this.log.debug(`Socket received a message from ${BLUE}${rinfo.family}${db} ${BLUE}${rinfo.address}${db}:${BLUE}${rinfo.port}${db}`);
90
34
  }
91
- /**
92
- * Stops the dgram unicast socket.
93
- */
94
35
  stop() {
95
36
  this.log.debug('Stopping dgram unicast socket...');
96
37
  this.socket.close();
97
38
  this.log.debug('Stopped dgram unicast socket.');
98
39
  }
99
40
  }
100
- //# sourceMappingURL=unicast.js.map