{"id":20367536,"url":"https://github.com/earthstar-project/dns-sd","last_synced_at":"2025-12-11T21:09:14.897Z","repository":{"id":165919005,"uuid":"627404297","full_name":"earthstar-project/dns-sd","owner":"earthstar-project","description":"DNS-SD (aka Zeroconf, Bonjour, Avahi) in TypeScript for Deno and Node.","archived":false,"fork":false,"pushed_at":"2024-07-14T21:28:32.000Z","size":147,"stargazers_count":55,"open_issues_count":1,"forks_count":3,"subscribers_count":3,"default_branch":"main","last_synced_at":"2025-11-09T23:33:21.950Z","etag":null,"topics":["avahi","bonjour","discovery","dns-sd","multicast-dns","rfc-6762","rfc-6763","zeroconf"],"latest_commit_sha":null,"homepage":"","language":"TypeScript","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"lgpl-3.0","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/earthstar-project.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":".github/FUNDING.yml","license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null,"zenodo":null},"funding":{"github":["sgwilym"],"open_collective":"earthstar"}},"created_at":"2023-04-13T11:57:04.000Z","updated_at":"2025-10-29T06:15:30.000Z","dependencies_parsed_at":"2024-05-28T22:40:22.398Z","dependency_job_id":"a2642f78-db02-483a-9594-32f9f6a169d8","html_url":"https://github.com/earthstar-project/dns-sd","commit_stats":null,"previous_names":["earthstar-project/dns_sd"],"tags_count":3,"template":false,"template_full_name":null,"purl":"pkg:github/earthstar-project/dns-sd","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/earthstar-project%2Fdns-sd","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/earthstar-project%2Fdns-sd/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/earthstar-project%2Fdns-sd/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/earthstar-project%2Fdns-sd/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/earthstar-project","download_url":"https://codeload.github.com/earthstar-project/dns-sd/tar.gz/refs/heads/main","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/earthstar-project%2Fdns-sd/sbom","scorecard":null,"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":286080680,"owners_count":27670235,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","status":"online","status_checked_at":"2025-12-11T02:00:11.302Z","response_time":56,"last_error":null,"robots_txt_status":"success","robots_txt_updated_at":"2025-07-24T06:49:26.215Z","robots_txt_url":"https://github.com/robots.txt","online":true,"can_crawl_api":true,"host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["avahi","bonjour","discovery","dns-sd","multicast-dns","rfc-6762","rfc-6763","zeroconf"],"created_at":"2024-11-15T00:33:06.398Z","updated_at":"2025-12-11T21:09:14.851Z","avatar_url":"https://github.com/earthstar-project.png","language":"TypeScript","funding_links":["https://github.com/sponsors/sgwilym","https://opencollective.com/earthstar"],"categories":[],"sub_categories":[],"readme":"# dns-sd\n\nA module of utilities for DNS-SD (aka Zeroconf, Bonjour, Avahi), featuring:\n\n- Advertise and browse DNS-SD services over multicast DNS (compliant with\n  [RFC 6763](https://www.rfc-editor.org/rfc/rfc6763))\n- A generic mDNS continuous querier (compliant with\n  [RFC 6762](https://www.rfc-editor.org/rfc/rfc6762))\n- A generic mDNS responder (compliant with\n  [RFC 6762](https://www.rfc-editor.org/rfc/rfc6762))\n- Utilities for encoding and decoding DNS messages to and from `Uint8Array`.\n- Works with any JS runtime (e.g. Deno, Node)\n- Implemented completely in TypeScript\n\n## Motivation\n\nThis module was made so that [Earthstar](https://earthstar-project.org) can have\nautomatic peer discovery on a local network. Earthstar is written in TypeScript,\nand can run in browsers, Deno, and Node.\n\nI made this because there weren't any DNS-SD libraries written in TypeScript\n_and_ which had service browsing _and_ service advertising _and_ which could run\non alternative JS runtimes like Deno (theoretically this module can run in the\nbrowser, which is cool — even if it doesn't make any sense).\n\nI also wanted something that used standard `Uint8Array` instead of Node's\n`Buffer` for message encoding and decoding.\n\n## Usage\n\nThis module works for both Deno and Node. The multicast drivers for each can be\nfound at the `@earthstar/dns-sd/deno` and `@earthstar/dns-sd/node` entrypoints,\nrespectively.\n\n\u003e **NB**: Deno's multicasting APIs have not yet stabilised, so the\n\u003e `--unstable-net` flag is required to use this module.\n\n## API\n\n### `browse`\n\nSearches for given DNS-SD services on the local network. Returns an async\niterator of discovered services.\n\n```ts\nconsole.log(\"Browsing for local HTTP services...\");\n\nfor await (\n  const service of browse({\n    multicastInterface: new MulticastInterface(),\n    service: {\n      protocol: \"tcp\",\n      type: \"http\",\n    },\n  })\n) {\n  if (service.isActive) {\n    console.log(`📡 ${service.name} - ${service.host}:${service.port}`);\n  }\n}\n```\n\n### `advertise`\n\nAdvertise a service over multicast DNS.\n\nReturns a promise which will reject if fifteen failed attempts to claim a name\nare made within a ten second interval.\n\nIf the service has to be renamed due to a conflict, a warning with the new name\nwill be sent to the console.\n\n```ts\nawait advertise({\n  service: {\n    host: \"10.0.0.7\",\n    name: \"My Web Server\",\n    port: 8080,\n    protocol: \"tcp\",\n    type: \"http\",\n    txt: {\n      psswd: \"abc123\",\n    },\n  },\n  multicastInterface: new MulticastInterface(),\n});\n```\n\n## Advanced API\n\nThese are lower-level APIs for directly working with DNS records. `browse` and\n`advertise` are implemented using these.\n\n### `respond`\n\nRuns a multicast DNS responder for the given resource records.\n\nReturns a promise that will reject when:\n\n- Probing for proposed records fails\n- Another responder starts responding with records our responder previously lay\n  claim to.\n\n```ts\nawait respond({\n  proposedRecords: [myAAAARecord],\n  multicastInterface: new MulticastInterface(),\n});\n```\n\n### `Query`\n\nA continuous multicast DNS query.\n\nReports additions, flushes, and expirations of resource records answering the\ngiven query via an asynchronous iterator:\n\n```ts\nconst query = new Query(\n  [{ name: \"_http._tcp.local\", recordType: 255 }],\n  multicastInterface: new MulticastInterface()\n);\n\nfor await (const event of query) {\n  console.log(event);\n}\n```\n\nAlso has an `answers` method which returns all records given as answers to this\nquery, as well as an `additional` method which returns all records found in the\nadditional section of DNS messages containing answers to our queries.\n\n### `decodeMessage`\n\nDecode a DNS message from `Uint8Array`.\n\nResource Records of the following types will have their RDATA decoded: `A`,\n`PTR`, `TXT`, `AAAA`, `SRV`, `NSEC`. Other types of resource records will have\ntheir RDATA left as `Uint8Array`.\n\n### `encodeMessage`\n\nEncode a DNS message as Uint8Array.\n\nCompresses domain names, so re-encoded messages may come out smaller.\n\nWill never use the `TC` flag in the header.\n\n### `MulticastInterface`\n\nThis represents a network interface which has joined a multicast group. When\ncombined with a `MulticastDriver` it can be made to work with different runtimes\nsuch as Deno and Node. If no driver is provided when this class is instantiated,\nit automatically selects a driver appropriate to the current runtime.\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fearthstar-project%2Fdns-sd","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fearthstar-project%2Fdns-sd","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fearthstar-project%2Fdns-sd/lists"}