matterbridge 3.4.5 → 3.4.6-dev-20251228-e06f048
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 +12 -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 +2 -114
- package/dist/dgram/mb_coap.js +3 -41
- package/dist/dgram/mb_mdns.js +22 -76
- package/dist/dgram/mdns.js +137 -351
- package/dist/dgram/mdnsReflectorClient.js +5 -29
- package/dist/dgram/mdnsReflectorServer.js +8 -49
- 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 -101
- package/dist/utils/network.js +5 -103
- 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 +2 -2
- package/package.json +1 -2
- 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 -350
- package/dist/dgram/mdns.d.ts.map +0 -1
- package/dist/dgram/mdns.js.map +0 -1
- package/dist/dgram/mdnsReflectorClient.d.ts +0 -39
- package/dist/dgram/mdnsReflectorClient.d.ts.map +0 -1
- package/dist/dgram/mdnsReflectorClient.js.map +0 -1
- package/dist/dgram/mdnsReflectorServer.d.ts +0 -54
- 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 -117
- 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
|
@@ -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.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 { AnsiLogger, BLUE, nt } from 'node-ansi-logger';
|
|
24
2
|
import { getStringArrayParameter, hasParameter } from '../utils/commandLine.js';
|
|
25
3
|
import { Mdns } from './mdns.js';
|
|
@@ -30,7 +8,7 @@ export class MdnsReflectorClient {
|
|
|
30
8
|
verbose = hasParameter('v') || hasParameter('verbose');
|
|
31
9
|
debug = hasParameter('d') || hasParameter('debug') || hasParameter('v') || hasParameter('verbose');
|
|
32
10
|
silent = hasParameter('s') || hasParameter('silent');
|
|
33
|
-
log = new AnsiLogger({ logName: 'MdnsReflectorClient', logTimestampFormat: 4
|
|
11
|
+
log = new AnsiLogger({ logName: 'MdnsReflectorClient', logTimestampFormat: 4, logLevel: this.debug ? "debug" : this.silent ? "notice" : "info" });
|
|
34
12
|
mdnsIpv4 = new Mdns('mDNS udp4 Server', MDNS_MULTICAST_IPV4_ADDRESS, MDNS_MULTICAST_PORT, 'udp4', true, undefined, MDNS_REFLECTOR_BIND_ADDRESS_IPV4);
|
|
35
13
|
mdnsIpv6 = new Mdns('mDNS udp6 Server', MDNS_MULTICAST_IPV6_ADDRESS, MDNS_MULTICAST_PORT, 'udp6', true, undefined, MDNS_REFLECTOR_BIND_ADDRESS_IPV6);
|
|
36
14
|
unicastIpv4 = new Unicast('mDNS udp4 Reflector Client', 'udp4', false, undefined, MDNS_REFLECTOR_BIND_ADDRESS_IPV4);
|
|
@@ -38,14 +16,13 @@ export class MdnsReflectorClient {
|
|
|
38
16
|
constructor() {
|
|
39
17
|
this.log.logNameColor = '\x1b[38;5;97m';
|
|
40
18
|
this.mdnsIpv4.log.logNameColor = '\x1b[38;5;97m';
|
|
41
|
-
this.mdnsIpv4.log.logLevel = "warn"
|
|
19
|
+
this.mdnsIpv4.log.logLevel = "warn";
|
|
42
20
|
this.mdnsIpv6.log.logNameColor = '\x1b[38;5;97m';
|
|
43
|
-
this.mdnsIpv6.log.logLevel = "warn"
|
|
21
|
+
this.mdnsIpv6.log.logLevel = "warn";
|
|
44
22
|
this.unicastIpv4.log.logNameColor = '\x1b[38;5;97m';
|
|
45
|
-
this.unicastIpv4.log.logLevel = "warn"
|
|
23
|
+
this.unicastIpv4.log.logLevel = "warn";
|
|
46
24
|
this.unicastIpv6.log.logNameColor = '\x1b[38;5;97m';
|
|
47
|
-
this.unicastIpv6.log.logLevel = "warn"
|
|
48
|
-
// Apply filters if any
|
|
25
|
+
this.unicastIpv6.log.logLevel = "warn";
|
|
49
26
|
const filters = getStringArrayParameter('filter');
|
|
50
27
|
if (filters)
|
|
51
28
|
this.mdnsIpv4.filters.push(...filters);
|
|
@@ -129,4 +106,3 @@ export class MdnsReflectorClient {
|
|
|
129
106
|
this.log.notice('mDNS Reflector Client stopped.');
|
|
130
107
|
}
|
|
131
108
|
}
|
|
132
|
-
//# 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.0.0
|
|
7
|
-
* @license Apache-2.0
|
|
8
|
-
*
|
|
9
|
-
* Copyright 2025, 2026, 2027 Luca Liguori.
|
|
10
|
-
*
|
|
11
|
-
* Licensed under the Apache License, Version 2.0 (the "License");
|
|
12
|
-
* you may not use this file except in compliance with the License.
|
|
13
|
-
* You may obtain a copy of the License at
|
|
14
|
-
*
|
|
15
|
-
* http://www.apache.org/licenses/LICENSE-2.0
|
|
16
|
-
*
|
|
17
|
-
* Unless required by applicable law or agreed to in writing, software
|
|
18
|
-
* distributed under the License is distributed on an "AS IS" BASIS,
|
|
19
|
-
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
20
|
-
* See the License for the specific language governing permissions and
|
|
21
|
-
* limitations under the License.
|
|
22
|
-
*/
|
|
23
1
|
import os from 'node:os';
|
|
24
2
|
import { AnsiLogger, BLUE, nt } from 'node-ansi-logger';
|
|
25
3
|
import { hasParameter, getStringArrayParameter } from '../utils/commandLine.js';
|
|
@@ -31,7 +9,7 @@ export class MdnsReflectorServer {
|
|
|
31
9
|
verbose = hasParameter('v') || hasParameter('verbose');
|
|
32
10
|
debug = hasParameter('d') || hasParameter('debug') || hasParameter('v') || hasParameter('verbose');
|
|
33
11
|
silent = hasParameter('s') || hasParameter('silent');
|
|
34
|
-
log = new AnsiLogger({ logName: 'MdnsReflectorServer', logTimestampFormat: 4
|
|
12
|
+
log = new AnsiLogger({ logName: 'MdnsReflectorServer', logTimestampFormat: 4, logLevel: this.debug ? "debug" : this.silent ? "notice" : "info" });
|
|
35
13
|
mdnsIpv4 = new Mdns('mDNS udp4 Server', MDNS_MULTICAST_IPV4_ADDRESS, MDNS_MULTICAST_PORT, 'udp4', true, undefined, MDNS_REFLECTOR_BIND_ADDRESS_IPV4);
|
|
36
14
|
mdnsIpv6 = new Mdns('mDNS udp6 Server', MDNS_MULTICAST_IPV6_ADDRESS, MDNS_MULTICAST_PORT, 'udp6', true, undefined, MDNS_REFLECTOR_BIND_ADDRESS_IPV6);
|
|
37
15
|
unicastIpv4 = new Unicast('mDNS udp4 Reflector Server', 'udp4', true, undefined, MDNS_REFLECTOR_BIND_ADDRESS_IPV4, MDNS_REFLECTOR_PORT);
|
|
@@ -41,14 +19,13 @@ export class MdnsReflectorServer {
|
|
|
41
19
|
constructor() {
|
|
42
20
|
this.log.logNameColor = '\x1b[38;5;115m';
|
|
43
21
|
this.mdnsIpv4.log.logNameColor = '\x1b[38;5;115m';
|
|
44
|
-
this.mdnsIpv4.log.logLevel = "warn"
|
|
22
|
+
this.mdnsIpv4.log.logLevel = "warn";
|
|
45
23
|
this.mdnsIpv6.log.logNameColor = '\x1b[38;5;115m';
|
|
46
|
-
this.mdnsIpv6.log.logLevel = "warn"
|
|
24
|
+
this.mdnsIpv6.log.logLevel = "warn";
|
|
47
25
|
this.unicastIpv4.log.logNameColor = '\x1b[38;5;115m';
|
|
48
|
-
this.unicastIpv4.log.logLevel = "warn"
|
|
26
|
+
this.unicastIpv4.log.logLevel = "warn";
|
|
49
27
|
this.unicastIpv6.log.logNameColor = '\x1b[38;5;115m';
|
|
50
|
-
this.unicastIpv6.log.logLevel = "warn"
|
|
51
|
-
// Apply filters if any
|
|
28
|
+
this.unicastIpv6.log.logLevel = "warn";
|
|
52
29
|
const filters = getStringArrayParameter('filter');
|
|
53
30
|
if (filters)
|
|
54
31
|
this.mdnsIpv4.filters.push(...filters);
|
|
@@ -66,18 +43,7 @@ export class MdnsReflectorServer {
|
|
|
66
43
|
mdns.log.error(`Error getting broadcast address: ${error.message}`);
|
|
67
44
|
}
|
|
68
45
|
}
|
|
69
|
-
/**
|
|
70
|
-
* Decode and upgrade the A and AAAA records from Docker environment to point the host machine.
|
|
71
|
-
* Matterbridge running inside Docker Desktop containers register mDNS records with the container's IP address,
|
|
72
|
-
* which is not reachable from outside the Docker network.
|
|
73
|
-
* To make these services reachable, we need to upgrade the A and AAAA records using the host machine IP addresses.
|
|
74
|
-
* The reflector server runs on the host, while mDNS advertisements come from containers.
|
|
75
|
-
*
|
|
76
|
-
* @param {Buffer<ArrayBufferLike>} msg - The mDNS message buffer.
|
|
77
|
-
* @returns {Buffer<ArrayBufferLike>} The upgraded mDNS message buffer.
|
|
78
|
-
*/
|
|
79
46
|
upgradeAddress(msg) {
|
|
80
|
-
// Safety: if it's not even a DNS header, do nothing.
|
|
81
47
|
if (!msg || msg.length < 12)
|
|
82
48
|
return msg;
|
|
83
49
|
const preferredInterfaceName = this.mdnsIpv4.interfaceName ?? this.mdnsIpv6.interfaceName;
|
|
@@ -113,7 +79,6 @@ export class MdnsReflectorServer {
|
|
|
113
79
|
this.log.info(`**UpgradeAddress Host IPv6 for address upgrade: ${hostIpv6List.length > 0 ? hostIpv6List.join(', ') : 'N/A'}`);
|
|
114
80
|
if (!hostIpv4 && hostIpv6List.length === 0)
|
|
115
81
|
return msg;
|
|
116
|
-
// Copy the message so callers can safely re-use the original buffer.
|
|
117
82
|
const upgradedMsg = Buffer.from(msg);
|
|
118
83
|
const qdCount = upgradedMsg.readUInt16BE(4);
|
|
119
84
|
const anCount = upgradedMsg.readUInt16BE(6);
|
|
@@ -121,11 +86,9 @@ export class MdnsReflectorServer {
|
|
|
121
86
|
const arCount = upgradedMsg.readUInt16BE(10);
|
|
122
87
|
let offset = 12;
|
|
123
88
|
try {
|
|
124
|
-
// Skip questions
|
|
125
89
|
for (let i = 0; i < qdCount; i++) {
|
|
126
90
|
const qnameResult = this.mdnsIpv4.decodeDnsName(upgradedMsg, offset);
|
|
127
91
|
offset = qnameResult.newOffset;
|
|
128
|
-
// QTYPE + QCLASS
|
|
129
92
|
offset += 4;
|
|
130
93
|
if (offset > upgradedMsg.length)
|
|
131
94
|
return msg;
|
|
@@ -141,9 +104,7 @@ export class MdnsReflectorServer {
|
|
|
141
104
|
return;
|
|
142
105
|
const type = upgradedMsg.readUInt16BE(offset);
|
|
143
106
|
offset += 2;
|
|
144
|
-
// class (unused)
|
|
145
107
|
offset += 2;
|
|
146
|
-
// ttl (unused)
|
|
147
108
|
offset += 4;
|
|
148
109
|
const rdlength = upgradedMsg.readUInt16BE(offset);
|
|
149
110
|
offset += 2;
|
|
@@ -151,10 +112,10 @@ export class MdnsReflectorServer {
|
|
|
151
112
|
const endOfRdata = rdataOffset + rdlength;
|
|
152
113
|
if (endOfRdata > upgradedMsg.length)
|
|
153
114
|
return;
|
|
154
|
-
if (type === 1
|
|
115
|
+
if (type === 1 && rdlength === 4 && hostA) {
|
|
155
116
|
hostA.copy(upgradedMsg, rdataOffset);
|
|
156
117
|
}
|
|
157
|
-
else if (type === 28
|
|
118
|
+
else if (type === 28 && rdlength === 16 && hostAAAAs.length > 0) {
|
|
158
119
|
const hostAAAA = hostAAAAs[Math.min(hostAAAAIndex, hostAAAAs.length - 1)];
|
|
159
120
|
hostAAAA.copy(upgradedMsg, rdataOffset);
|
|
160
121
|
hostAAAAIndex++;
|
|
@@ -162,7 +123,6 @@ export class MdnsReflectorServer {
|
|
|
162
123
|
offset = endOfRdata;
|
|
163
124
|
}
|
|
164
125
|
};
|
|
165
|
-
// Walk RR sections and patch A/AAAA in-place.
|
|
166
126
|
upgradeResourceRecords(anCount);
|
|
167
127
|
upgradeResourceRecords(nsCount);
|
|
168
128
|
upgradeResourceRecords(arCount);
|
|
@@ -265,7 +225,7 @@ export class MdnsReflectorServer {
|
|
|
265
225
|
this.log.debug(`Notifying ipv6 client ${client.address}:${client.port} about server stopping`);
|
|
266
226
|
this.unicastIpv6.send(Buffer.from('mDNS Reflector Server is stopping'), client.address, client.port);
|
|
267
227
|
}
|
|
268
|
-
await new Promise((resolve) => setTimeout(resolve, 100));
|
|
228
|
+
await new Promise((resolve) => setTimeout(resolve, 100));
|
|
269
229
|
const promises = [];
|
|
270
230
|
promises[0] = new Promise((resolve) => {
|
|
271
231
|
this.mdnsIpv4.once('closed', () => resolve());
|
|
@@ -291,4 +251,3 @@ export class MdnsReflectorServer {
|
|
|
291
251
|
this.log.notice('mDNS Reflector Server stopped.');
|
|
292
252
|
}
|
|
293
253
|
}
|
|
294
|
-
//# sourceMappingURL=mdnsReflectorServer.js.map
|
|
@@ -1,28 +1,5 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* @description This file contains the definitions for the mDNS reflector classes.
|
|
3
|
-
* @file src/dgram/mdnsReflectorTypes.ts
|
|
4
|
-
* @author Luca Liguori
|
|
5
|
-
* @created 2025-12-25
|
|
6
|
-
* @version 1.0.0
|
|
7
|
-
* @license Apache-2.0
|
|
8
|
-
*
|
|
9
|
-
* Copyright 2025, 2026, 2027 Luca Liguori.
|
|
10
|
-
*
|
|
11
|
-
* Licensed under the Apache License, Version 2.0 (the "License");
|
|
12
|
-
* you may not use this file except in compliance with the License.
|
|
13
|
-
* You may obtain a copy of the License at
|
|
14
|
-
*
|
|
15
|
-
* http://www.apache.org/licenses/LICENSE-2.0
|
|
16
|
-
*
|
|
17
|
-
* Unless required by applicable law or agreed to in writing, software
|
|
18
|
-
* distributed under the License is distributed on an "AS IS" BASIS,
|
|
19
|
-
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
20
|
-
* See the License for the specific language governing permissions and
|
|
21
|
-
* limitations under the License.
|
|
22
|
-
*/
|
|
23
1
|
export const MDNS_REFLECTOR_BIND_ADDRESS_IPV4 = '0.0.0.0';
|
|
24
2
|
export const MDNS_REFLECTOR_BIND_ADDRESS_IPV6 = '::';
|
|
25
|
-
export const MDNS_REFLECTOR_ADDRESS = 'localhost';
|
|
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
|