matterbridge 3.4.6-dev-20260102-b04c53d → 3.4.6
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 +1 -1
- package/dist/broadcastServer.d.ts +144 -0
- package/dist/broadcastServer.d.ts.map +1 -0
- package/dist/broadcastServer.js +117 -0
- package/dist/broadcastServer.js.map +1 -0
- package/dist/broadcastServerTypes.d.ts +841 -0
- package/dist/broadcastServerTypes.d.ts.map +1 -0
- package/dist/broadcastServerTypes.js +24 -0
- package/dist/broadcastServerTypes.js.map +1 -0
- package/dist/cli.d.ts +30 -0
- package/dist/cli.d.ts.map +1 -0
- package/dist/cli.js +97 -1
- package/dist/cli.js.map +1 -0
- package/dist/cliEmitter.d.ts +50 -0
- package/dist/cliEmitter.d.ts.map +1 -0
- package/dist/cliEmitter.js +37 -0
- package/dist/cliEmitter.js.map +1 -0
- package/dist/cliHistory.d.ts +48 -0
- package/dist/cliHistory.d.ts.map +1 -0
- package/dist/cliHistory.js +38 -0
- package/dist/cliHistory.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/deviceManager.d.ts +135 -0
- package/dist/deviceManager.d.ts.map +1 -0
- package/dist/deviceManager.js +113 -1
- package/dist/deviceManager.js.map +1 -0
- package/dist/devices/airConditioner.d.ts +98 -0
- package/dist/devices/airConditioner.d.ts.map +1 -0
- package/dist/devices/airConditioner.js +57 -0
- package/dist/devices/airConditioner.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 +61 -0
- package/dist/devices/cooktop.d.ts.map +1 -0
- package/dist/devices/cooktop.js +56 -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 +76 -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 +17 -0
- package/dist/devices/export.d.ts.map +1 -0
- package/dist/devices/export.js +5 -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 +43 -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 +118 -0
- package/dist/devices/refrigerator.d.ts.map +1 -0
- package/dist/devices/refrigerator.js +102 -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 +100 -9
- 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/speaker.d.ts +87 -0
- package/dist/devices/speaker.d.ts.map +1 -0
- package/dist/devices/speaker.js +84 -0
- package/dist/devices/speaker.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 +24 -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 +143 -0
- package/dist/dgram/dgram.d.ts.map +1 -0
- package/dist/dgram/dgram.js +114 -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 +77 -23
- package/dist/dgram/mb_mdns.js.map +1 -0
- package/dist/dgram/mdns.d.ts +371 -0
- package/dist/dgram/mdns.d.ts.map +1 -0
- package/dist/dgram/mdns.js +371 -139
- package/dist/dgram/mdns.js.map +1 -0
- package/dist/dgram/mdnsReflectorClient.d.ts +88 -0
- package/dist/dgram/mdnsReflectorClient.d.ts.map +1 -0
- package/dist/dgram/mdnsReflectorClient.js +71 -5
- package/dist/dgram/mdnsReflectorClient.js.map +1 -0
- package/dist/dgram/mdnsReflectorServer.d.ts +78 -0
- package/dist/dgram/mdnsReflectorServer.d.ts.map +1 -0
- package/dist/dgram/mdnsReflectorServer.js +73 -8
- package/dist/dgram/mdnsReflectorServer.js.map +1 -0
- package/dist/dgram/mdnsReflectorTypes.d.ts +28 -0
- package/dist/dgram/mdnsReflectorTypes.d.ts.map +1 -0
- package/dist/dgram/mdnsReflectorTypes.js +24 -1
- package/dist/dgram/mdnsReflectorTypes.js.map +1 -0
- package/dist/dgram/multicast.d.ts +67 -0
- package/dist/dgram/multicast.d.ts.map +1 -0
- package/dist/dgram/multicast.js +62 -1
- package/dist/dgram/multicast.js.map +1 -0
- package/dist/dgram/unicast.d.ts +64 -0
- package/dist/dgram/unicast.d.ts.map +1 -0
- package/dist/dgram/unicast.js +60 -0
- package/dist/dgram/unicast.js.map +1 -0
- package/dist/frontend.d.ts +245 -0
- package/dist/frontend.d.ts.map +1 -0
- package/dist/frontend.js +485 -38
- package/dist/frontend.js.map +1 -0
- package/dist/frontendTypes.d.ts +529 -0
- package/dist/frontendTypes.d.ts.map +1 -0
- package/dist/frontendTypes.js +45 -0
- package/dist/frontendTypes.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 +34 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +25 -0
- package/dist/index.js.map +1 -0
- package/dist/jestutils/export.d.ts +2 -0
- package/dist/jestutils/export.d.ts.map +1 -0
- package/dist/jestutils/export.js +1 -0
- package/dist/jestutils/export.js.map +1 -0
- package/dist/jestutils/jestHelpers.d.ts +345 -0
- package/dist/jestutils/jestHelpers.d.ts.map +1 -0
- package/dist/jestutils/jestHelpers.js +371 -14
- package/dist/jestutils/jestHelpers.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/matterNode.d.ts +342 -0
- package/dist/matterNode.d.ts.map +1 -0
- package/dist/matterNode.js +369 -8
- package/dist/matterNode.js.map +1 -0
- package/dist/matterbridge.d.ts +505 -0
- package/dist/matterbridge.d.ts.map +1 -0
- package/dist/matterbridge.js +824 -46
- package/dist/matterbridge.js.map +1 -0
- package/dist/matterbridgeAccessoryPlatform.d.ts +41 -0
- package/dist/matterbridgeAccessoryPlatform.d.ts.map +1 -0
- package/dist/matterbridgeAccessoryPlatform.js +38 -0
- package/dist/matterbridgeAccessoryPlatform.js.map +1 -0
- package/dist/matterbridgeBehaviors.d.ts +2404 -0
- package/dist/matterbridgeBehaviors.d.ts.map +1 -0
- package/dist/matterbridgeBehaviors.js +68 -5
- package/dist/matterbridgeBehaviors.js.map +1 -0
- package/dist/matterbridgeDeviceTypes.d.ts +698 -0
- package/dist/matterbridgeDeviceTypes.d.ts.map +1 -0
- package/dist/matterbridgeDeviceTypes.js +635 -14
- package/dist/matterbridgeDeviceTypes.js.map +1 -0
- package/dist/matterbridgeDynamicPlatform.d.ts +41 -0
- package/dist/matterbridgeDynamicPlatform.d.ts.map +1 -0
- package/dist/matterbridgeDynamicPlatform.js +38 -0
- package/dist/matterbridgeDynamicPlatform.js.map +1 -0
- package/dist/matterbridgeEndpoint.d.ts +1507 -0
- package/dist/matterbridgeEndpoint.d.ts.map +1 -0
- package/dist/matterbridgeEndpoint.js +1457 -53
- package/dist/matterbridgeEndpoint.js.map +1 -0
- package/dist/matterbridgeEndpointHelpers.d.ts +787 -0
- package/dist/matterbridgeEndpointHelpers.d.ts.map +1 -0
- package/dist/matterbridgeEndpointHelpers.js +483 -20
- package/dist/matterbridgeEndpointHelpers.js.map +1 -0
- package/dist/matterbridgeEndpointTypes.d.ts +166 -0
- package/dist/matterbridgeEndpointTypes.d.ts.map +1 -0
- package/dist/matterbridgeEndpointTypes.js +25 -0
- package/dist/matterbridgeEndpointTypes.js.map +1 -0
- package/dist/matterbridgePlatform.d.ts +539 -0
- package/dist/matterbridgePlatform.d.ts.map +1 -0
- package/dist/matterbridgePlatform.js +451 -1
- package/dist/matterbridgePlatform.js.map +1 -0
- package/dist/matterbridgeTypes.d.ts +252 -0
- package/dist/matterbridgeTypes.d.ts.map +1 -0
- package/dist/matterbridgeTypes.js +26 -0
- package/dist/matterbridgeTypes.js.map +1 -0
- package/dist/pluginManager.d.ts +372 -0
- package/dist/pluginManager.d.ts.map +1 -0
- package/dist/pluginManager.js +341 -5
- package/dist/pluginManager.js.map +1 -0
- package/dist/shelly.d.ts +181 -0
- package/dist/shelly.d.ts.map +1 -0
- package/dist/shelly.js +178 -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 +84 -0
- package/dist/update.d.ts.map +1 -0
- package/dist/update.js +93 -1
- package/dist/update.js.map +1 -0
- package/dist/utils/colorUtils.d.ts +101 -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 +66 -0
- package/dist/utils/commandLine.d.ts.map +1 -0
- package/dist/utils/commandLine.js +60 -0
- package/dist/utils/commandLine.js.map +1 -0
- package/dist/utils/copyDirectory.d.ts +35 -0
- package/dist/utils/copyDirectory.d.ts.map +1 -0
- package/dist/utils/copyDirectory.js +37 -0
- 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 +45 -0
- package/dist/utils/error.d.ts.map +1 -0
- package/dist/utils/error.js +42 -0
- package/dist/utils/error.js.map +1 -0
- package/dist/utils/export.d.ts +13 -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/format.d.ts +53 -0
- package/dist/utils/format.d.ts.map +1 -0
- package/dist/utils/format.js +49 -0
- package/dist/utils/format.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/inspector.d.ts +87 -0
- package/dist/utils/inspector.d.ts.map +1 -0
- package/dist/utils/inspector.js +69 -1
- package/dist/utils/inspector.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 +93 -0
- package/dist/utils/isValid.js.map +1 -0
- package/dist/utils/network.d.ts +140 -0
- package/dist/utils/network.d.ts.map +1 -0
- package/dist/utils/network.js +126 -6
- 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 +71 -1
- package/dist/utils/spawn.js.map +1 -0
- package/dist/utils/tracker.d.ts +108 -0
- package/dist/utils/tracker.d.ts.map +1 -0
- package/dist/utils/tracker.js +64 -1
- package/dist/utils/tracker.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/dist/workerGlobalPrefix.d.ts +25 -0
- package/dist/workerGlobalPrefix.d.ts.map +1 -0
- package/dist/workerGlobalPrefix.js +37 -5
- package/dist/workerGlobalPrefix.js.map +1 -0
- package/dist/workerTypes.d.ts +52 -0
- package/dist/workerTypes.d.ts.map +1 -0
- package/dist/workerTypes.js +24 -0
- package/dist/workerTypes.js.map +1 -0
- package/dist/workers.d.ts +69 -0
- package/dist/workers.d.ts.map +1 -0
- package/dist/workers.js +68 -4
- package/dist/workers.js.map +1 -0
- package/npm-shrinkwrap.json +2 -2
- package/package.json +2 -1
package/dist/dgram/mb_mdns.js
CHANGED
|
@@ -1,12 +1,39 @@
|
|
|
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
|
+
*/
|
|
1
23
|
import os from 'node:os';
|
|
24
|
+
// Matterbridge
|
|
2
25
|
import { getIntParameter, getParameter, getStringArrayParameter, hasParameter } from '../utils/commandLine.js';
|
|
26
|
+
// Net imports
|
|
3
27
|
import { MDNS_MULTICAST_IPV4_ADDRESS, MDNS_MULTICAST_IPV6_ADDRESS, MDNS_MULTICAST_PORT } from './multicast.js';
|
|
4
28
|
import { Mdns } from './mdns.js';
|
|
5
29
|
import { MdnsReflectorClient } from './mdnsReflectorClient.js';
|
|
6
30
|
import { MdnsReflectorServer } from './mdnsReflectorServer.js';
|
|
31
|
+
// istanbul ignore next
|
|
7
32
|
{
|
|
8
33
|
if (hasParameter('h') || hasParameter('help')) {
|
|
34
|
+
// eslint-disable-next-line no-console
|
|
9
35
|
console.log(`Copyright (c) Matterbridge. All rights reserved. Version 1.0.0.\n`);
|
|
36
|
+
// eslint-disable-next-line no-console
|
|
10
37
|
console.log(`Usage: mb_mdns [options...]
|
|
11
38
|
|
|
12
39
|
If no command line is provided, mb_mdns shows all incoming mDNS records on all interfaces (0.0.0.0 and ::).
|
|
@@ -55,8 +82,10 @@ Examples:
|
|
|
55
82
|
# Query each 5s and listen for _matterbridge._tcp.local service records
|
|
56
83
|
mb_mdns --query 5000 --filter _matterbridge._tcp.local
|
|
57
84
|
`);
|
|
85
|
+
// eslint-disable-next-line n/no-process-exit
|
|
58
86
|
process.exit(0);
|
|
59
87
|
}
|
|
88
|
+
// Dynamic JSON import (Node >= 20) with import attributes
|
|
60
89
|
const { default: pkg } = await import('../../package.json', { with: { type: 'json' } });
|
|
61
90
|
let mdnsIpv4QueryInterval;
|
|
62
91
|
let mdnsIpv6QueryInterval;
|
|
@@ -66,6 +95,9 @@ Examples:
|
|
|
66
95
|
let mdnsIpv6 = undefined;
|
|
67
96
|
let reflectorClient = undefined;
|
|
68
97
|
let reflectorServer = undefined;
|
|
98
|
+
/**
|
|
99
|
+
* Cleanup and log device information before exiting.
|
|
100
|
+
*/
|
|
69
101
|
async function cleanupAndLogAndExit() {
|
|
70
102
|
clearInterval(mdnsIpv4QueryInterval);
|
|
71
103
|
clearInterval(mdnsIpv6QueryInterval);
|
|
@@ -73,32 +105,38 @@ Examples:
|
|
|
73
105
|
clearInterval(mdnsIpv6AdvertiseInterval);
|
|
74
106
|
if (hasParameter('advertise')) {
|
|
75
107
|
if (mdnsIpv4)
|
|
76
|
-
advertise(mdnsIpv4, 0);
|
|
108
|
+
advertise(mdnsIpv4, 0); // Send goodbye with TTL 0
|
|
77
109
|
if (mdnsIpv6)
|
|
78
|
-
advertise(mdnsIpv6, 0);
|
|
110
|
+
advertise(mdnsIpv6, 0); // Send goodbye with TTL 0
|
|
79
111
|
}
|
|
80
|
-
await new Promise((resolve) => setTimeout(resolve, 250));
|
|
112
|
+
await new Promise((resolve) => setTimeout(resolve, 250)); // Wait for 250ms to allow goodbye messages to be sent
|
|
81
113
|
mdnsIpv4?.stop();
|
|
82
114
|
mdnsIpv6?.stop();
|
|
83
115
|
mdnsIpv4?.logDevices();
|
|
84
116
|
mdnsIpv6?.logDevices();
|
|
85
|
-
await new Promise((resolve) => setTimeout(resolve, 250));
|
|
117
|
+
await new Promise((resolve) => setTimeout(resolve, 250)); // Wait for 250ms to allow sockets to close
|
|
86
118
|
await reflectorClient?.stop();
|
|
87
119
|
await reflectorServer?.stop();
|
|
88
120
|
}
|
|
89
121
|
const query = (mdns) => {
|
|
90
122
|
mdns.log.info('Sending mDNS query for common services...');
|
|
91
123
|
mdns.sendQuery([
|
|
92
|
-
{ name: '_matterc._udp.local', type: 12
|
|
93
|
-
{ name: '_matter._tcp.local', type: 12
|
|
94
|
-
{ name: '_matterbridge._tcp.local', type: 12
|
|
95
|
-
{ name: '_home-assistant._tcp.local', type: 12
|
|
96
|
-
{ name: '_shelly._tcp.local', type: 12
|
|
97
|
-
{ name: '_mqtt._tcp.local', type: 12
|
|
98
|
-
{ name: '_http._tcp.local', type: 12
|
|
99
|
-
{ name: '_services._dns-sd._udp.local', type: 12
|
|
124
|
+
{ name: '_matterc._udp.local', type: 12 /* DnsRecordType.PTR */, class: 1 /* DnsClass.IN */, unicastResponse: true },
|
|
125
|
+
{ name: '_matter._tcp.local', type: 12 /* DnsRecordType.PTR */, class: 1 /* DnsClass.IN */, unicastResponse: true },
|
|
126
|
+
{ name: '_matterbridge._tcp.local', type: 12 /* DnsRecordType.PTR */, class: 1 /* DnsClass.IN */, unicastResponse: true },
|
|
127
|
+
{ name: '_home-assistant._tcp.local', type: 12 /* DnsRecordType.PTR */, class: 1 /* DnsClass.IN */, unicastResponse: true },
|
|
128
|
+
{ name: '_shelly._tcp.local', type: 12 /* DnsRecordType.PTR */, class: 1 /* DnsClass.IN */, unicastResponse: true },
|
|
129
|
+
{ name: '_mqtt._tcp.local', type: 12 /* DnsRecordType.PTR */, class: 1 /* DnsClass.IN */, unicastResponse: true },
|
|
130
|
+
{ name: '_http._tcp.local', type: 12 /* DnsRecordType.PTR */, class: 1 /* DnsClass.IN */, unicastResponse: true },
|
|
131
|
+
{ name: '_services._dns-sd._udp.local', type: 12 /* DnsRecordType.PTR */, class: 1 /* DnsClass.IN */, unicastResponse: true },
|
|
100
132
|
]);
|
|
101
133
|
};
|
|
134
|
+
/**
|
|
135
|
+
* Sends an mDNS advertisement for the HTTP service over UDP IPv4.
|
|
136
|
+
*
|
|
137
|
+
* @param {Mdns} mdns - The Mdns instance to use for sending the advertisement.
|
|
138
|
+
* @param {number} [ttl] - The time-to-live for the advertisement records. Defaults to 120 seconds. Send 0 for goodbye.
|
|
139
|
+
*/
|
|
102
140
|
const advertise = (mdns, ttl = 120) => {
|
|
103
141
|
mdns.log.info(`Sending mDNS advertisement for matterbridge service with TTL ${ttl ? ttl.toString() : 'goodbye'}...`);
|
|
104
142
|
const httpServiceType = '_http._tcp.local';
|
|
@@ -114,17 +152,25 @@ Examples:
|
|
|
114
152
|
const srvRdata = mdns.encodeSrvRdata(0, 0, port, hostName);
|
|
115
153
|
const txtRdata = mdns.encodeTxtRdata([`version=${pkg.version}`, 'path=/']);
|
|
116
154
|
const answers = [
|
|
117
|
-
|
|
118
|
-
{ name:
|
|
119
|
-
{ name:
|
|
120
|
-
{ name:
|
|
121
|
-
{ name:
|
|
122
|
-
|
|
123
|
-
{ name: httpInstanceName, rtype:
|
|
124
|
-
|
|
155
|
+
// PTR records for service types and instances
|
|
156
|
+
{ name: '_services._dns-sd._udp.local', rtype: 12 /* DnsRecordType.PTR */, rclass: 1 /* DnsClass.IN */, ttl, rdata: ptrHttpServiceTypeRdata },
|
|
157
|
+
{ name: httpServiceType, rtype: 12 /* DnsRecordType.PTR */, rclass: 1 /* DnsClass.IN */, ttl, rdata: ptrHttpInstanceRdata },
|
|
158
|
+
{ name: '_services._dns-sd._udp.local', rtype: 12 /* DnsRecordType.PTR */, rclass: 1 /* DnsClass.IN */, ttl, rdata: ptrMatterbridgeServiceTypeRdata },
|
|
159
|
+
{ name: matterbridgeServiceType, rtype: 12 /* DnsRecordType.PTR */, rclass: 1 /* DnsClass.IN */, ttl, rdata: ptrMatterbridgeInstanceRdata },
|
|
160
|
+
// SRV record for the HTTP instance
|
|
161
|
+
{ name: httpInstanceName, rtype: 33 /* DnsRecordType.SRV */, rclass: 1 /* DnsClass.IN */ | 32768 /* DnsClassFlag.FLUSH */, ttl, rdata: srvRdata },
|
|
162
|
+
// SRV record for the matterbridge instance
|
|
163
|
+
{ name: matterbridgeInstanceName, rtype: 33 /* DnsRecordType.SRV */, rclass: 1 /* DnsClass.IN */ | 32768 /* DnsClassFlag.FLUSH */, ttl, rdata: srvRdata },
|
|
164
|
+
// TXT record for the HTTP instance
|
|
165
|
+
{ name: httpInstanceName, rtype: 16 /* DnsRecordType.TXT */, rclass: 1 /* DnsClass.IN */ | 32768 /* DnsClassFlag.FLUSH */, ttl, rdata: txtRdata },
|
|
166
|
+
// TXT record for the matterbridge instance
|
|
167
|
+
{ name: matterbridgeInstanceName, rtype: 16 /* DnsRecordType.TXT */, rclass: 1 /* DnsClass.IN */ | 32768 /* DnsClassFlag.FLUSH */, ttl, rdata: txtRdata },
|
|
125
168
|
];
|
|
169
|
+
// Always attempt to add both A and all AAAA records (best effort), regardless of the socket family.
|
|
126
170
|
const interfaces = os.networkInterfaces();
|
|
171
|
+
// Use specified interface name if provided
|
|
127
172
|
let interfaceInfos = mdns.interfaceName ? interfaces[mdns.interfaceName] : undefined;
|
|
173
|
+
// Find the first non-internal IPv4 and IPv6 addresses if interface name is not provided or not found
|
|
128
174
|
if (!interfaceInfos) {
|
|
129
175
|
interfaceInfos = [];
|
|
130
176
|
for (const name of Object.keys(interfaces)) {
|
|
@@ -135,15 +181,16 @@ Examples:
|
|
|
135
181
|
}
|
|
136
182
|
}
|
|
137
183
|
}
|
|
184
|
+
// Encode A and AAAA records for all non-internal addresses of the selected interface
|
|
138
185
|
try {
|
|
139
186
|
for (const info of interfaceInfos) {
|
|
140
187
|
if (info.family === 'IPv4' && !info.internal) {
|
|
141
188
|
const ipv4 = info.address;
|
|
142
|
-
answers.push({ name: hostName, rtype: 1
|
|
189
|
+
answers.push({ name: hostName, rtype: 1 /* DnsRecordType.A */, rclass: 1 /* DnsClass.IN */ | 32768 /* DnsClassFlag.FLUSH */, ttl, rdata: mdns.encodeA(ipv4) });
|
|
143
190
|
}
|
|
144
191
|
else if (info.family === 'IPv6' && !info.internal) {
|
|
145
192
|
const ipv6 = info.address;
|
|
146
|
-
answers.push({ name: hostName, rtype: 28
|
|
193
|
+
answers.push({ name: hostName, rtype: 28 /* DnsRecordType.AAAA */, rclass: 1 /* DnsClass.IN */ | 32768 /* DnsClassFlag.FLUSH */, ttl, rdata: mdns.encodeAAAA(ipv6) });
|
|
147
194
|
}
|
|
148
195
|
}
|
|
149
196
|
}
|
|
@@ -156,9 +203,11 @@ Examples:
|
|
|
156
203
|
mdnsIpv4 = new Mdns('mDNS Server udp4', MDNS_MULTICAST_IPV4_ADDRESS, MDNS_MULTICAST_PORT, 'udp4', true, getParameter('interfaceName'), getParameter('ipv4InterfaceAddress') || '0.0.0.0', getParameter('outgoingIpv4InterfaceAddress'));
|
|
157
204
|
if (hasParameter('v') || hasParameter('verbose'))
|
|
158
205
|
mdnsIpv4.listNetworkInterfaces();
|
|
206
|
+
// Apply filters if any
|
|
159
207
|
const filters = getStringArrayParameter('filter');
|
|
160
208
|
if (filters)
|
|
161
209
|
mdnsIpv4.filters.push(...filters);
|
|
210
|
+
// Start the IPv4 mDNS server
|
|
162
211
|
mdnsIpv4.start();
|
|
163
212
|
mdnsIpv4.on('ready', (address) => {
|
|
164
213
|
mdnsIpv4?.socket.setMulticastLoopback(false);
|
|
@@ -177,9 +226,11 @@ Examples:
|
|
|
177
226
|
mdnsIpv6 = new Mdns('mDNS Server udp6', MDNS_MULTICAST_IPV6_ADDRESS, MDNS_MULTICAST_PORT, 'udp6', true, getParameter('interfaceName'), getParameter('ipv6InterfaceAddress') || '::', getParameter('outgoingIpv6InterfaceAddress'));
|
|
178
227
|
if (hasParameter('v') || hasParameter('verbose'))
|
|
179
228
|
mdnsIpv6.listNetworkInterfaces();
|
|
229
|
+
// Apply filters if any
|
|
180
230
|
const filters = getStringArrayParameter('filter');
|
|
181
231
|
if (filters)
|
|
182
232
|
mdnsIpv6.filters.push(...filters);
|
|
233
|
+
// Start the IPv6 mDNS server
|
|
183
234
|
mdnsIpv6.start();
|
|
184
235
|
mdnsIpv6.on('ready', (address) => {
|
|
185
236
|
mdnsIpv6?.socket.setMulticastLoopback(false);
|
|
@@ -202,15 +253,18 @@ Examples:
|
|
|
202
253
|
reflectorServer = new MdnsReflectorServer();
|
|
203
254
|
await reflectorServer.start();
|
|
204
255
|
}
|
|
256
|
+
// Handle Ctrl+C (SIGINT) and SIGTERM to stop and log devices
|
|
205
257
|
process.on('SIGINT', async () => {
|
|
206
258
|
await cleanupAndLogAndExit();
|
|
207
259
|
});
|
|
208
260
|
process.on('SIGTERM', async () => {
|
|
209
261
|
await cleanupAndLogAndExit();
|
|
210
262
|
});
|
|
263
|
+
// Exit after a timeout to avoid running indefinitely in test environments
|
|
211
264
|
if (!hasParameter('no-timeout') && !hasParameter('reflector-server') && !hasParameter('reflector-client')) {
|
|
212
265
|
setTimeout(async () => {
|
|
213
266
|
await cleanupAndLogAndExit();
|
|
214
|
-
}, 600000).unref();
|
|
267
|
+
}, 600000).unref(); // 10 minutes timeout to exit if no activity
|
|
215
268
|
}
|
|
216
269
|
}
|
|
270
|
+
//# 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;AAIH,OAAO,EAAE,MAAM,SAAS,CAAC;AAEzB,eAAe;AACf,OAAO,EAAE,eAAe,EAAE,YAAY,EAAE,uBAAuB,EAAE,YAAY,EAAE,MAAM,yBAAyB,CAAC;AAE/G,cAAc;AACd,OAAO,EAAE,2BAA2B,EAAE,2BAA2B,EAAE,mBAAmB,EAAE,MAAM,gBAAgB,CAAC;AAC/G,OAAO,EAAyC,IAAI,EAAE,MAAM,WAAW,CAAC;AACxE,OAAO,EAAE,mBAAmB,EAAE,MAAM,0BAA0B,CAAC;AAC/D,OAAO,EAAE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AE;QAC/B,MAAM,oBAAoB,EAAE,CAAC;IAC/B,CAAC,CAAC,CAAC;IAEH,0EAA0E;IAC1E,IAAI,CAAC,YAAY,CAAC,YAAY,CAAC,IAAI,CAAC,YAAY,CAAC,kBAAkB,CAAC,IAAI,CAAC,YAAY,CAAC,kBAAkB,CAAC,EAAE,CAAC;QAC1G,UAAU,CAAC,KAAK,IAAI,EAAE;YACpB,MAAM,oBAAoB,EAAE,CAAC;QAC/B,CAAC,EAAE,MAAM,CAAC,CAAC,KAAK,EAAE,CAAC,CAAC,4CAA4C;IAClE,CAAC;AACH,CAAC"}
|
|
@@ -0,0 +1,371 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @description This file contains the class Mdns.
|
|
3
|
+
* @file mdns.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
|
+
import dgram from 'node:dgram';
|
|
24
|
+
import { AnsiLogger } from 'node-ansi-logger';
|
|
25
|
+
import { Multicast } from './multicast.js';
|
|
26
|
+
export declare const enum DnsRecordType {
|
|
27
|
+
A = 1,
|
|
28
|
+
NS = 2,
|
|
29
|
+
MD = 3,
|
|
30
|
+
MF = 4,
|
|
31
|
+
CNAME = 5,
|
|
32
|
+
SOA = 6,
|
|
33
|
+
MB = 7,
|
|
34
|
+
MG = 8,
|
|
35
|
+
MR = 9,
|
|
36
|
+
NULL = 10,
|
|
37
|
+
WKS = 11,
|
|
38
|
+
PTR = 12,
|
|
39
|
+
HINFO = 13,
|
|
40
|
+
MINFO = 14,
|
|
41
|
+
MX = 15,
|
|
42
|
+
TXT = 16,
|
|
43
|
+
RP = 17,
|
|
44
|
+
AFSDB = 18,
|
|
45
|
+
X25 = 19,
|
|
46
|
+
ISDN = 20,
|
|
47
|
+
RT = 21,
|
|
48
|
+
NSAP = 22,
|
|
49
|
+
NSAP_PTR = 23,
|
|
50
|
+
SIG = 24,
|
|
51
|
+
KEY = 25,
|
|
52
|
+
PX = 26,
|
|
53
|
+
GPOS = 27,
|
|
54
|
+
AAAA = 28,
|
|
55
|
+
LOC = 29,
|
|
56
|
+
NXT = 30,
|
|
57
|
+
EID = 31,
|
|
58
|
+
NIMLOC = 32,
|
|
59
|
+
SRV = 33,
|
|
60
|
+
ATMA = 34,
|
|
61
|
+
NAPTR = 35,
|
|
62
|
+
KX = 36,
|
|
63
|
+
CERT = 37,
|
|
64
|
+
A6 = 38,
|
|
65
|
+
DNAME = 39,
|
|
66
|
+
SINK = 40,
|
|
67
|
+
OPT = 41,
|
|
68
|
+
APL = 42,
|
|
69
|
+
DS = 43,
|
|
70
|
+
SSHFP = 44,
|
|
71
|
+
IPSECKEY = 45,
|
|
72
|
+
RRSIG = 46,
|
|
73
|
+
NSEC = 47,
|
|
74
|
+
DNSKEY = 48,
|
|
75
|
+
DHCID = 49,
|
|
76
|
+
NSEC3 = 50,
|
|
77
|
+
NSEC3PARAM = 51,
|
|
78
|
+
TLSA = 52,
|
|
79
|
+
SMIMEA = 53,
|
|
80
|
+
HIP = 55,
|
|
81
|
+
NINFO = 56,
|
|
82
|
+
RKEY = 57,
|
|
83
|
+
TALINK = 58,
|
|
84
|
+
CDS = 59,
|
|
85
|
+
CDNSKEY = 60,
|
|
86
|
+
OPENPGPKEY = 61,
|
|
87
|
+
CSYNC = 62,
|
|
88
|
+
ZONEMD = 63,
|
|
89
|
+
SVCB = 64,
|
|
90
|
+
HTTPS = 65,
|
|
91
|
+
SPF = 99,
|
|
92
|
+
UINFO = 100,
|
|
93
|
+
UID = 101,
|
|
94
|
+
GID = 102,
|
|
95
|
+
UNSPEC = 103,
|
|
96
|
+
NID = 104,
|
|
97
|
+
L32 = 105,
|
|
98
|
+
L64 = 106,
|
|
99
|
+
LP = 107,
|
|
100
|
+
EUI48 = 108,
|
|
101
|
+
EUI64 = 109,
|
|
102
|
+
TKEY = 249,
|
|
103
|
+
TSIG = 250,
|
|
104
|
+
IXFR = 251,
|
|
105
|
+
AXFR = 252,
|
|
106
|
+
MAILB = 253,
|
|
107
|
+
MAILA = 254,
|
|
108
|
+
ANY = 255,
|
|
109
|
+
URI = 256,
|
|
110
|
+
CAA = 257,
|
|
111
|
+
AVC = 258,
|
|
112
|
+
DOA = 259,
|
|
113
|
+
AMTRELAY = 260,
|
|
114
|
+
ZONEVERSION = 261,
|
|
115
|
+
TA = 32768,
|
|
116
|
+
DLV = 32769
|
|
117
|
+
}
|
|
118
|
+
export declare const enum DnsClass {
|
|
119
|
+
IN = 1,// Internet
|
|
120
|
+
CH = 3,// Chaos
|
|
121
|
+
HS = 4,// Hesiod
|
|
122
|
+
ANY = 255
|
|
123
|
+
}
|
|
124
|
+
export declare const enum DnsClassFlag {
|
|
125
|
+
FLUSH = 32768,// For answers (resource records)
|
|
126
|
+
QU = 32768
|
|
127
|
+
}
|
|
128
|
+
export interface MdnsMessage {
|
|
129
|
+
id: number;
|
|
130
|
+
qr: number;
|
|
131
|
+
opcode: number;
|
|
132
|
+
aa: boolean;
|
|
133
|
+
tc: boolean;
|
|
134
|
+
rd: boolean;
|
|
135
|
+
ra: boolean;
|
|
136
|
+
z: number;
|
|
137
|
+
rcode: number;
|
|
138
|
+
qdCount: number;
|
|
139
|
+
anCount: number;
|
|
140
|
+
nsCount: number;
|
|
141
|
+
arCount: number;
|
|
142
|
+
questions?: DnsQuestion[];
|
|
143
|
+
answers?: MdnsRecord[];
|
|
144
|
+
authorities?: MdnsRecord[];
|
|
145
|
+
additionals?: MdnsRecord[];
|
|
146
|
+
}
|
|
147
|
+
interface DnsQuestion {
|
|
148
|
+
name: string;
|
|
149
|
+
type: number;
|
|
150
|
+
class: number;
|
|
151
|
+
}
|
|
152
|
+
interface MdnsRecord {
|
|
153
|
+
name: string;
|
|
154
|
+
type: number;
|
|
155
|
+
class: number;
|
|
156
|
+
ttl: number;
|
|
157
|
+
data: string;
|
|
158
|
+
}
|
|
159
|
+
/**
|
|
160
|
+
* Checks if a given message is an mDNS message.
|
|
161
|
+
*
|
|
162
|
+
* @param {Buffer} message - The message buffer to check.
|
|
163
|
+
* @returns {boolean} True if the message is an mDNS message, false otherwise.
|
|
164
|
+
*/
|
|
165
|
+
export declare function isMdns(message: Buffer): boolean;
|
|
166
|
+
/**
|
|
167
|
+
* Checks if a given mDNS message is a query.
|
|
168
|
+
*
|
|
169
|
+
* @param {Buffer} message - The mDNS message buffer to check.
|
|
170
|
+
* @returns {boolean} True if the message is a query, false otherwise.
|
|
171
|
+
*/
|
|
172
|
+
export declare function isMdnsQuery(message: Buffer): boolean;
|
|
173
|
+
/**
|
|
174
|
+
* Checks if a given mDNS message is a query.
|
|
175
|
+
*
|
|
176
|
+
* @param {Buffer} message - The mDNS message buffer to check.
|
|
177
|
+
* @returns {boolean} True if the message is a query, false otherwise.
|
|
178
|
+
*/
|
|
179
|
+
export declare function isMdnsResponse(message: Buffer): boolean;
|
|
180
|
+
export declare class Mdns extends Multicast {
|
|
181
|
+
deviceQueries: Map<string, {
|
|
182
|
+
rinfo: dgram.RemoteInfo;
|
|
183
|
+
query: MdnsMessage;
|
|
184
|
+
}>;
|
|
185
|
+
deviceResponses: Map<string, {
|
|
186
|
+
rinfo: dgram.RemoteInfo;
|
|
187
|
+
response: MdnsMessage;
|
|
188
|
+
dataPTR?: string;
|
|
189
|
+
}>;
|
|
190
|
+
filters: string[];
|
|
191
|
+
/**
|
|
192
|
+
* Creates an instance of the Mdns class.
|
|
193
|
+
*
|
|
194
|
+
* @param {string} name - The internal name of the mDNS server for the logs.
|
|
195
|
+
* @param {string} multicastAddress - The multicast address for mDNS (i.e. 224.0.0.251 for udp4 or ff02::fb for udp6).
|
|
196
|
+
* @param {number} multicastPort - The port for mDNS (i.e. 5353).
|
|
197
|
+
* @param {('udp4' | 'udp6')} socketType - The type of socket to create (either 'udp4' or 'udp6').
|
|
198
|
+
* @param {boolean} [reuseAddr] - Whether to reuse the address. Defaults to true.
|
|
199
|
+
* @param {string} [interfaceName] - The optional name of the network interface to use.
|
|
200
|
+
* @param {string} [interfaceAddress] - The optional IP address of the network interface to use.
|
|
201
|
+
* @param {string} [outgoingInterfaceAddress] - The address of the outgoing network interface.
|
|
202
|
+
*/
|
|
203
|
+
constructor(name: string, multicastAddress: string, multicastPort: number, socketType: 'udp4' | 'udp6', reuseAddr?: boolean | undefined, interfaceName?: string, interfaceAddress?: string, outgoingInterfaceAddress?: string);
|
|
204
|
+
onQuery(rinfo: dgram.RemoteInfo, _query: MdnsMessage): void;
|
|
205
|
+
onResponse(rinfo: dgram.RemoteInfo, _response: MdnsMessage): void;
|
|
206
|
+
onMessage(msg: Buffer, rinfo: dgram.RemoteInfo): void;
|
|
207
|
+
/**
|
|
208
|
+
* Decodes an mDNS message, including the header, question section, answer section,
|
|
209
|
+
* authority section, and additional section.
|
|
210
|
+
*
|
|
211
|
+
* @param {Buffer} msg - The raw mDNS message buffer.
|
|
212
|
+
* @returns {MdnsMessage} An object representing the decoded mDNS message.
|
|
213
|
+
* @throws {Error} if the message is too short.
|
|
214
|
+
*/
|
|
215
|
+
decodeMdnsMessage(msg: Buffer): MdnsMessage;
|
|
216
|
+
/**
|
|
217
|
+
* Decodes a DNS name from a buffer, handling compression.
|
|
218
|
+
*
|
|
219
|
+
* @param {Buffer} msg - The full mDNS message buffer.
|
|
220
|
+
* @param {number} offset - The offset at which the DNS name starts.
|
|
221
|
+
* @returns {{ name: string; newOffset: number }} An object with the decoded name and the new offset.
|
|
222
|
+
* @throws {Error} if the offset exceeds the buffer length or too many iterations are performed.
|
|
223
|
+
*/
|
|
224
|
+
decodeDnsName(msg: Buffer, offset: number): {
|
|
225
|
+
name: string;
|
|
226
|
+
newOffset: number;
|
|
227
|
+
};
|
|
228
|
+
/**
|
|
229
|
+
* Encodes a domain name into the DNS label format.
|
|
230
|
+
*
|
|
231
|
+
* For example, "example.local" becomes:
|
|
232
|
+
* [7] "example" [5] "local" [0]
|
|
233
|
+
*
|
|
234
|
+
* @param {string} name - The domain name to encode.
|
|
235
|
+
* @returns {Buffer} The encoded domain name as a Buffer.
|
|
236
|
+
*/
|
|
237
|
+
encodeDnsName(name: string): Buffer;
|
|
238
|
+
/**
|
|
239
|
+
* Encodes TXT record RDATA.
|
|
240
|
+
*
|
|
241
|
+
* In DNS/mDNS, TXT RDATA is a sequence of one or more <character-string>,
|
|
242
|
+
* each encoded as: [length byte][UTF-8 bytes].
|
|
243
|
+
*
|
|
244
|
+
* @param {string[]} txt - Array of TXT entries, e.g. ["key=value", "path=/"].
|
|
245
|
+
* @returns {Buffer} Encoded TXT RDATA.
|
|
246
|
+
* @throws {Error} If any entry exceeds 255 bytes.
|
|
247
|
+
*
|
|
248
|
+
* @example
|
|
249
|
+
* const txtRdata = mdns.encodeTxtRdata(['txtvers=1', 'path=/']);
|
|
250
|
+
* mdns.sendResponse([
|
|
251
|
+
* { name: 'example._http._tcp.local', rtype: DnsRecordType.TXT, rclass: DnsClass.IN | DnsClassFlag.FLUSH, ttl: 120, rdata: txtRdata },
|
|
252
|
+
* ]);
|
|
253
|
+
*/
|
|
254
|
+
encodeTxtRdata(txt: string[]): Buffer;
|
|
255
|
+
/**
|
|
256
|
+
* Encodes SRV record RDATA.
|
|
257
|
+
*
|
|
258
|
+
* SRV RDATA layout (RFC 2782):
|
|
259
|
+
* - priority (2 bytes)
|
|
260
|
+
* - weight (2 bytes)
|
|
261
|
+
* - port (2 bytes)
|
|
262
|
+
* - target (DNS name)
|
|
263
|
+
*
|
|
264
|
+
* @param {number} priority - SRV priority.
|
|
265
|
+
* @param {number} weight - SRV weight.
|
|
266
|
+
* @param {number} port - Service port.
|
|
267
|
+
* @param {string} target - Target hostname (e.g. "matterbridge.local").
|
|
268
|
+
* @returns {Buffer} Encoded SRV RDATA.
|
|
269
|
+
*/
|
|
270
|
+
encodeSrvRdata(priority: number, weight: number, port: number, target: string): Buffer;
|
|
271
|
+
/**
|
|
272
|
+
* Encodes an IPv4 address for an A record RDATA (4 bytes).
|
|
273
|
+
*
|
|
274
|
+
* @param {string} ipv4 - IPv4 address, e.g. "192.168.1.10".
|
|
275
|
+
* @returns {Buffer} 4-byte buffer.
|
|
276
|
+
* @throws {Error} If the address is not a valid dotted-quad.
|
|
277
|
+
*/
|
|
278
|
+
encodeA(ipv4: string): Buffer;
|
|
279
|
+
/**
|
|
280
|
+
* Encodes an IPv6 address for an AAAA record RDATA (16 bytes).
|
|
281
|
+
*
|
|
282
|
+
* Supports the "::" zero-compression form and ignores an optional scope id
|
|
283
|
+
* suffix (e.g. "fe80::1%12" or "fe80::1%eth0").
|
|
284
|
+
*
|
|
285
|
+
* @param {string} ipv6WithOptionalScope - IPv6 address (optionally with scope id).
|
|
286
|
+
* @returns {Buffer} 16-byte buffer.
|
|
287
|
+
* @throws {Error} If the address is not a valid IPv6 literal.
|
|
288
|
+
*/
|
|
289
|
+
encodeAAAA(ipv6WithOptionalScope: string): Buffer;
|
|
290
|
+
/**
|
|
291
|
+
* Decodes a DNS resource record.
|
|
292
|
+
*
|
|
293
|
+
* @param {Buffer} msg - The full mDNS message buffer.
|
|
294
|
+
* @param {number} offset - The offset at which the resource record starts.
|
|
295
|
+
* @returns {{ record: MdnsRecord; newOffset: number }} An object containing the decoded record and the new offset.
|
|
296
|
+
*/
|
|
297
|
+
decodeResourceRecord(msg: Buffer, offset: number): {
|
|
298
|
+
record: MdnsRecord;
|
|
299
|
+
newOffset: number;
|
|
300
|
+
};
|
|
301
|
+
/**
|
|
302
|
+
* Sends a DNS query with multiple questions.
|
|
303
|
+
*
|
|
304
|
+
* @param {Array<{ name: string; type: number; class: number; unicastResponse?: boolean }>} questions - Array of questions
|
|
305
|
+
* to include in the query.
|
|
306
|
+
* @returns {Buffer<ArrayBuffer>} The constructed query buffer.
|
|
307
|
+
*
|
|
308
|
+
* @remarks
|
|
309
|
+
* Each question should have a name (e.g., "_http._tcp.local"), type (e.g., DnsRecordType.PTR), class (e.g., DnsClass.IN),
|
|
310
|
+
* and an optional unicastResponse flag (this will add the DnsClassFlag.QU flag to the query).
|
|
311
|
+
*/
|
|
312
|
+
sendQuery(questions: {
|
|
313
|
+
name: string;
|
|
314
|
+
type: number;
|
|
315
|
+
class: number;
|
|
316
|
+
unicastResponse?: boolean;
|
|
317
|
+
}[]): Buffer<ArrayBuffer>;
|
|
318
|
+
/**
|
|
319
|
+
* Constructs an mDNS response packet and sends it to the multicast address and port.
|
|
320
|
+
*
|
|
321
|
+
* @param {Array<{ name: string; rtype: number; rclass: number; ttl: number; rdata: Buffer }>} answers - Array of answer records.
|
|
322
|
+
* @returns {Buffer<ArrayBuffer>} The constructed response buffer.
|
|
323
|
+
*
|
|
324
|
+
* @example
|
|
325
|
+
* const ptrRdata = mdnsIpv4.encodeDnsName('matterbridge._http._tcp.local');
|
|
326
|
+
* mdnsIpv4.sendResponse([{ name: '_http._tcp.local', rtype: DnsRecordType.PTR, rclass: DnsClass.IN, ttl: 120, rdata: ptrRdata }]);
|
|
327
|
+
*/
|
|
328
|
+
sendResponse(answers: {
|
|
329
|
+
name: string;
|
|
330
|
+
rtype: number;
|
|
331
|
+
rclass: number;
|
|
332
|
+
ttl: number;
|
|
333
|
+
rdata: Buffer;
|
|
334
|
+
}[]): Buffer<ArrayBuffer>;
|
|
335
|
+
/**
|
|
336
|
+
* Converts a DNS record type numeric value to its string representation.
|
|
337
|
+
*
|
|
338
|
+
* @param {number} type - The numeric DNS record type.
|
|
339
|
+
* @returns {string} The string representation of the record type.
|
|
340
|
+
*/
|
|
341
|
+
dnsTypeToString(type: number): string;
|
|
342
|
+
/**
|
|
343
|
+
* Converts a DNS response class numeric value to its string representation.
|
|
344
|
+
*
|
|
345
|
+
* @param {number} cls - The numeric DNS class.
|
|
346
|
+
* @returns {string} The string representation of the DNS class.
|
|
347
|
+
*/
|
|
348
|
+
dnsResponseClassToString(cls: number): string;
|
|
349
|
+
/**
|
|
350
|
+
* Converts a DNS question class to a human-readable string.
|
|
351
|
+
* Adds support for mDNS QU (unicast-response) bit.
|
|
352
|
+
*
|
|
353
|
+
* @param {number} cls - The numeric question class.
|
|
354
|
+
* @returns {string} The string representation, e.g. "IN|QU"
|
|
355
|
+
*/
|
|
356
|
+
dnsQuestionClassToString(cls: number): string;
|
|
357
|
+
/**
|
|
358
|
+
* Logs the decoded mDNS message header.
|
|
359
|
+
*
|
|
360
|
+
* @param {MdnsMessage} msg - The mDNS message header object.
|
|
361
|
+
* @param {AnsiLogger} [log] - The logger to use (defaults to this.log).
|
|
362
|
+
* @param {string} [text] - Optional additional text to include in the log.
|
|
363
|
+
*/
|
|
364
|
+
logMdnsMessage(msg: MdnsMessage, log?: AnsiLogger, text?: string): void;
|
|
365
|
+
/**
|
|
366
|
+
* Logs the discovered devices from the mDNS queries and responses.
|
|
367
|
+
*/
|
|
368
|
+
logDevices(): void;
|
|
369
|
+
}
|
|
370
|
+
export {};
|
|
371
|
+
//# sourceMappingURL=mdns.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"mdns.d.ts","sourceRoot":"","sources":["../../src/dgram/mdns.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;GAqBG;AAGH,OAAO,KAAK,MAAM,YAAY,CAAC;AAG/B,OAAO,EAAE,UAAU,EAA+C,MAAM,kBAAkB,CAAC;AAM3F,OAAO,EAAE,SAAS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