@astronautlabs/mdns

中文文档
1.0.10发布于 2024/01/14MITTypeScriptCommonJS零依赖近 30 天下载 1.4万

Fully featured mDNS and DNS-SD implementation in Typescript

原始使用文档

@/mdns

npm CircleCI

📜 IETF RFC 6762
Multicast DNS

📜 IETF RFC 6763
DNS-Based Service Discovery

📺 Part of the Astronaut Labs Broadcast Suite

✅ Production Quality
This library is ready for use today (v1.x.x) but will be receiving substantial API upgrades and retooling to use more of the @astronautlabs/* frameworks in v2.x, so expect fairly large compatibility changes when those versions are released.

Fully featured mDNS and DNS-SD implementation in Typescript. No native dependencies, works alongside OS-level implementations as long as multiple UDP socket listeners are supported on your platform (supported in modern macOS, Windows, Linux). Extensive tests with continuous integration. Intended for use by Astronaut Labs' NMOS IS-04 implementation, but usable for any general purpose mDNS/DNS-SD use cases.

npm install @astronautlabs/mdns

Usage

Advertise an HTTP server on port 4321:

import { Advertisement } from '@astronautlabs/mdns';

const ad = new Advertisement('_http._tcp', 4321)
  .start();

Find all Google Cast compatible devices:

import { Browser } from '@astronautlabs/mdns';

new Browser('_googlecast._tcp')
  .on('serviceUp', service => console.log("Device up: ", service))
  .on('serviceDown', service => console.log("Device down: ", service))
  .start();

You can also use this library to query multicast DNS as you would unicast DNS using the MulticastDNS class.

import { MulticastDNS } from '@astronautlabs/mdns';
let ipAddress: string = await MulticastDNS.A('myService._http._tcp');

You can also use MulticastDNS.query() to retrieve the records themselves.

import { MulticastDNS, SRVRecord } from '@astronautlabs/mdns';

let { answer, related } = await MulticastDNS.query<SRVRecord>('myService._http._tcp', 'SRV');
// answer: SRVRecord, related: ResourceRecord[]

Validation

Service type names and TXT records have some specific restrictions.

Service names:

  • must start with an underscore _
  • less than 16 chars including the leading _
  • must start with a letter or digit
  • only letters / digits / hyphens (but not consecutively: --)

TXT records:

  • Keys <= 9 chars
  • Keys must be ascii and can't use '='
  • Values must be a string, buffer, number, or boolean
  • Each key/value pair must be < 255 bytes
  • Total TXT object is < 1300 bytes

Credits

This package is based on Gravity Software's dnssd.js package, which itself is based on David Siegel's mdns package.

版本与发布记录

@astronautlabs/mdns 共发布 8 个版本,首次发布于 2024/01/08;过去 12 个月发布了 0 个版本。

版本发布日期距今
1.0.10latest2024/01/142 年前
1.0.72024/01/092 年前
1.0.52024/01/092 年前
1.0.42024/01/092 年前
1.0.32024/01/092 年前
1.0.22024/01/092 年前

关于 @astronautlabs/mdns 的常见问题

@astronautlabs/mdns 是什么?

Fully featured mDNS and DNS-SD implementation in Typescript

如何安装 @astronautlabs/mdns?

在项目目录运行 npm install @astronautlabs/mdns,或使用 pnpm add / yarn add / bun add。

@astronautlabs/mdns 支持 TypeScript 吗?

支持。包内自带 TypeScript 类型声明(package.json 声明了 types 入口),安装后即可获得类型提示,无需再安装 @types 包。

@astronautlabs/mdns 支持 ESM 还是 CommonJS?

以 CommonJS 形式发布,可以直接 require();在 ES Module 项目中也可以用 import 引入(Node.js 会把 module.exports 作为默认导出)。

@astronautlabs/mdns 可以商用吗?

@astronautlabs/mdns 使用 MIT 许可。宽松许可:允许商业使用、修改和再分发,通常只需在分发时保留原版权与许可声明。以上为概括,不构成法律意见,请以许可原文为准。

@astronautlabs/mdns 的下载量有多少?

根据 npm 官方下载统计,@astronautlabs/mdns 在 2026/10/07 – 2026/11/05 这 30 天内被下载 13,660 次,日均约 455 次。下载量会把 CI 构建、镜像同步和作为其他包依赖的安装一并计入,适合横向比较热度,不能直接等同于使用人数。

@astronautlabs/mdns 还在维护吗?

最新版本 1.0.10 发布于 2024/01/14(2 年前);至今共发布 8 个版本,其中过去 12 个月发布了 0 个;首次发布于 2024/01/08。发布频率只是参考信号:功能稳定的工具可能很少需要更新,建议结合源码仓库的 issue 和提交记录判断。