matterbridge 3.2.4-dev-20250830-5c48452 → 3.2.4
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/dist/cli.d.ts +26 -0
- package/dist/cli.d.ts.map +1 -0
- package/dist/cli.js +91 -2
- package/dist/cli.js.map +1 -0
- package/dist/cliEmitter.d.ts +34 -0
- package/dist/cliEmitter.d.ts.map +1 -0
- package/dist/cliEmitter.js +30 -0
- package/dist/cliEmitter.js.map +1 -0
- package/dist/clusters/export.d.ts +2 -0
- package/dist/clusters/export.d.ts.map +1 -0
- package/dist/clusters/export.js +2 -0
- package/dist/clusters/export.js.map +1 -0
- package/dist/defaultConfigSchema.d.ts +28 -0
- package/dist/defaultConfigSchema.d.ts.map +1 -0
- package/dist/defaultConfigSchema.js +24 -0
- package/dist/defaultConfigSchema.js.map +1 -0
- package/dist/deviceManager.d.ts +112 -0
- package/dist/deviceManager.d.ts.map +1 -0
- package/dist/deviceManager.js +94 -1
- package/dist/deviceManager.js.map +1 -0
- package/dist/devices/batteryStorage.d.ts +48 -0
- package/dist/devices/batteryStorage.d.ts.map +1 -0
- package/dist/devices/batteryStorage.js +48 -1
- package/dist/devices/batteryStorage.js.map +1 -0
- package/dist/devices/cooktop.d.ts +60 -0
- package/dist/devices/cooktop.d.ts.map +1 -0
- package/dist/devices/cooktop.js +55 -0
- package/dist/devices/cooktop.js.map +1 -0
- package/dist/devices/dishwasher.d.ts +71 -0
- package/dist/devices/dishwasher.d.ts.map +1 -0
- package/dist/devices/dishwasher.js +57 -0
- package/dist/devices/dishwasher.js.map +1 -0
- package/dist/devices/evse.d.ts +75 -0
- package/dist/devices/evse.d.ts.map +1 -0
- package/dist/devices/evse.js +74 -10
- package/dist/devices/evse.js.map +1 -0
- package/dist/devices/export.d.ts +15 -0
- package/dist/devices/export.d.ts.map +1 -0
- package/dist/devices/export.js +4 -0
- package/dist/devices/export.js.map +1 -0
- package/dist/devices/extractorHood.d.ts +46 -0
- package/dist/devices/extractorHood.d.ts.map +1 -0
- package/dist/devices/extractorHood.js +42 -0
- package/dist/devices/extractorHood.js.map +1 -0
- package/dist/devices/heatPump.d.ts +47 -0
- package/dist/devices/heatPump.d.ts.map +1 -0
- package/dist/devices/heatPump.js +50 -2
- package/dist/devices/heatPump.js.map +1 -0
- package/dist/devices/laundryDryer.d.ts +67 -0
- package/dist/devices/laundryDryer.d.ts.map +1 -0
- package/dist/devices/laundryDryer.js +62 -3
- package/dist/devices/laundryDryer.js.map +1 -0
- package/dist/devices/laundryWasher.d.ts +81 -0
- package/dist/devices/laundryWasher.d.ts.map +1 -0
- package/dist/devices/laundryWasher.js +70 -4
- package/dist/devices/laundryWasher.js.map +1 -0
- package/dist/devices/microwaveOven.d.ts +168 -0
- package/dist/devices/microwaveOven.d.ts.map +1 -0
- package/dist/devices/microwaveOven.js +88 -5
- package/dist/devices/microwaveOven.js.map +1 -0
- package/dist/devices/oven.d.ts +105 -0
- package/dist/devices/oven.d.ts.map +1 -0
- package/dist/devices/oven.js +85 -0
- package/dist/devices/oven.js.map +1 -0
- package/dist/devices/refrigerator.d.ts +93 -0
- package/dist/devices/refrigerator.d.ts.map +1 -0
- package/dist/devices/refrigerator.js +80 -0
- package/dist/devices/refrigerator.js.map +1 -0
- package/dist/devices/roboticVacuumCleaner.d.ts +112 -0
- package/dist/devices/roboticVacuumCleaner.d.ts.map +1 -0
- package/dist/devices/roboticVacuumCleaner.js +93 -7
- package/dist/devices/roboticVacuumCleaner.js.map +1 -0
- package/dist/devices/solarPower.d.ts +40 -0
- package/dist/devices/solarPower.d.ts.map +1 -0
- package/dist/devices/solarPower.js +38 -0
- package/dist/devices/solarPower.js.map +1 -0
- package/dist/devices/temperatureControl.d.ts +166 -0
- package/dist/devices/temperatureControl.d.ts.map +1 -0
- package/dist/devices/temperatureControl.js +25 -3
- package/dist/devices/temperatureControl.js.map +1 -0
- package/dist/devices/waterHeater.d.ts +111 -0
- package/dist/devices/waterHeater.d.ts.map +1 -0
- package/dist/devices/waterHeater.js +82 -2
- package/dist/devices/waterHeater.js.map +1 -0
- package/dist/dgram/coap.d.ts +205 -0
- package/dist/dgram/coap.d.ts.map +1 -0
- package/dist/dgram/coap.js +126 -13
- package/dist/dgram/coap.js.map +1 -0
- package/dist/dgram/dgram.d.ts +140 -0
- package/dist/dgram/dgram.d.ts.map +1 -0
- package/dist/dgram/dgram.js +113 -2
- package/dist/dgram/dgram.js.map +1 -0
- package/dist/dgram/mb_coap.d.ts +24 -0
- package/dist/dgram/mb_coap.d.ts.map +1 -0
- package/dist/dgram/mb_coap.js +41 -3
- package/dist/dgram/mb_coap.js.map +1 -0
- package/dist/dgram/mb_mdns.d.ts +24 -0
- package/dist/dgram/mb_mdns.d.ts.map +1 -0
- package/dist/dgram/mb_mdns.js +51 -13
- package/dist/dgram/mb_mdns.js.map +1 -0
- package/dist/dgram/mdns.d.ts +288 -0
- package/dist/dgram/mdns.d.ts.map +1 -0
- package/dist/dgram/mdns.js +298 -137
- package/dist/dgram/mdns.js.map +1 -0
- package/dist/dgram/multicast.d.ts +65 -0
- package/dist/dgram/multicast.d.ts.map +1 -0
- package/dist/dgram/multicast.js +60 -1
- package/dist/dgram/multicast.js.map +1 -0
- package/dist/dgram/unicast.d.ts +56 -0
- package/dist/dgram/unicast.d.ts.map +1 -0
- package/dist/dgram/unicast.js +54 -0
- package/dist/dgram/unicast.js.map +1 -0
- package/dist/frontend.d.ts +313 -0
- package/dist/frontend.d.ts.map +1 -0
- package/dist/frontend.js +451 -24
- package/dist/frontend.js.map +1 -0
- package/dist/globalMatterbridge.d.ts +59 -0
- package/dist/globalMatterbridge.d.ts.map +1 -0
- package/dist/globalMatterbridge.js +47 -0
- package/dist/globalMatterbridge.js.map +1 -0
- package/dist/helpers.d.ts +48 -0
- package/dist/helpers.d.ts.map +1 -0
- package/dist/helpers.js +53 -0
- package/dist/helpers.js.map +1 -0
- package/dist/index.d.ts +33 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +30 -1
- package/dist/index.js.map +1 -0
- package/dist/logger/export.d.ts +2 -0
- package/dist/logger/export.d.ts.map +1 -0
- package/dist/logger/export.js +1 -0
- package/dist/logger/export.js.map +1 -0
- package/dist/matter/behaviors.d.ts +2 -0
- package/dist/matter/behaviors.d.ts.map +1 -0
- package/dist/matter/behaviors.js +2 -0
- package/dist/matter/behaviors.js.map +1 -0
- package/dist/matter/clusters.d.ts +2 -0
- package/dist/matter/clusters.d.ts.map +1 -0
- package/dist/matter/clusters.js +2 -0
- package/dist/matter/clusters.js.map +1 -0
- package/dist/matter/devices.d.ts +2 -0
- package/dist/matter/devices.d.ts.map +1 -0
- package/dist/matter/devices.js +2 -0
- package/dist/matter/devices.js.map +1 -0
- package/dist/matter/endpoints.d.ts +2 -0
- package/dist/matter/endpoints.d.ts.map +1 -0
- package/dist/matter/endpoints.js +2 -0
- package/dist/matter/endpoints.js.map +1 -0
- package/dist/matter/export.d.ts +5 -0
- package/dist/matter/export.d.ts.map +1 -0
- package/dist/matter/export.js +3 -0
- package/dist/matter/export.js.map +1 -0
- package/dist/matter/types.d.ts +3 -0
- package/dist/matter/types.d.ts.map +1 -0
- package/dist/matter/types.js +3 -0
- package/dist/matter/types.js.map +1 -0
- package/dist/matterbridge.d.ts +462 -0
- package/dist/matterbridge.d.ts.map +1 -0
- package/dist/matterbridge.js +789 -50
- package/dist/matterbridge.js.map +1 -0
- package/dist/matterbridgeAccessoryPlatform.d.ts +42 -0
- package/dist/matterbridgeAccessoryPlatform.d.ts.map +1 -0
- package/dist/matterbridgeAccessoryPlatform.js +36 -0
- package/dist/matterbridgeAccessoryPlatform.js.map +1 -0
- package/dist/matterbridgeBehaviors.d.ts +1351 -0
- package/dist/matterbridgeBehaviors.d.ts.map +1 -0
- package/dist/matterbridgeBehaviors.js +65 -5
- package/dist/matterbridgeBehaviors.js.map +1 -0
- package/dist/matterbridgeDeviceTypes.d.ts +709 -0
- package/dist/matterbridgeDeviceTypes.d.ts.map +1 -0
- package/dist/matterbridgeDeviceTypes.js +579 -15
- package/dist/matterbridgeDeviceTypes.js.map +1 -0
- package/dist/matterbridgeDynamicPlatform.d.ts +42 -0
- package/dist/matterbridgeDynamicPlatform.d.ts.map +1 -0
- package/dist/matterbridgeDynamicPlatform.js +36 -0
- package/dist/matterbridgeDynamicPlatform.js.map +1 -0
- package/dist/matterbridgeEndpoint.d.ts +1356 -0
- package/dist/matterbridgeEndpoint.d.ts.map +1 -0
- package/dist/matterbridgeEndpoint.js +1220 -54
- package/dist/matterbridgeEndpoint.js.map +1 -0
- package/dist/matterbridgeEndpointHelpers.d.ts +407 -0
- package/dist/matterbridgeEndpointHelpers.d.ts.map +1 -0
- package/dist/matterbridgeEndpointHelpers.js +345 -12
- package/dist/matterbridgeEndpointHelpers.js.map +1 -0
- package/dist/matterbridgePlatform.d.ts +331 -0
- package/dist/matterbridgePlatform.d.ts.map +1 -0
- package/dist/matterbridgePlatform.js +256 -0
- package/dist/matterbridgePlatform.js.map +1 -0
- package/dist/matterbridgeTypes.d.ts +198 -0
- package/dist/matterbridgeTypes.d.ts.map +1 -0
- package/dist/matterbridgeTypes.js +25 -0
- package/dist/matterbridgeTypes.js.map +1 -0
- package/dist/pluginManager.d.ts +270 -0
- package/dist/pluginManager.d.ts.map +1 -0
- package/dist/pluginManager.js +249 -3
- package/dist/pluginManager.js.map +1 -0
- package/dist/shelly.d.ts +174 -0
- package/dist/shelly.d.ts.map +1 -0
- package/dist/shelly.js +168 -7
- package/dist/shelly.js.map +1 -0
- package/dist/storage/export.d.ts +2 -0
- package/dist/storage/export.d.ts.map +1 -0
- package/dist/storage/export.js +1 -0
- package/dist/storage/export.js.map +1 -0
- package/dist/update.d.ts +75 -0
- package/dist/update.d.ts.map +1 -0
- package/dist/update.js +69 -0
- package/dist/update.js.map +1 -0
- package/dist/utils/colorUtils.d.ts +99 -0
- package/dist/utils/colorUtils.d.ts.map +1 -0
- package/dist/utils/colorUtils.js +97 -2
- package/dist/utils/colorUtils.js.map +1 -0
- package/dist/utils/commandLine.d.ts +59 -0
- package/dist/utils/commandLine.d.ts.map +1 -0
- package/dist/utils/commandLine.js +54 -0
- package/dist/utils/commandLine.js.map +1 -0
- package/dist/utils/copyDirectory.d.ts +33 -0
- package/dist/utils/copyDirectory.d.ts.map +1 -0
- package/dist/utils/copyDirectory.js +38 -1
- package/dist/utils/copyDirectory.js.map +1 -0
- package/dist/utils/createDirectory.d.ts +34 -0
- package/dist/utils/createDirectory.d.ts.map +1 -0
- package/dist/utils/createDirectory.js +33 -0
- package/dist/utils/createDirectory.js.map +1 -0
- package/dist/utils/createZip.d.ts +39 -0
- package/dist/utils/createZip.d.ts.map +1 -0
- package/dist/utils/createZip.js +47 -2
- package/dist/utils/createZip.js.map +1 -0
- package/dist/utils/deepCopy.d.ts +32 -0
- package/dist/utils/deepCopy.d.ts.map +1 -0
- package/dist/utils/deepCopy.js +39 -0
- package/dist/utils/deepCopy.js.map +1 -0
- package/dist/utils/deepEqual.d.ts +54 -0
- package/dist/utils/deepEqual.d.ts.map +1 -0
- package/dist/utils/deepEqual.js +72 -1
- package/dist/utils/deepEqual.js.map +1 -0
- package/dist/utils/error.d.ts +44 -0
- package/dist/utils/error.d.ts.map +1 -0
- package/dist/utils/error.js +41 -0
- package/dist/utils/error.js.map +1 -0
- package/dist/utils/export.d.ts +12 -0
- package/dist/utils/export.d.ts.map +1 -0
- package/dist/utils/export.js +1 -0
- package/dist/utils/export.js.map +1 -0
- package/dist/utils/hex.d.ts +89 -0
- package/dist/utils/hex.d.ts.map +1 -0
- package/dist/utils/hex.js +124 -0
- package/dist/utils/hex.js.map +1 -0
- package/dist/utils/isvalid.d.ts +103 -0
- package/dist/utils/isvalid.d.ts.map +1 -0
- package/dist/utils/isvalid.js +101 -0
- package/dist/utils/isvalid.js.map +1 -0
- package/dist/utils/network.d.ts +84 -0
- package/dist/utils/network.d.ts.map +1 -0
- package/dist/utils/network.js +91 -5
- package/dist/utils/network.js.map +1 -0
- package/dist/utils/spawn.d.ts +33 -0
- package/dist/utils/spawn.d.ts.map +1 -0
- package/dist/utils/spawn.js +40 -0
- package/dist/utils/spawn.js.map +1 -0
- package/dist/utils/wait.d.ts +54 -0
- package/dist/utils/wait.d.ts.map +1 -0
- package/dist/utils/wait.js +60 -8
- package/dist/utils/wait.js.map +1 -0
- package/npm-shrinkwrap.json +2 -2
- package/package.json +2 -1
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"dgram.d.ts","sourceRoot":"","sources":["../../src/dgram/dgram.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;GAqBG;AAGH,OAAO,KAAK,MAAM,YAAY,CAAC;AAC/B,OAAO,YAAY,MAAM,aAAa,CAAC;AACvC,OAAO,EAAE,WAAW,EAAE,MAAM,UAAU,CAAC;AAIvC,OAAO,EAAE,UAAU,EAAoD,MAAM,kBAAkB,CAAC;AAEhG;;GAEG;AACH,UAAU,WAAW;IACnB,KAAK,EAAE,CAAC,KAAK,EAAE,KAAK,CAAC,CAAC;IACtB,KAAK,EAAE,EAAE,CAAC;IACV,OAAO,EAAE,EAAE,CAAC;IACZ,OAAO,EAAE,CAAC,GAAG,EAAE,MAAM,EAAE,KAAK,EAAE,KAAK,CAAC,UAAU,CAAC,CAAC;IAChD,SAAS,EAAE,CAAC,OAAO,EAAE,WAAW,CAAC,CAAC;IAClC,IAAI,EAAE,CAAC,GAAG,EAAE,MAAM,EAAE,aAAa,EAAE,MAAM,EAAE,UAAU,EAAE,MAAM,CAAC,CAAC;IAC/D,KAAK,EAAE,CAAC,OAAO,EAAE,WAAW,CAAC,CAAC;IAC9B,KAAK,EAAE,CAAC,OAAO,EAAE,WAAW,CAAC,CAAC;CAC/B;AAED;;GAEG;AACH,qBAAa,KAAM,SAAQ,YAAY,CAAC,WAAW,CAAC;IAClD,GAAG,aAAC;IACJ,MAAM,EAAE,KAAK,CAAC,MAAM,CAAC;IACrB,KAAK,UAAS;IACd,UAAU,EAAE,MAAM,GAAG,MAAM,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SAAS,GAAG,MAAM,GAAG,SAAS;IAUvG;;;;OAIG;IACH,uBAAuB,IAAI,MAAM;IAIjC;;OAEG;IACH,qBAAqB;CAYtB"}
|
package/dist/dgram/dgram.js
CHANGED
|
@@ -1,7 +1,34 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @description This file contains the class Dgram.
|
|
3
|
+
* @file dgram.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
|
+
// Node.js imports
|
|
1
24
|
import dgram from 'node:dgram';
|
|
2
25
|
import EventEmitter from 'node:events';
|
|
3
26
|
import os from 'node:os';
|
|
27
|
+
// AnsiLogger imports
|
|
4
28
|
import { AnsiLogger, BLUE, db, idn, nf, rs } from 'node-ansi-logger';
|
|
29
|
+
/**
|
|
30
|
+
* This class implements a dgram socket.
|
|
31
|
+
*/
|
|
5
32
|
export class Dgram extends EventEmitter {
|
|
6
33
|
log;
|
|
7
34
|
socket;
|
|
@@ -10,9 +37,18 @@ export class Dgram extends EventEmitter {
|
|
|
10
37
|
interfaceName;
|
|
11
38
|
interfaceAddress;
|
|
12
39
|
interfaceNetmask;
|
|
40
|
+
/**
|
|
41
|
+
* Creates an instance of Dgram.
|
|
42
|
+
*
|
|
43
|
+
* @param {string} name - The name of the socket.
|
|
44
|
+
* @param {'udp4' | 'udp6'} socketType - The type of the socket (IPv4 or IPv6).
|
|
45
|
+
* @param {boolean | undefined} reuseAddr - Whether to allow address reuse.
|
|
46
|
+
* @param {string} [interfaceName] - The name of the network interface to bind to.
|
|
47
|
+
* @param {string} [interfaceAddress] - The address of the network interface to bind to.
|
|
48
|
+
*/
|
|
13
49
|
constructor(name, socketType, reuseAddr = true, interfaceName, interfaceAddress) {
|
|
14
50
|
super();
|
|
15
|
-
this.log = new AnsiLogger({ logName: name, logTimestampFormat: 4
|
|
51
|
+
this.log = new AnsiLogger({ logName: name, logTimestampFormat: 4 /* TimestampFormat.TIME_MILLIS */, logLevel: "debug" /* LogLevel.DEBUG */ });
|
|
16
52
|
this.socket = dgram.createSocket({ type: socketType, reuseAddr });
|
|
17
53
|
this.socketType = socketType;
|
|
18
54
|
this.interfaceName = interfaceName;
|
|
@@ -46,6 +82,13 @@ export class Dgram extends EventEmitter {
|
|
|
46
82
|
this.onListening(address);
|
|
47
83
|
});
|
|
48
84
|
}
|
|
85
|
+
/**
|
|
86
|
+
* Sends a message to the specified server.
|
|
87
|
+
*
|
|
88
|
+
* @param {Buffer} msg - The message buffer to send.
|
|
89
|
+
* @param {string} serverAddress - The IPv4 address of the destination server.
|
|
90
|
+
* @param {number} serverPort - The port of the destination server.
|
|
91
|
+
*/
|
|
49
92
|
send(msg, serverAddress, serverPort) {
|
|
50
93
|
this.socket.send(msg, 0, msg.length, serverPort, serverAddress, (error) => {
|
|
51
94
|
if (error) {
|
|
@@ -83,18 +126,30 @@ export class Dgram extends EventEmitter {
|
|
|
83
126
|
this.log.info(`Socket ready on ${BLUE}${address.family}${nf} ${BLUE}${address.address}${nf}:${BLUE}${address.port}${nf}`);
|
|
84
127
|
this.emit('ready', address);
|
|
85
128
|
}
|
|
129
|
+
/**
|
|
130
|
+
* Retrieves the IPv4 address of the specified network interface or the first external IPv4 interface if no interface is specified.
|
|
131
|
+
* Throws an error if no suitable interface or address is found.
|
|
132
|
+
*
|
|
133
|
+
* @param {string} networkInterface - The name of the network interface to retrieve the IPv4 address from. If not specified, the first external IPv4 interface will be used.
|
|
134
|
+
* @returns {string | undefined} The IPv4 address of the specified network interface or the first external IPv4 interface.
|
|
135
|
+
* @throws Error if no suitable interface or address is found.
|
|
136
|
+
*/
|
|
86
137
|
getIpv4InterfaceAddress(networkInterface) {
|
|
138
|
+
// Normalize the interface name: treat an empty string as undefined.
|
|
87
139
|
if (networkInterface === '')
|
|
88
140
|
networkInterface = undefined;
|
|
89
141
|
const interfaces = os.networkInterfaces();
|
|
142
|
+
// If a specific interface is provided but not found, warn and fall back.
|
|
90
143
|
if (networkInterface && !interfaces[networkInterface]) {
|
|
91
144
|
this.log.warn(`Interface "${networkInterface}" not found. Using first external IPv4 interface.`);
|
|
92
145
|
networkInterface = undefined;
|
|
93
146
|
}
|
|
147
|
+
// If no interface was specified or the provided one doesn't exist, find the first external IPv4 interface.
|
|
94
148
|
if (!networkInterface) {
|
|
95
149
|
for (const [interfaceName, interfaceDetails] of Object.entries(interfaces)) {
|
|
96
150
|
if (!interfaceDetails)
|
|
97
151
|
continue;
|
|
152
|
+
// Check if at least one external IPv4 address exists on this interface.
|
|
98
153
|
for (const detail of interfaceDetails) {
|
|
99
154
|
if (detail.family === 'IPv4' && !detail.internal) {
|
|
100
155
|
networkInterface = interfaceName;
|
|
@@ -108,6 +163,7 @@ export class Dgram extends EventEmitter {
|
|
|
108
163
|
if (!networkInterface) {
|
|
109
164
|
throw new Error(`Didn't find an external IPv4 network interface`);
|
|
110
165
|
}
|
|
166
|
+
// Select the first external IPv4 address from the interface.
|
|
111
167
|
const addresses = interfaces[networkInterface];
|
|
112
168
|
const ipv4Address = addresses?.find((addr) => addr.family === 'IPv4' && !addr.internal);
|
|
113
169
|
if (!ipv4Address) {
|
|
@@ -115,14 +171,25 @@ export class Dgram extends EventEmitter {
|
|
|
115
171
|
}
|
|
116
172
|
return ipv4Address.address;
|
|
117
173
|
}
|
|
174
|
+
/**
|
|
175
|
+
* Retrieves the IPv6 address of the specified network interface or the first external IPv6 interface if no interface is specified.
|
|
176
|
+
* Throws an error if no suitable interface or address is found.
|
|
177
|
+
*
|
|
178
|
+
* @param {string} [networkInterface] - The name of the network interface to retrieve the IPv6 address from. If not specified, the first external IPv6 interface will be used.
|
|
179
|
+
* @returns {string | undefined} The IPv6 address of the specified network interface or the first external IPv6 interface.
|
|
180
|
+
* @throws {Error} If no suitable interface or address is found.
|
|
181
|
+
*/
|
|
118
182
|
getIpv6InterfaceAddress(networkInterface) {
|
|
183
|
+
// Normalize the interface name: treat an empty string as undefined.
|
|
119
184
|
if (networkInterface === '')
|
|
120
185
|
networkInterface = undefined;
|
|
121
186
|
const interfaces = os.networkInterfaces();
|
|
187
|
+
// If a specific interface is provided, verify it exists. Otherwise, warn and use the first external IPv6 interface.
|
|
122
188
|
if (networkInterface && !interfaces[networkInterface]) {
|
|
123
189
|
this.log.warn(`Interface "${networkInterface}" not found. Using first external IPv6 interface.`);
|
|
124
190
|
networkInterface = undefined;
|
|
125
191
|
}
|
|
192
|
+
// If no network interface was specified, search for the first external IPv6 interface.
|
|
126
193
|
if (!networkInterface) {
|
|
127
194
|
for (const [interfaceName, interfaceDetails] of Object.entries(interfaces)) {
|
|
128
195
|
if (!interfaceDetails)
|
|
@@ -141,18 +208,21 @@ export class Dgram extends EventEmitter {
|
|
|
141
208
|
throw new Error(`Didn't find an external IPv6 network interface`);
|
|
142
209
|
}
|
|
143
210
|
const addresses = interfaces[networkInterface];
|
|
211
|
+
// Try to find a link-local address and use scopeid
|
|
144
212
|
const linkLocalAddress = addresses?.find((addr) => addr.family === 'IPv6' && !addr.internal && addr.address.startsWith('fe80'));
|
|
145
213
|
if (linkLocalAddress) {
|
|
146
214
|
this.log.debug('Found IPv6 link-local address');
|
|
147
215
|
return linkLocalAddress.scopeid ? `${linkLocalAddress.address}%${process.platform !== 'win32' ? networkInterface : linkLocalAddress.scopeid}` : linkLocalAddress.address;
|
|
148
216
|
}
|
|
149
217
|
this.log.debug('No IPv6 link-local address found');
|
|
218
|
+
// Try to find a unique local address
|
|
150
219
|
const ulaAddress = addresses?.find((addr) => addr.family === 'IPv6' && !addr.internal && addr.address.startsWith('fd') && addr.netmask === 'ffff:ffff:ffff:ffff::');
|
|
151
220
|
if (ulaAddress) {
|
|
152
221
|
this.log.debug('Found IPv6 Unique Local Addresses (ULA) unicast address');
|
|
153
222
|
return ulaAddress.address;
|
|
154
223
|
}
|
|
155
224
|
this.log.debug('No IPv6 Unique Local Addresses (ULA) unicast address found');
|
|
225
|
+
// Try to find a unique local address
|
|
156
226
|
const uniqueLocalAddress = addresses?.find((addr) => addr.family === 'IPv6' && !addr.internal && addr.address.startsWith('fd'));
|
|
157
227
|
if (uniqueLocalAddress) {
|
|
158
228
|
this.log.debug('Found IPv6 Unique Local Addresses (ULA) address');
|
|
@@ -161,6 +231,11 @@ export class Dgram extends EventEmitter {
|
|
|
161
231
|
this.log.debug('No IPv6 Unique Local Addresses (ULA) address found');
|
|
162
232
|
throw new Error(`Interface ${networkInterface} does not have a suitable external IPv6 address`);
|
|
163
233
|
}
|
|
234
|
+
/**
|
|
235
|
+
* Retrieves the names of all available network interfaces.
|
|
236
|
+
*
|
|
237
|
+
* @returns {string[]} An array of network interface names.
|
|
238
|
+
*/
|
|
164
239
|
getInterfacesNames() {
|
|
165
240
|
const interfaces = os.networkInterfaces();
|
|
166
241
|
const interfaceNames = [];
|
|
@@ -171,6 +246,11 @@ export class Dgram extends EventEmitter {
|
|
|
171
246
|
}
|
|
172
247
|
return interfaceNames;
|
|
173
248
|
}
|
|
249
|
+
/**
|
|
250
|
+
* Retrieves the scope ID for all interfaces address '::'.
|
|
251
|
+
*
|
|
252
|
+
* @returns {string} The scope ID of the first found IPv6 address or an empty string.
|
|
253
|
+
*/
|
|
174
254
|
getIpv6ScopeIdForAllInterfacesAddress() {
|
|
175
255
|
const interfaces = os.networkInterfaces();
|
|
176
256
|
for (const name in interfaces) {
|
|
@@ -178,17 +258,24 @@ export class Dgram extends EventEmitter {
|
|
|
178
258
|
if (iface) {
|
|
179
259
|
const ipv6Address = iface.find((addr) => addr.family === 'IPv6' && !addr.internal && addr.scopeid);
|
|
180
260
|
if (ipv6Address) {
|
|
181
|
-
return process.platform === 'win32' ? '%' + String(ipv6Address.scopeid) : '%' + name;
|
|
261
|
+
return process.platform === 'win32' ? '%' + String(ipv6Address.scopeid) : '%' + name; // Use the scope ID for Windows, or the interface name for non-Windows platforms
|
|
182
262
|
}
|
|
183
263
|
}
|
|
184
264
|
}
|
|
185
265
|
return '';
|
|
186
266
|
}
|
|
267
|
+
/**
|
|
268
|
+
* Retrieves the interface name from the scope id of an IPv6 address.
|
|
269
|
+
*
|
|
270
|
+
* @param {number} scopeId - The scope id of the IPv6 address.
|
|
271
|
+
* @returns {string | undefined} The interface name or undefined if not found.
|
|
272
|
+
*/
|
|
187
273
|
getInterfaceNameFromScopeId(scopeId) {
|
|
188
274
|
const nets = os.networkInterfaces();
|
|
189
275
|
for (const ifaceName in nets) {
|
|
190
276
|
const addresses = nets[ifaceName] || [];
|
|
191
277
|
for (const addr of addresses) {
|
|
278
|
+
// Check for IPv6 addresses with a matching scope id.
|
|
192
279
|
if (addr.family === 'IPv6' && addr.scopeid === scopeId) {
|
|
193
280
|
return ifaceName;
|
|
194
281
|
}
|
|
@@ -196,8 +283,16 @@ export class Dgram extends EventEmitter {
|
|
|
196
283
|
}
|
|
197
284
|
return undefined;
|
|
198
285
|
}
|
|
286
|
+
/**
|
|
287
|
+
* Retrieves the netmask of the specified interface address.
|
|
288
|
+
*
|
|
289
|
+
* @param {string} interfaceAddress - The interface address for which to retrieve the netmask.
|
|
290
|
+
* @returns {string | undefined} The netmask of the specified interface address or undefined if not found.
|
|
291
|
+
*/
|
|
199
292
|
getNetmask(interfaceAddress) {
|
|
293
|
+
// Remove zone index if present (e.g. for IPv6 "fe80::1%eth0")
|
|
200
294
|
const cleanedAddress = interfaceAddress.includes('%') ? interfaceAddress.split('%')[0] : interfaceAddress;
|
|
295
|
+
// Iterate over all interfaces.
|
|
201
296
|
const nets = os.networkInterfaces();
|
|
202
297
|
for (const ifaceName in nets) {
|
|
203
298
|
const ifaceAddresses = nets[ifaceName];
|
|
@@ -211,6 +306,13 @@ export class Dgram extends EventEmitter {
|
|
|
211
306
|
}
|
|
212
307
|
return undefined;
|
|
213
308
|
}
|
|
309
|
+
/**
|
|
310
|
+
* Computes the broadcast address given an IPv4 address and netmask.
|
|
311
|
+
*
|
|
312
|
+
* @param {string | undefined} [ipAddress] - The IPv4 address e.g. "192.168.1.20"
|
|
313
|
+
* @param {string | undefined} [netmask] - The IPv4 netmask e.g. "255.255.255.0"
|
|
314
|
+
* @returns {string | undefined} The computed broadcast address, e.g. "192.168.1.255"
|
|
315
|
+
*/
|
|
214
316
|
getIpv4BroadcastAddress(ipAddress, netmask) {
|
|
215
317
|
if (!ipAddress || !netmask) {
|
|
216
318
|
return undefined;
|
|
@@ -220,9 +322,17 @@ export class Dgram extends EventEmitter {
|
|
|
220
322
|
const broadcastParts = ipParts.map((octet, i) => (octet & maskParts[i]) | (255 - maskParts[i]));
|
|
221
323
|
return broadcastParts.join('.');
|
|
222
324
|
}
|
|
325
|
+
/**
|
|
326
|
+
* Returns the broadcast IPv6 address.
|
|
327
|
+
*
|
|
328
|
+
* @returns {string} The broadcast IPv6 address, e.g. "ff02::1"
|
|
329
|
+
*/
|
|
223
330
|
getIpv6BroadcastAddress() {
|
|
224
331
|
return 'ff02::1';
|
|
225
332
|
}
|
|
333
|
+
/**
|
|
334
|
+
* Logs all available network interfaces and their details.
|
|
335
|
+
*/
|
|
226
336
|
listNetworkInterfaces() {
|
|
227
337
|
const interfaces = os.networkInterfaces();
|
|
228
338
|
for (const [name, addresses] of Object.entries(interfaces)) {
|
|
@@ -235,3 +345,4 @@ export class Dgram extends EventEmitter {
|
|
|
235
345
|
}
|
|
236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AE,GAAG,EAAE,EAAE,CAAC,CAAC;YACrD,KAAK,MAAM,OAAO,IAAI,SAAS,EAAE,CAAC;gBAChC,IAAI,CAAC,GAAG,CAAC,KAAK,CACZ,aAAa,IAAI,GAAG,OAAO,CAAC,OAAO,GAAG,EAAE,YAAY,IAAI,GAAG,OAAO,CAAC,OAAO,GAAG,EAAE,IAAI,OAAO,CAAC,GAAG,CAAC,CAAC,CAAC,OAAO,GAAG,IAAI,GAAG,OAAO,CAAC,GAAG,GAAG,EAAE,CAAC,CAAC,CAAC,EAAE,UAAU,IAAI,GAAG,OAAO,CAAC,MAAM,GAAG,EAAE,IAAI,IAAI,GAAG,OAAO,CAAC,QAAQ,CAAC,CAAC,CAAC,UAAU,CAAC,CAAC,CAAC,UAAU,GAAG,EAAE,IAAI,OAAO,CAAC,OAAO,KAAK,SAAS,CAAC,CAAC,CAAC,WAAW,GAAG,IAAI,GAAG,OAAO,CAAC,OAAO,GAAG,EAAE,CAAC,CAAC,CAAC,EAAE,UAAU,IAAI,GAAG,OAAO,CAAC,IAAI,GAAG,EAAE,EAAE,CAC5V,CAAC;YACJ,CAAC;QACH,CAAC;IACH,CAAC;CACF"}
|
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @description This file contains the bin mb_coap for the class Coap.
|
|
3
|
+
* @file src/dgram/mb_coap.ts
|
|
4
|
+
* @author Luca Liguori
|
|
5
|
+
* @created 2025-07-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
|
+
export {};
|
|
24
|
+
//# sourceMappingURL=mb_coap.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"mb_coap.d.ts","sourceRoot":"","sources":["../../src/dgram/mb_coap.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;GAqBG"}
|
package/dist/dgram/mb_coap.js
CHANGED
|
@@ -1,28 +1,65 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @description This file contains the bin mb_coap for the class Coap.
|
|
3
|
+
* @file src/dgram/mb_coap.ts
|
|
4
|
+
* @author Luca Liguori
|
|
5
|
+
* @created 2025-07-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
|
+
// Net imports
|
|
1
24
|
import { COAP_MULTICAST_IPV4_ADDRESS, COAP_MULTICAST_IPV6_ADDRESS, COAP_MULTICAST_PORT } from './multicast.js';
|
|
2
25
|
import { Coap, COAP_OPTION_URI_PATH } from './coap.js';
|
|
26
|
+
// istanbul ignore next
|
|
3
27
|
{
|
|
4
28
|
const coapIpv4 = new Coap('CoAP Server udp4', COAP_MULTICAST_IPV4_ADDRESS, COAP_MULTICAST_PORT, 'udp4', true);
|
|
5
29
|
const coapIpv6 = new Coap('CoAP Server udp6', COAP_MULTICAST_IPV6_ADDRESS, COAP_MULTICAST_PORT, 'udp6', true);
|
|
6
30
|
coapIpv4.listNetworkInterfaces();
|
|
31
|
+
/**
|
|
32
|
+
* Cleanup and log device information before exiting.
|
|
33
|
+
*/
|
|
7
34
|
function cleanupAndLogAndExit() {
|
|
8
35
|
if (process.argv.includes('--coap-udp4'))
|
|
9
36
|
coapIpv4.stop();
|
|
10
37
|
if (process.argv.includes('--coap-udp6'))
|
|
11
38
|
coapIpv6.stop();
|
|
39
|
+
// eslint-disable-next-line n/no-process-exit
|
|
12
40
|
process.exit(0);
|
|
13
41
|
}
|
|
42
|
+
/**
|
|
43
|
+
* Queries mDNS services over UDP IPv4 and sends a response for a specific service instance.
|
|
44
|
+
* This function sends a query for Shelly, HTTP, and services, and responds with the appropriate PTR records.
|
|
45
|
+
*/
|
|
14
46
|
const requestUdp4 = () => {
|
|
15
47
|
coapIpv4.sendRequest(32000, [
|
|
16
48
|
{ number: COAP_OPTION_URI_PATH, value: Buffer.from('cit') },
|
|
17
49
|
{ number: COAP_OPTION_URI_PATH, value: Buffer.from('d') },
|
|
18
50
|
], {}, undefined, COAP_MULTICAST_IPV4_ADDRESS, COAP_MULTICAST_PORT);
|
|
19
51
|
};
|
|
52
|
+
/**
|
|
53
|
+
* Queries mDNS services over UDP IPv4 and sends a response for a specific service instance.
|
|
54
|
+
* This function sends a query for Shelly, HTTP, and services, and responds with the appropriate PTR records.
|
|
55
|
+
*/
|
|
20
56
|
const requestUdp6 = () => {
|
|
21
57
|
coapIpv6.sendRequest(32000, [
|
|
22
58
|
{ number: COAP_OPTION_URI_PATH, value: Buffer.from('cit') },
|
|
23
59
|
{ number: COAP_OPTION_URI_PATH, value: Buffer.from('d') },
|
|
24
60
|
], {}, undefined, COAP_MULTICAST_IPV6_ADDRESS, COAP_MULTICAST_PORT);
|
|
25
61
|
};
|
|
62
|
+
// Handle Ctrl+C (SIGINT) to stop and log devices
|
|
26
63
|
process.on('SIGINT', () => {
|
|
27
64
|
cleanupAndLogAndExit();
|
|
28
65
|
});
|
|
@@ -30,7 +67,7 @@ import { Coap, COAP_OPTION_URI_PATH } from './coap.js';
|
|
|
30
67
|
coapIpv4.on('ready', (address) => {
|
|
31
68
|
coapIpv4.log.info(`coapIpv4 server ready on ${address.family} ${address.address}:${address.port}`);
|
|
32
69
|
if (!process.argv.includes('--coap-request'))
|
|
33
|
-
return;
|
|
70
|
+
return; // Skip querying if --coap-request is not specified
|
|
34
71
|
requestUdp4();
|
|
35
72
|
setInterval(() => {
|
|
36
73
|
requestUdp4();
|
|
@@ -40,7 +77,7 @@ import { Coap, COAP_OPTION_URI_PATH } from './coap.js';
|
|
|
40
77
|
coapIpv6.on('ready', (address) => {
|
|
41
78
|
coapIpv6.log.info(`coapIpv6 server ready on ${address.family} ${address.address}:${address.port}`);
|
|
42
79
|
if (!process.argv.includes('--coap-request'))
|
|
43
|
-
return;
|
|
80
|
+
return; // Skip querying if --coap-request is not specified
|
|
44
81
|
requestUdp6();
|
|
45
82
|
setInterval(() => {
|
|
46
83
|
requestUdp6();
|
|
@@ -48,5 +85,6 @@ import { Coap, COAP_OPTION_URI_PATH } from './coap.js';
|
|
|
48
85
|
});
|
|
49
86
|
setTimeout(() => {
|
|
50
87
|
cleanupAndLogAndExit();
|
|
51
|
-
}, 600000);
|
|
88
|
+
}, 600000); // 10 minutes timeout to exit if no activity
|
|
52
89
|
}
|
|
90
|
+
//# sourceMappingURL=mb_coap.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"mb_coap.js","sourceRoot":"","sources":["../../src/dgram/mb_coap.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;GAqBG;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AE,CAAC;QACd,WAAW,CAAC,GAAG,EAAE;YACf,WAAW,EAAE,CAAC;QAChB,CAAC,EAAE,KAAK,CAAC,CAAC,KAAK,EAAE,CAAC;IACpB,CAAC,CAAC,CAAC;IAEH,UAAU,CAAC,GAAG,EAAE;QACd,oBAAoB,EAAE,CAAC;IACzB,CAAC,EAAE,MAAM,CAAC,CAAC,CAAC,4CAA4C;AAC1D,CAAC"}
|
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @description This file contains the bin mb_mdns for the class Mdns.
|
|
3
|
+
* @file src/dgram/mb_mdns.ts
|
|
4
|
+
* @author Luca Liguori
|
|
5
|
+
* @created 2025-07-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
|
+
export {};
|
|
24
|
+
//# sourceMappingURL=mb_mdns.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"mb_mdns.d.ts","sourceRoot":"","sources":["../../src/dgram/mb_mdns.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;GAqBG"}
|
package/dist/dgram/mb_mdns.js
CHANGED
|
@@ -1,36 +1,73 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @description This file contains the bin mb_mdns for the class Mdns.
|
|
3
|
+
* @file src/dgram/mb_mdns.ts
|
|
4
|
+
* @author Luca Liguori
|
|
5
|
+
* @created 2025-07-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
|
+
// Net imports
|
|
1
24
|
import { MDNS_MULTICAST_IPV4_ADDRESS, MDNS_MULTICAST_IPV6_ADDRESS, MDNS_MULTICAST_PORT } from './multicast.js';
|
|
2
25
|
import { Mdns } from './mdns.js';
|
|
26
|
+
// istanbul ignore next
|
|
3
27
|
{
|
|
4
28
|
const mdnsIpv4 = new Mdns('mDNS Server udp4', MDNS_MULTICAST_IPV4_ADDRESS, MDNS_MULTICAST_PORT, 'udp4', true, undefined, '0.0.0.0');
|
|
5
29
|
const mdnsIpv6 = new Mdns('mDNS Server udp6', MDNS_MULTICAST_IPV6_ADDRESS, MDNS_MULTICAST_PORT, 'udp6', true, undefined, '::');
|
|
6
30
|
mdnsIpv4.listNetworkInterfaces();
|
|
31
|
+
/**
|
|
32
|
+
* Cleanup and log device information before exiting.
|
|
33
|
+
*/
|
|
7
34
|
function cleanupAndLogAndExit() {
|
|
8
35
|
mdnsIpv4.stop();
|
|
9
36
|
mdnsIpv6.stop();
|
|
10
37
|
mdnsIpv4.logDevices();
|
|
11
38
|
mdnsIpv6.logDevices();
|
|
39
|
+
// eslint-disable-next-line n/no-process-exit
|
|
12
40
|
process.exit(0);
|
|
13
41
|
}
|
|
42
|
+
/**
|
|
43
|
+
* Queries mDNS services over UDP IPv4 and sends a response for a specific service instance.
|
|
44
|
+
* This function sends a query for Shelly, HTTP, and services, and responds with the appropriate PTR records.
|
|
45
|
+
*/
|
|
14
46
|
const queryUdp4 = () => {
|
|
15
47
|
mdnsIpv4.sendQuery([
|
|
16
|
-
{ name: '_matter._tcp.local', type: 12
|
|
17
|
-
{ name: '_shelly._tcp.local', type: 12
|
|
18
|
-
{ name: '_http._tcp.local', type: 12
|
|
19
|
-
{ name: '_services._dns-sd._udp.local', type: 12
|
|
48
|
+
{ name: '_matter._tcp.local', type: 12 /* DnsRecordType.PTR */, class: 1 /* DnsClass.IN */, unicastResponse: false },
|
|
49
|
+
{ name: '_shelly._tcp.local', type: 12 /* DnsRecordType.PTR */, class: 1 /* DnsClass.IN */, unicastResponse: false },
|
|
50
|
+
{ name: '_http._tcp.local', type: 12 /* DnsRecordType.PTR */, class: 1 /* DnsClass.IN */, unicastResponse: false },
|
|
51
|
+
{ name: '_services._dns-sd._udp.local', type: 12 /* DnsRecordType.PTR */, class: 1 /* DnsClass.IN */, unicastResponse: false },
|
|
20
52
|
]);
|
|
21
53
|
const ptrRdata = mdnsIpv4.encodeDnsName('matterbridge._http._tcp.local');
|
|
22
|
-
mdnsIpv4.sendResponse('_http._tcp.local', 12
|
|
54
|
+
mdnsIpv4.sendResponse('_http._tcp.local', 12 /* DnsRecordType.PTR */, 1 /* DnsClass.IN */, 120, ptrRdata);
|
|
23
55
|
};
|
|
56
|
+
/**
|
|
57
|
+
* Queries mDNS services over UDP IPv6 and sends a response for a specific service instance.
|
|
58
|
+
* This function sends a query for Shelly, HTTP, and services, and responds with the appropriate PTR records.
|
|
59
|
+
*/
|
|
24
60
|
const queryUdp6 = () => {
|
|
25
61
|
mdnsIpv6.sendQuery([
|
|
26
|
-
{ name: '_matter._tcp.local', type: 12
|
|
27
|
-
{ name: '_shelly._tcp.local', type: 12
|
|
28
|
-
{ name: '_http._tcp.local', type: 12
|
|
29
|
-
{ name: '_services._dns-sd._udp.local', type: 12
|
|
62
|
+
{ name: '_matter._tcp.local', type: 12 /* DnsRecordType.PTR */, class: 1 /* DnsClass.IN */, unicastResponse: true },
|
|
63
|
+
{ name: '_shelly._tcp.local', type: 12 /* DnsRecordType.PTR */, class: 1 /* DnsClass.IN */, unicastResponse: true },
|
|
64
|
+
{ name: '_http._tcp.local', type: 12 /* DnsRecordType.PTR */, class: 1 /* DnsClass.IN */, unicastResponse: true },
|
|
65
|
+
{ name: '_services._dns-sd._udp.local', type: 12 /* DnsRecordType.PTR */, class: 1 /* DnsClass.IN */, unicastResponse: true },
|
|
30
66
|
]);
|
|
31
67
|
const ptrRdata = mdnsIpv6.encodeDnsName('matterbridge._http._tcp.local');
|
|
32
|
-
mdnsIpv6.sendResponse('_http._tcp.local', 12
|
|
68
|
+
mdnsIpv6.sendResponse('_http._tcp.local', 12 /* DnsRecordType.PTR */, 1 /* DnsClass.IN */, 120, ptrRdata);
|
|
33
69
|
};
|
|
70
|
+
// Handle Ctrl+C (SIGINT) to stop and log devices
|
|
34
71
|
process.on('SIGINT', () => {
|
|
35
72
|
cleanupAndLogAndExit();
|
|
36
73
|
});
|
|
@@ -38,7 +75,7 @@ import { Mdns } from './mdns.js';
|
|
|
38
75
|
mdnsIpv4.on('ready', (address) => {
|
|
39
76
|
mdnsIpv4.log.info(`mdnsIpv4 server ready on ${address.family} ${address.address}:${address.port}`);
|
|
40
77
|
if (!process.argv.includes('--query'))
|
|
41
|
-
return;
|
|
78
|
+
return; // Skip querying if --query is not specified
|
|
42
79
|
queryUdp4();
|
|
43
80
|
setInterval(() => {
|
|
44
81
|
queryUdp4();
|
|
@@ -48,7 +85,7 @@ import { Mdns } from './mdns.js';
|
|
|
48
85
|
mdnsIpv6.on('ready', (address) => {
|
|
49
86
|
mdnsIpv6.log.info(`mdnsIpv6 server ready on ${address.family} ${address.address}:${address.port}`);
|
|
50
87
|
if (!process.argv.includes('--query'))
|
|
51
|
-
return;
|
|
88
|
+
return; // Skip querying if --query is not specified
|
|
52
89
|
queryUdp6();
|
|
53
90
|
setInterval(() => {
|
|
54
91
|
queryUdp6();
|
|
@@ -56,5 +93,6 @@ import { Mdns } from './mdns.js';
|
|
|
56
93
|
});
|
|
57
94
|
setTimeout(() => {
|
|
58
95
|
cleanupAndLogAndExit();
|
|
59
|
-
}, 600000);
|
|
96
|
+
}, 600000); // 10 minutes timeout to exit if no activity
|
|
60
97
|
}
|
|
98
|
+
//# sourceMappingURL=mb_mdns.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"mb_mdns.js","sourceRoot":"","sources":["../../src/dgram/mb_mdns.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;GAqBG;AAKH,cAAc;AACd,OAAO,EAAE,2BAA2B,EAAE,2BAA2B,EAAE,mBAAmB,EAAE,MAAM,gBAAgB,CAAC;AAC/G,OAAO,EAA2B,IAAI,EAAE,MAAM,WAAW,CAAC;AAE1D,uBAAuB;AACvB,CAAC;IACC,MAAM,QAAQ,GAAG,IAAI,IAAI,CAAC,kBAAkB,EAAE,2BAA2B,EAAE,mBAAmB,EAAE,MAAM,EAAE,IAAI,EAAE,SAAS,EAAE,SAAS,CAAC,CAAC;IACpI,MAAM,QAAQ,GAAG,IAAI,IAAI,CAAC,kBAAkB,EAAE,2BAA2B,EAAE,mBAAmB,EAAE,MAAM,EAAE,IAAI,EAAE,SAAS,EAAE,IAAI,CAAC,CAAC;IAC/H,QAAQ,CAAC,qBAAqB,EAAE,CAAC;IAEjC;;OAEG;IACH,SAAS,oBAAoB;QAC3B,QAAQ,CAAC,IAAI,EAAE,CAAC;QAChB,QAAQ,CAAC,IAAI,EAAE,CAAC;QAChB,QAAQ,CAAC,UAAU,EAAE,CAAC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