matterbridge 3.1.6 → 3.1.7-dev-20250723-8e073ce
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 +33 -0
- package/README-DOCKER.md +3 -3
- package/bin/mb_coap.js +2 -0
- package/bin/mb_mdns.js +2 -0
- package/dist/cli.js +2 -91
- package/dist/cliEmitter.js +0 -30
- package/dist/clusters/export.js +0 -2
- package/dist/defaultConfigSchema.js +0 -24
- package/dist/deviceManager.js +1 -94
- package/dist/devices/batteryStorage.js +1 -48
- package/dist/devices/dishwasher.js +3 -78
- package/dist/devices/evse.js +10 -74
- package/dist/devices/export.js +0 -2
- package/dist/devices/extractorHood.js +0 -42
- package/dist/devices/heatPump.js +2 -50
- package/dist/devices/laundryDryer.js +6 -83
- package/dist/devices/laundryWasher.js +7 -91
- package/dist/devices/roboticVacuumCleaner.js +7 -93
- package/dist/devices/solarPower.js +0 -38
- package/dist/devices/waterHeater.js +2 -82
- package/dist/dgram/coap.js +252 -0
- package/dist/dgram/dgram.js +2 -113
- package/dist/dgram/mb_coap.js +52 -0
- package/dist/dgram/mb_mdns.js +60 -0
- package/dist/dgram/mdns.js +135 -380
- package/dist/dgram/multicast.js +7 -64
- package/dist/dgram/unicast.js +0 -54
- package/dist/frontend.js +21 -435
- package/dist/globalMatterbridge.js +0 -47
- package/dist/helpers.js +0 -53
- package/dist/index.js +1 -30
- 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/matterbridge.js +50 -804
- package/dist/matterbridgeAccessoryPlatform.js +0 -36
- package/dist/matterbridgeBehaviors.js +5 -65
- package/dist/matterbridgeDeviceTypes.js +15 -579
- package/dist/matterbridgeDynamicPlatform.js +0 -36
- package/dist/matterbridgeEndpoint.js +51 -1191
- package/dist/matterbridgeEndpointHelpers.js +13 -322
- package/dist/matterbridgePlatform.js +0 -233
- package/dist/matterbridgeTypes.js +0 -25
- package/dist/pluginManager.js +3 -249
- package/dist/shelly.js +7 -168
- package/dist/storage/export.js +0 -1
- package/dist/update.js +0 -54
- package/dist/utils/colorUtils.js +2 -263
- package/dist/utils/commandLine.js +0 -54
- package/dist/utils/copyDirectory.js +1 -38
- 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 -41
- package/dist/utils/export.js +0 -1
- package/dist/utils/hex.js +0 -58
- package/dist/utils/isvalid.js +0 -101
- package/dist/utils/network.js +5 -81
- package/dist/utils/spawn.js +0 -40
- package/dist/utils/wait.js +9 -62
- package/npm-shrinkwrap.json +5 -3
- package/package.json +4 -3
- package/dist/cli.d.ts +0 -26
- package/dist/cli.d.ts.map +0 -1
- package/dist/cli.js.map +0 -1
- package/dist/cliEmitter.d.ts +0 -34
- package/dist/cliEmitter.d.ts.map +0 -1
- package/dist/cliEmitter.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/defaultConfigSchema.d.ts +0 -28
- package/dist/defaultConfigSchema.d.ts.map +0 -1
- package/dist/defaultConfigSchema.js.map +0 -1
- package/dist/deviceManager.d.ts +0 -112
- package/dist/deviceManager.d.ts.map +0 -1
- package/dist/deviceManager.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/dishwasher.d.ts +0 -91
- package/dist/devices/dishwasher.d.ts.map +0 -1
- package/dist/devices/dishwasher.js.map +0 -1
- package/dist/devices/evse.d.ts +0 -75
- package/dist/devices/evse.d.ts.map +0 -1
- package/dist/devices/evse.js.map +0 -1
- package/dist/devices/export.d.ts +0 -11
- 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 -87
- package/dist/devices/laundryDryer.d.ts.map +0 -1
- package/dist/devices/laundryDryer.js.map +0 -1
- package/dist/devices/laundryWasher.d.ts +0 -242
- package/dist/devices/laundryWasher.d.ts.map +0 -1
- package/dist/devices/laundryWasher.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/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/dgram.d.ts +0 -140
- package/dist/dgram/dgram.d.ts.map +0 -1
- package/dist/dgram/dgram.js.map +0 -1
- package/dist/dgram/mdns.d.ts +0 -288
- package/dist/dgram/mdns.d.ts.map +0 -1
- package/dist/dgram/mdns.js.map +0 -1
- package/dist/dgram/multicast.d.ts +0 -65
- package/dist/dgram/multicast.d.ts.map +0 -1
- package/dist/dgram/multicast.js.map +0 -1
- package/dist/dgram/unicast.d.ts +0 -56
- package/dist/dgram/unicast.d.ts.map +0 -1
- package/dist/dgram/unicast.js.map +0 -1
- package/dist/frontend.d.ts +0 -304
- package/dist/frontend.d.ts.map +0 -1
- package/dist/frontend.js.map +0 -1
- package/dist/globalMatterbridge.d.ts +0 -59
- package/dist/globalMatterbridge.d.ts.map +0 -1
- package/dist/globalMatterbridge.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 -33
- package/dist/index.d.ts.map +0 -1
- package/dist/index.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/matterbridge.d.ts +0 -460
- package/dist/matterbridge.d.ts.map +0 -1
- package/dist/matterbridge.js.map +0 -1
- package/dist/matterbridgeAccessoryPlatform.d.ts +0 -42
- package/dist/matterbridgeAccessoryPlatform.d.ts.map +0 -1
- package/dist/matterbridgeAccessoryPlatform.js.map +0 -1
- package/dist/matterbridgeBehaviors.d.ts +0 -1351
- package/dist/matterbridgeBehaviors.d.ts.map +0 -1
- package/dist/matterbridgeBehaviors.js.map +0 -1
- package/dist/matterbridgeDeviceTypes.d.ts +0 -709
- package/dist/matterbridgeDeviceTypes.d.ts.map +0 -1
- package/dist/matterbridgeDeviceTypes.js.map +0 -1
- package/dist/matterbridgeDynamicPlatform.d.ts +0 -42
- package/dist/matterbridgeDynamicPlatform.d.ts.map +0 -1
- package/dist/matterbridgeDynamicPlatform.js.map +0 -1
- package/dist/matterbridgeEndpoint.d.ts +0 -1328
- package/dist/matterbridgeEndpoint.d.ts.map +0 -1
- package/dist/matterbridgeEndpoint.js.map +0 -1
- package/dist/matterbridgeEndpointHelpers.d.ts +0 -3198
- package/dist/matterbridgeEndpointHelpers.d.ts.map +0 -1
- package/dist/matterbridgeEndpointHelpers.js.map +0 -1
- package/dist/matterbridgePlatform.d.ts +0 -310
- package/dist/matterbridgePlatform.d.ts.map +0 -1
- package/dist/matterbridgePlatform.js.map +0 -1
- package/dist/matterbridgeTypes.d.ts +0 -195
- package/dist/matterbridgeTypes.d.ts.map +0 -1
- package/dist/matterbridgeTypes.js.map +0 -1
- package/dist/pluginManager.d.ts +0 -270
- package/dist/pluginManager.d.ts.map +0 -1
- package/dist/pluginManager.js.map +0 -1
- package/dist/shelly.d.ts +0 -174
- 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 -59
- package/dist/update.d.ts.map +0 -1
- package/dist/update.js.map +0 -1
- package/dist/utils/colorUtils.d.ts +0 -117
- package/dist/utils/colorUtils.d.ts.map +0 -1
- package/dist/utils/colorUtils.js.map +0 -1
- package/dist/utils/commandLine.d.ts +0 -59
- package/dist/utils/commandLine.d.ts.map +0 -1
- package/dist/utils/commandLine.js.map +0 -1
- package/dist/utils/copyDirectory.d.ts +0 -33
- 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 -44
- package/dist/utils/error.d.ts.map +0 -1
- package/dist/utils/error.js.map +0 -1
- package/dist/utils/export.d.ts +0 -12
- package/dist/utils/export.d.ts.map +0 -1
- package/dist/utils/export.js.map +0 -1
- package/dist/utils/hex.d.ts +0 -49
- package/dist/utils/hex.d.ts.map +0 -1
- package/dist/utils/hex.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 -74
- 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/wait.d.ts +0 -56
- package/dist/utils/wait.d.ts.map +0 -1
- package/dist/utils/wait.js.map +0 -1
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
|
-
// Net 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,34 +7,16 @@ 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
|
joinedInterfaces = [];
|
|
41
|
-
/**
|
|
42
|
-
* Creates an instance of Multicast.
|
|
43
|
-
*
|
|
44
|
-
* @param {string} name - The name of the socket.
|
|
45
|
-
* @param {string} multicastAddress - The multicast address to join.
|
|
46
|
-
* @param {number} multicastPort - The port number to bind to.
|
|
47
|
-
* @param {'udp4' | 'udp6'} socketType - The type of the socket (IPv4 or IPv6).
|
|
48
|
-
* @param {boolean | undefined} reuseAddr - Whether to allow address reuse.
|
|
49
|
-
* @param {string} [interfaceName] - The name of the network interface to bind to.
|
|
50
|
-
* @param {string} [interfaceAddress] - The address of the network interface to bind to.
|
|
51
|
-
*/
|
|
52
14
|
constructor(name, multicastAddress, multicastPort, socketType, reuseAddr = true, interfaceName, interfaceAddress) {
|
|
53
15
|
super(name, socketType, reuseAddr, interfaceName, interfaceAddress);
|
|
54
16
|
this.multicastAddress = multicastAddress;
|
|
55
17
|
this.multicastPort = multicastPort;
|
|
56
18
|
}
|
|
57
|
-
/**
|
|
58
|
-
* Starts the dgram multicast socket.
|
|
59
|
-
*/
|
|
60
19
|
start() {
|
|
61
|
-
// Get the local ipv4 or ipv6 address to bind to.
|
|
62
20
|
if (this.socketType === 'udp4') {
|
|
63
21
|
this.log.debug(`Starting ipv4 dgram multicast socket...`);
|
|
64
22
|
this.interfaceAddress = this.interfaceAddress ?? this.getIpv4InterfaceAddress(this.interfaceName);
|
|
@@ -74,59 +32,49 @@ export class Multicast extends Dgram {
|
|
|
74
32
|
this.emit('bound', address);
|
|
75
33
|
});
|
|
76
34
|
}
|
|
77
|
-
/**
|
|
78
|
-
* Event handler for the 'listening' event. This event is emitted when the socket starts listening for datagram messages.
|
|
79
|
-
*
|
|
80
|
-
* @param {AddressInfo} [address] - The address info.
|
|
81
|
-
*/
|
|
82
35
|
onListening(address) {
|
|
83
36
|
this.log.debug(`Dgram multicast socket listening on ${BLUE}${address.family}${db} ${BLUE}${address.address}${db}:${BLUE}${address.port}${db}`);
|
|
84
37
|
this.socket.setBroadcast(true);
|
|
85
38
|
this.log.debug(`Dgram multicast socket broadcast enabled`);
|
|
39
|
+
this.socket.setTTL(255);
|
|
40
|
+
this.log.debug(`Dgram multicast socket TTL set to 255`);
|
|
86
41
|
this.socket.setMulticastTTL(255);
|
|
87
42
|
this.log.debug(`Dgram multicast socket multicast TTL set to 255`);
|
|
88
43
|
this.socket.setMulticastLoopback(true);
|
|
89
44
|
this.log.debug(`Dgram multicast socket multicast loopback enabled`);
|
|
90
|
-
// 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.
|
|
91
45
|
Object.entries(os.networkInterfaces()).forEach(([name, interfaces]) => {
|
|
92
46
|
this.log.debug(`Dgram multicast socket processing interface ${CYAN}${name}${db}`);
|
|
93
47
|
if (!interfaces)
|
|
94
48
|
return;
|
|
95
49
|
if (this.interfaceName && name !== this.interfaceName)
|
|
96
|
-
return;
|
|
50
|
+
return;
|
|
97
51
|
let iface;
|
|
98
52
|
let membershipInterface;
|
|
99
|
-
// Find the first ipv4 interface
|
|
100
53
|
const ifaceIpv4 = interfaces.find((iface) => iface.family === 'IPv4' && this.socketType === 'udp4');
|
|
101
54
|
if (ifaceIpv4) {
|
|
102
55
|
iface = ifaceIpv4;
|
|
103
56
|
membershipInterface = ifaceIpv4.address;
|
|
104
57
|
}
|
|
105
|
-
// Find the first IPv6 Address
|
|
106
58
|
const ifaceIpv6 = interfaces.find((iface) => iface.family === 'IPv6' && this.socketType === 'udp6');
|
|
107
59
|
if (ifaceIpv6) {
|
|
108
60
|
iface = ifaceIpv6;
|
|
109
|
-
membershipInterface = ifaceIpv6.address;
|
|
61
|
+
membershipInterface = ifaceIpv6.address + (ifaceIpv6.scopeid !== undefined ? (process.platform === 'win32' ? '%' + String(ifaceIpv6.scopeid) : '%' + name) : '');
|
|
110
62
|
}
|
|
111
|
-
// Find the first Unique Local IPv6 Address (ULA)
|
|
112
63
|
const ifaceUla = interfaces.find((iface) => iface.family === 'IPv6' && this.socketType === 'udp6' && iface.address.startsWith('fd'));
|
|
113
64
|
if (ifaceUla) {
|
|
114
65
|
iface = ifaceUla;
|
|
115
|
-
membershipInterface = ifaceUla.address + (
|
|
66
|
+
membershipInterface = ifaceUla.address + (ifaceUla.scopeid !== undefined ? (process.platform === 'win32' ? '%' + String(ifaceUla.scopeid) : '%' + name) : '');
|
|
116
67
|
}
|
|
117
|
-
// Find the first Unique Local IPv6 Address (ULA) with prefix length /64 (netmask ffff:ffff:ffff:ffff::)
|
|
118
68
|
const ifaceUla64 = interfaces.find((iface) => iface.family === 'IPv6' && this.socketType === 'udp6' && iface.address.startsWith('fd') && iface.netmask === 'ffff:ffff:ffff:ffff::');
|
|
119
69
|
if (ifaceUla64) {
|
|
120
70
|
iface = ifaceUla64;
|
|
121
|
-
membershipInterface = ifaceUla64.address + (
|
|
71
|
+
membershipInterface = ifaceUla64.address + (ifaceUla64.scopeid !== undefined ? (process.platform === 'win32' ? '%' + String(ifaceUla64.scopeid) : '%' + name) : '');
|
|
122
72
|
}
|
|
123
|
-
// Find the first Link-local IPv6 Address
|
|
124
73
|
const ifaceLinkLocal = interfaces.find((iface) => iface.family === 'IPv6' && this.socketType === 'udp6' && iface.address.startsWith('fe80'));
|
|
125
74
|
if (ifaceLinkLocal) {
|
|
126
75
|
iface = ifaceLinkLocal;
|
|
127
|
-
membershipInterface = ifaceLinkLocal.address + (
|
|
76
|
+
membershipInterface = ifaceLinkLocal.address + (ifaceLinkLocal.scopeid !== undefined ? (process.platform === 'win32' ? '%' + String(ifaceLinkLocal.scopeid) : '%' + name) : '');
|
|
128
77
|
}
|
|
129
|
-
// Add the interface address to the multicast group
|
|
130
78
|
if (iface && membershipInterface) {
|
|
131
79
|
try {
|
|
132
80
|
this.socket.addMembership(this.multicastAddress, membershipInterface);
|
|
@@ -138,7 +86,6 @@ export class Multicast extends Dgram {
|
|
|
138
86
|
}
|
|
139
87
|
}
|
|
140
88
|
});
|
|
141
|
-
// If the interfaceAddress is '::', we need to set the default outgoing multicast interface to '::' + the scope ID for all interfaces address.
|
|
142
89
|
let interfaceAddress = this.interfaceAddress;
|
|
143
90
|
if (this.socketType === 'udp6' && this.interfaceAddress === '::') {
|
|
144
91
|
interfaceAddress = '::' + this.getIpv6ScopeIdForAllInterfacesAddress();
|
|
@@ -148,9 +95,6 @@ export class Multicast extends Dgram {
|
|
|
148
95
|
this.log.debug(`Dgram multicast socket multicastInterface set to ${BLUE}${interfaceAddress}${db}`);
|
|
149
96
|
this.emit('ready', address);
|
|
150
97
|
}
|
|
151
|
-
/**
|
|
152
|
-
* Stops the dgram multicast socket.
|
|
153
|
-
*/
|
|
154
98
|
stop() {
|
|
155
99
|
this.log.debug('Stopping dgram multicast socket...');
|
|
156
100
|
this.joinedInterfaces.forEach((membershipInterface) => {
|
|
@@ -167,4 +111,3 @@ export class Multicast extends Dgram {
|
|
|
167
111
|
this.log.debug('Stopped dgram multicast socket.');
|
|
168
112
|
}
|
|
169
113
|
}
|
|
170
|
-
//# 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.
|
|
38
|
-
* @param {string} [interfaceName] - The name of the network interface to bind to.
|
|
39
|
-
* @param {string} [interfaceAddress] - The address of the network interface to bind to.
|
|
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,20 +16,12 @@ 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.socket.bind(this.port, this.interfaceAddress, () => {
|
|
65
20
|
const address = this.socket.address();
|
|
66
21
|
this.log.debug(`Dgram unicast socket bound to ${BLUE}${address.family}${db} ${BLUE}${address.address}${db}:${BLUE}${address.port}${db}`);
|
|
67
22
|
this.emit('bound', address);
|
|
68
23
|
});
|
|
69
24
|
}
|
|
70
|
-
/**
|
|
71
|
-
* Event handler for the 'listening' event. This event is emitted when the socket starts listening for datagram messages.
|
|
72
|
-
*
|
|
73
|
-
* @param {AddressInfo} [address] - The address info.
|
|
74
|
-
*/
|
|
75
25
|
onListening(address) {
|
|
76
26
|
this.log.debug(`Dgram unicast socket listening on ${BLUE}${address.family}${db} ${BLUE}${address.address}${db}:${BLUE}${address.port}${db}`);
|
|
77
27
|
this.socket.setBroadcast(true);
|
|
@@ -79,13 +29,9 @@ export class Unicast extends Dgram {
|
|
|
79
29
|
this.emit('ready', address);
|
|
80
30
|
this.onReady(address);
|
|
81
31
|
}
|
|
82
|
-
/**
|
|
83
|
-
* Stops the dgram unicast socket.
|
|
84
|
-
*/
|
|
85
32
|
stop() {
|
|
86
33
|
this.log.debug('Stopping dgram unicast socket...');
|
|
87
34
|
this.socket.close();
|
|
88
35
|
this.log.debug('Stopped dgram unicast socket.');
|
|
89
36
|
}
|
|
90
37
|
}
|
|
91
|
-
//# sourceMappingURL=unicast.js.map
|