Loading files
50b3be768This file is pinned to the selected release. Download the original to open it in your design tool.
Files from this revision, including CAD and LFS contents. Git history is not included.
Or in GitHub Desktop, choose File → Clone repository → URL and paste this address.
Public repositories can be cloned without signing in. For pushing, use your ThingAtlas username and a Git access token as the password.
git lfs install git clone https://thingatlas.com/git/-unclaimed/openharness-1322671404.git
Includes Git history, branches, and Git LFS files. Clones the repository’s default branch, regardless of the version shown here.
import Bonjour from 'bonjour-service'
import { isIP } from 'node:net'
export interface DiscoveredDevice { id: string; name: string; host: string; port: number }
/** Reuse the OS's existing Avahi _autonomous._tcp advertisement. Discovery grants no trust. */
export function discoverDevices(durationMs = 3000): Promise<DiscoveredDevice[]> {
return new Promise((resolve, reject) => {
const found = new Map<string, DiscoveredDevice>()
let done = false
const bonjour = new Bonjour({}, (error: Error) => finish(error))
const browser = bonjour.find({ type: 'autonomous', protocol: 'tcp' }, service => {
const host = service.addresses?.find(a => isIP(a) === 4) ?? service.host
if (service.fqdn && host && service.port > 0 && service.port <= 65535) found.set(service.fqdn, { id: service.fqdn, name: service.name, host, port: service.port })
})
const timer = setTimeout(() => finish(), durationMs)
function finish(error?: Error) {
if (done) return; done = true; clearTimeout(timer); browser.stop(); bonjour.destroy()
if (error) reject(error); else resolve([...found.values()].sort((a, b) => a.name.localeCompare(b.name)))
}
})
}
50b3be768This file is pinned to the selected release. Download the original to open it in your design tool.