UNPKG

@holusion/product-scanner

Version:

MDNS network scanner for holusion products

24 lines (21 loc) 728 B
import {on} from "events"; import { query, isProduct } from "./services.js"; import { combineHosts, parse } from "./packets.js"; /** * @return {AsyncGenerator<import("./index.js").Host,void, unknown>} */ export async function* add({mdns, signal}){ let events = on(mdns, "response", {signal}) await query({mdns}); for await(let [packet] of events){ for (let host of combineHosts(parse(packet))){ if(!isProduct(host)){ //if(/^iris\d+-\d+/.test(host.host)) console.log("Not a product : ", host.host, JSON.stringify(packet, null, 2)); continue; } yield host; } } /* c8 ignore next */ /* Coverage ignore because events.on() never breaks unless it throws an AbortError */ }