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.
- package/CHANGELOG.md +17 -0
- package/README-DOCKER.md +8 -0
- package/dist/broadcastServer.js +0 -117
- package/dist/broadcastServerTypes.js +0 -24
- package/dist/cli.js +1 -97
- package/dist/cliEmitter.js +0 -37
- package/dist/cliHistory.js +0 -38
- package/dist/clusters/export.js +0 -2
- package/dist/deviceManager.js +1 -113
- package/dist/devices/airConditioner.js +0 -57
- package/dist/devices/batteryStorage.js +1 -48
- package/dist/devices/cooktop.js +0 -56
- package/dist/devices/dishwasher.js +0 -57
- package/dist/devices/evse.js +10 -74
- package/dist/devices/export.js +0 -5
- package/dist/devices/extractorHood.js +0 -43
- package/dist/devices/heatPump.js +2 -50
- package/dist/devices/laundryDryer.js +3 -62
- package/dist/devices/laundryWasher.js +4 -70
- package/dist/devices/microwaveOven.js +5 -88
- package/dist/devices/oven.js +0 -85
- package/dist/devices/refrigerator.js +0 -102
- package/dist/devices/roboticVacuumCleaner.js +9 -100
- package/dist/devices/solarPower.js +0 -38
- package/dist/devices/speaker.js +0 -84
- package/dist/devices/temperatureControl.js +3 -24
- package/dist/devices/waterHeater.js +2 -82
- package/dist/dgram/coap.js +13 -126
- package/dist/dgram/dgram.js +6 -114
- package/dist/dgram/mb_coap.js +3 -41
- package/dist/dgram/mb_mdns.js +23 -77
- package/dist/dgram/mdns.js +139 -371
- package/dist/dgram/mdnsReflectorClient.js +5 -71
- package/dist/dgram/mdnsReflectorServer.js +8 -73
- package/dist/dgram/mdnsReflectorTypes.js +1 -24
- package/dist/dgram/multicast.js +1 -62
- package/dist/dgram/unicast.js +0 -60
- package/dist/frontend.js +38 -485
- package/dist/frontendTypes.js +0 -45
- package/dist/helpers.js +0 -53
- package/dist/index.js +0 -25
- package/dist/jestutils/export.js +0 -1
- package/dist/jestutils/jestHelpers.js +14 -371
- package/dist/logger/export.js +0 -1
- package/dist/matter/behaviors.js +0 -2
- package/dist/matter/clusters.js +0 -2
- package/dist/matter/devices.js +0 -2
- package/dist/matter/endpoints.js +0 -2
- package/dist/matter/export.js +0 -3
- package/dist/matter/types.js +0 -3
- package/dist/matterNode.js +8 -369
- package/dist/matterbridge.js +46 -824
- package/dist/matterbridgeAccessoryPlatform.js +0 -38
- package/dist/matterbridgeBehaviors.js +5 -68
- package/dist/matterbridgeDeviceTypes.js +14 -635
- package/dist/matterbridgeDynamicPlatform.js +0 -38
- package/dist/matterbridgeEndpoint.js +53 -1457
- package/dist/matterbridgeEndpointHelpers.js +20 -483
- package/dist/matterbridgeEndpointTypes.js +0 -25
- package/dist/matterbridgePlatform.js +1 -451
- package/dist/matterbridgeTypes.js +0 -26
- package/dist/pluginManager.js +5 -341
- package/dist/shelly.js +7 -178
- package/dist/storage/export.js +0 -1
- package/dist/update.js +1 -93
- package/dist/utils/colorUtils.js +2 -97
- package/dist/utils/commandLine.js +0 -60
- package/dist/utils/copyDirectory.js +0 -37
- package/dist/utils/createDirectory.js +0 -33
- package/dist/utils/createZip.js +2 -47
- package/dist/utils/deepCopy.js +0 -39
- package/dist/utils/deepEqual.js +1 -72
- package/dist/utils/error.js +0 -42
- package/dist/utils/export.js +0 -1
- package/dist/utils/format.js +0 -49
- package/dist/utils/hex.js +0 -124
- package/dist/utils/inspector.js +1 -69
- package/dist/utils/isValid.js +0 -93
- package/dist/utils/network.js +5 -125
- package/dist/utils/spawn.js +1 -71
- package/dist/utils/tracker.js +1 -64
- package/dist/utils/wait.js +8 -60
- package/dist/workerGlobalPrefix.js +5 -37
- package/dist/workerTypes.js +0 -24
- package/dist/workers.js +4 -68
- package/npm-shrinkwrap.json +25 -25
- package/package.json +1 -2
- package/packages/mb-lib-test/dist/jestutils/jestHelpers.d.ts +21 -0
- package/packages/mb-lib-test/dist/jestutils/jestHelpers.js +77 -0
- package/packages/mb-lib-test/dist/module.d.ts +2 -0
- package/packages/mb-lib-test/dist/module.js +2 -0
- package/packages/mb-lib-test/dist/vitestutils/vitestHelpers.d.ts +21 -0
- package/packages/mb-lib-test/dist/vitestutils/vitestHelpers.js +77 -0
- package/packages/mb-lib-test/package.json +12 -11
- package/reflector/DockerDesktopSetup.png +0 -0
- package/reflector/Reflector.md +158 -0
- package/reflector/ReflectorClient.png +0 -0
- package/reflector/ReflectorServer.png +0 -0
- package/reflector/docker-compose.yml +32 -0
- package/reflector/mDnsPacket.png +0 -0
- package/dist/broadcastServer.d.ts +0 -144
- package/dist/broadcastServer.d.ts.map +0 -1
- package/dist/broadcastServer.js.map +0 -1
- package/dist/broadcastServerTypes.d.ts +0 -841
- package/dist/broadcastServerTypes.d.ts.map +0 -1
- package/dist/broadcastServerTypes.js.map +0 -1
- package/dist/cli.d.ts +0 -30
- package/dist/cli.d.ts.map +0 -1
- package/dist/cli.js.map +0 -1
- package/dist/cliEmitter.d.ts +0 -50
- package/dist/cliEmitter.d.ts.map +0 -1
- package/dist/cliEmitter.js.map +0 -1
- package/dist/cliHistory.d.ts +0 -48
- package/dist/cliHistory.d.ts.map +0 -1
- package/dist/cliHistory.js.map +0 -1
- package/dist/clusters/export.d.ts +0 -2
- package/dist/clusters/export.d.ts.map +0 -1
- package/dist/clusters/export.js.map +0 -1
- package/dist/deviceManager.d.ts +0 -135
- package/dist/deviceManager.d.ts.map +0 -1
- package/dist/deviceManager.js.map +0 -1
- package/dist/devices/airConditioner.d.ts +0 -98
- package/dist/devices/airConditioner.d.ts.map +0 -1
- package/dist/devices/airConditioner.js.map +0 -1
- package/dist/devices/batteryStorage.d.ts +0 -48
- package/dist/devices/batteryStorage.d.ts.map +0 -1
- package/dist/devices/batteryStorage.js.map +0 -1
- package/dist/devices/cooktop.d.ts +0 -61
- package/dist/devices/cooktop.d.ts.map +0 -1
- package/dist/devices/cooktop.js.map +0 -1
- package/dist/devices/dishwasher.d.ts +0 -71
- package/dist/devices/dishwasher.d.ts.map +0 -1
- package/dist/devices/dishwasher.js.map +0 -1
- package/dist/devices/evse.d.ts +0 -76
- package/dist/devices/evse.d.ts.map +0 -1
- package/dist/devices/evse.js.map +0 -1
- package/dist/devices/export.d.ts +0 -17
- package/dist/devices/export.d.ts.map +0 -1
- package/dist/devices/export.js.map +0 -1
- package/dist/devices/extractorHood.d.ts +0 -46
- package/dist/devices/extractorHood.d.ts.map +0 -1
- package/dist/devices/extractorHood.js.map +0 -1
- package/dist/devices/heatPump.d.ts +0 -47
- package/dist/devices/heatPump.d.ts.map +0 -1
- package/dist/devices/heatPump.js.map +0 -1
- package/dist/devices/laundryDryer.d.ts +0 -67
- package/dist/devices/laundryDryer.d.ts.map +0 -1
- package/dist/devices/laundryDryer.js.map +0 -1
- package/dist/devices/laundryWasher.d.ts +0 -81
- package/dist/devices/laundryWasher.d.ts.map +0 -1
- package/dist/devices/laundryWasher.js.map +0 -1
- package/dist/devices/microwaveOven.d.ts +0 -168
- package/dist/devices/microwaveOven.d.ts.map +0 -1
- package/dist/devices/microwaveOven.js.map +0 -1
- package/dist/devices/oven.d.ts +0 -105
- package/dist/devices/oven.d.ts.map +0 -1
- package/dist/devices/oven.js.map +0 -1
- package/dist/devices/refrigerator.d.ts +0 -118
- package/dist/devices/refrigerator.d.ts.map +0 -1
- package/dist/devices/refrigerator.js.map +0 -1
- package/dist/devices/roboticVacuumCleaner.d.ts +0 -112
- package/dist/devices/roboticVacuumCleaner.d.ts.map +0 -1
- package/dist/devices/roboticVacuumCleaner.js.map +0 -1
- package/dist/devices/solarPower.d.ts +0 -40
- package/dist/devices/solarPower.d.ts.map +0 -1
- package/dist/devices/solarPower.js.map +0 -1
- package/dist/devices/speaker.d.ts +0 -87
- package/dist/devices/speaker.d.ts.map +0 -1
- package/dist/devices/speaker.js.map +0 -1
- package/dist/devices/temperatureControl.d.ts +0 -166
- package/dist/devices/temperatureControl.d.ts.map +0 -1
- package/dist/devices/temperatureControl.js.map +0 -1
- package/dist/devices/waterHeater.d.ts +0 -111
- package/dist/devices/waterHeater.d.ts.map +0 -1
- package/dist/devices/waterHeater.js.map +0 -1
- package/dist/dgram/coap.d.ts +0 -205
- package/dist/dgram/coap.d.ts.map +0 -1
- package/dist/dgram/coap.js.map +0 -1
- package/dist/dgram/dgram.d.ts +0 -143
- package/dist/dgram/dgram.d.ts.map +0 -1
- package/dist/dgram/dgram.js.map +0 -1
- package/dist/dgram/mb_coap.d.ts +0 -24
- package/dist/dgram/mb_coap.d.ts.map +0 -1
- package/dist/dgram/mb_coap.js.map +0 -1
- package/dist/dgram/mb_mdns.d.ts +0 -24
- package/dist/dgram/mb_mdns.d.ts.map +0 -1
- package/dist/dgram/mb_mdns.js.map +0 -1
- package/dist/dgram/mdns.d.ts +0 -371
- package/dist/dgram/mdns.d.ts.map +0 -1
- package/dist/dgram/mdns.js.map +0 -1
- package/dist/dgram/mdnsReflectorClient.d.ts +0 -88
- package/dist/dgram/mdnsReflectorClient.d.ts.map +0 -1
- package/dist/dgram/mdnsReflectorClient.js.map +0 -1
- package/dist/dgram/mdnsReflectorServer.d.ts +0 -78
- package/dist/dgram/mdnsReflectorServer.d.ts.map +0 -1
- package/dist/dgram/mdnsReflectorServer.js.map +0 -1
- package/dist/dgram/mdnsReflectorTypes.d.ts +0 -28
- package/dist/dgram/mdnsReflectorTypes.d.ts.map +0 -1
- package/dist/dgram/mdnsReflectorTypes.js.map +0 -1
- package/dist/dgram/multicast.d.ts +0 -67
- package/dist/dgram/multicast.d.ts.map +0 -1
- package/dist/dgram/multicast.js.map +0 -1
- package/dist/dgram/unicast.d.ts +0 -64
- package/dist/dgram/unicast.d.ts.map +0 -1
- package/dist/dgram/unicast.js.map +0 -1
- package/dist/frontend.d.ts +0 -245
- package/dist/frontend.d.ts.map +0 -1
- package/dist/frontend.js.map +0 -1
- package/dist/frontendTypes.d.ts +0 -529
- package/dist/frontendTypes.d.ts.map +0 -1
- package/dist/frontendTypes.js.map +0 -1
- package/dist/helpers.d.ts +0 -48
- package/dist/helpers.d.ts.map +0 -1
- package/dist/helpers.js.map +0 -1
- package/dist/index.d.ts +0 -34
- package/dist/index.d.ts.map +0 -1
- package/dist/index.js.map +0 -1
- package/dist/jestutils/export.d.ts +0 -2
- package/dist/jestutils/export.d.ts.map +0 -1
- package/dist/jestutils/export.js.map +0 -1
- package/dist/jestutils/jestHelpers.d.ts +0 -345
- package/dist/jestutils/jestHelpers.d.ts.map +0 -1
- package/dist/jestutils/jestHelpers.js.map +0 -1
- package/dist/logger/export.d.ts +0 -2
- package/dist/logger/export.d.ts.map +0 -1
- package/dist/logger/export.js.map +0 -1
- package/dist/matter/behaviors.d.ts +0 -2
- package/dist/matter/behaviors.d.ts.map +0 -1
- package/dist/matter/behaviors.js.map +0 -1
- package/dist/matter/clusters.d.ts +0 -2
- package/dist/matter/clusters.d.ts.map +0 -1
- package/dist/matter/clusters.js.map +0 -1
- package/dist/matter/devices.d.ts +0 -2
- package/dist/matter/devices.d.ts.map +0 -1
- package/dist/matter/devices.js.map +0 -1
- package/dist/matter/endpoints.d.ts +0 -2
- package/dist/matter/endpoints.d.ts.map +0 -1
- package/dist/matter/endpoints.js.map +0 -1
- package/dist/matter/export.d.ts +0 -5
- package/dist/matter/export.d.ts.map +0 -1
- package/dist/matter/export.js.map +0 -1
- package/dist/matter/types.d.ts +0 -3
- package/dist/matter/types.d.ts.map +0 -1
- package/dist/matter/types.js.map +0 -1
- package/dist/matterNode.d.ts +0 -342
- package/dist/matterNode.d.ts.map +0 -1
- package/dist/matterNode.js.map +0 -1
- package/dist/matterbridge.d.ts +0 -505
- package/dist/matterbridge.d.ts.map +0 -1
- package/dist/matterbridge.js.map +0 -1
- package/dist/matterbridgeAccessoryPlatform.d.ts +0 -41
- package/dist/matterbridgeAccessoryPlatform.d.ts.map +0 -1
- package/dist/matterbridgeAccessoryPlatform.js.map +0 -1
- package/dist/matterbridgeBehaviors.d.ts +0 -2404
- package/dist/matterbridgeBehaviors.d.ts.map +0 -1
- package/dist/matterbridgeBehaviors.js.map +0 -1
- package/dist/matterbridgeDeviceTypes.d.ts +0 -698
- package/dist/matterbridgeDeviceTypes.d.ts.map +0 -1
- package/dist/matterbridgeDeviceTypes.js.map +0 -1
- package/dist/matterbridgeDynamicPlatform.d.ts +0 -41
- package/dist/matterbridgeDynamicPlatform.d.ts.map +0 -1
- package/dist/matterbridgeDynamicPlatform.js.map +0 -1
- package/dist/matterbridgeEndpoint.d.ts +0 -1507
- package/dist/matterbridgeEndpoint.d.ts.map +0 -1
- package/dist/matterbridgeEndpoint.js.map +0 -1
- package/dist/matterbridgeEndpointHelpers.d.ts +0 -787
- package/dist/matterbridgeEndpointHelpers.d.ts.map +0 -1
- package/dist/matterbridgeEndpointHelpers.js.map +0 -1
- package/dist/matterbridgeEndpointTypes.d.ts +0 -166
- package/dist/matterbridgeEndpointTypes.d.ts.map +0 -1
- package/dist/matterbridgeEndpointTypes.js.map +0 -1
- package/dist/matterbridgePlatform.d.ts +0 -539
- package/dist/matterbridgePlatform.d.ts.map +0 -1
- package/dist/matterbridgePlatform.js.map +0 -1
- package/dist/matterbridgeTypes.d.ts +0 -252
- package/dist/matterbridgeTypes.d.ts.map +0 -1
- package/dist/matterbridgeTypes.js.map +0 -1
- package/dist/pluginManager.d.ts +0 -372
- package/dist/pluginManager.d.ts.map +0 -1
- package/dist/pluginManager.js.map +0 -1
- package/dist/shelly.d.ts +0 -181
- package/dist/shelly.d.ts.map +0 -1
- package/dist/shelly.js.map +0 -1
- package/dist/storage/export.d.ts +0 -2
- package/dist/storage/export.d.ts.map +0 -1
- package/dist/storage/export.js.map +0 -1
- package/dist/update.d.ts +0 -84
- package/dist/update.d.ts.map +0 -1
- package/dist/update.js.map +0 -1
- package/dist/utils/colorUtils.d.ts +0 -101
- package/dist/utils/colorUtils.d.ts.map +0 -1
- package/dist/utils/colorUtils.js.map +0 -1
- package/dist/utils/commandLine.d.ts +0 -66
- package/dist/utils/commandLine.d.ts.map +0 -1
- package/dist/utils/commandLine.js.map +0 -1
- package/dist/utils/copyDirectory.d.ts +0 -35
- package/dist/utils/copyDirectory.d.ts.map +0 -1
- package/dist/utils/copyDirectory.js.map +0 -1
- package/dist/utils/createDirectory.d.ts +0 -34
- package/dist/utils/createDirectory.d.ts.map +0 -1
- package/dist/utils/createDirectory.js.map +0 -1
- package/dist/utils/createZip.d.ts +0 -39
- package/dist/utils/createZip.d.ts.map +0 -1
- package/dist/utils/createZip.js.map +0 -1
- package/dist/utils/deepCopy.d.ts +0 -32
- package/dist/utils/deepCopy.d.ts.map +0 -1
- package/dist/utils/deepCopy.js.map +0 -1
- package/dist/utils/deepEqual.d.ts +0 -54
- package/dist/utils/deepEqual.d.ts.map +0 -1
- package/dist/utils/deepEqual.js.map +0 -1
- package/dist/utils/error.d.ts +0 -45
- package/dist/utils/error.d.ts.map +0 -1
- package/dist/utils/error.js.map +0 -1
- package/dist/utils/export.d.ts +0 -13
- package/dist/utils/export.d.ts.map +0 -1
- package/dist/utils/export.js.map +0 -1
- package/dist/utils/format.d.ts +0 -53
- package/dist/utils/format.d.ts.map +0 -1
- package/dist/utils/format.js.map +0 -1
- package/dist/utils/hex.d.ts +0 -89
- package/dist/utils/hex.d.ts.map +0 -1
- package/dist/utils/hex.js.map +0 -1
- package/dist/utils/inspector.d.ts +0 -87
- package/dist/utils/inspector.d.ts.map +0 -1
- package/dist/utils/inspector.js.map +0 -1
- package/dist/utils/isValid.d.ts +0 -103
- package/dist/utils/isValid.d.ts.map +0 -1
- package/dist/utils/isValid.js.map +0 -1
- package/dist/utils/network.d.ts +0 -140
- package/dist/utils/network.d.ts.map +0 -1
- package/dist/utils/network.js.map +0 -1
- package/dist/utils/spawn.d.ts +0 -33
- package/dist/utils/spawn.d.ts.map +0 -1
- package/dist/utils/spawn.js.map +0 -1
- package/dist/utils/tracker.d.ts +0 -108
- package/dist/utils/tracker.d.ts.map +0 -1
- package/dist/utils/tracker.js.map +0 -1
- package/dist/utils/wait.d.ts +0 -54
- package/dist/utils/wait.d.ts.map +0 -1
- package/dist/utils/wait.js.map +0 -1
- package/dist/workerGlobalPrefix.d.ts +0 -25
- package/dist/workerGlobalPrefix.d.ts.map +0 -1
- package/dist/workerGlobalPrefix.js.map +0 -1
- package/dist/workerTypes.d.ts +0 -52
- package/dist/workerTypes.d.ts.map +0 -1
- package/dist/workerTypes.js.map +0 -1
- package/dist/workers.d.ts +0 -69
- package/dist/workers.d.ts.map +0 -1
- package/dist/workers.js.map +0 -1
- package/scripts/data_model.mjs +0 -2058
- package/scripts/fetch-chip.mjs +0 -102
- package/scripts/marked.mjs +0 -133
- package/scripts/markedFooter.html +0 -42
- 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
|
|
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"
|
|
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"
|
|
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"
|
|
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"
|
|
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
|
|
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"
|
|
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"
|
|
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"
|
|
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"
|
|
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
|
|
119
|
+
if (type === 1 && rdlength === 4 && hostA) {
|
|
177
120
|
hostA.copy(upgradedMsg, rdataOffset);
|
|
178
121
|
}
|
|
179
|
-
else if (type === 28
|
|
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));
|
|
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';
|
|
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
|
package/dist/dgram/multicast.js
CHANGED
|
@@ -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;
|
|
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
|
package/dist/dgram/unicast.js
CHANGED
|
@@ -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
|