Table of Contents

ZEROCONF

This is the documentation of the ZEROCONF module that implements a Zeroconf discovery api;

Use import { Zeroconf } from "hop:zeroconf";

This imports the Zeroconf constructor.

Example

zeroconf.js

"use hopscript"

import { Zeroconf } from "hop:zeroconf";
import * as hop from "hop";

const zc = Zeroconf();
console.log("zeroconf backend:", zc.backend);

console.log("publishing...");
zc.publish("Hop.js", "_dummy._tcp", hop.port);

console.log("scanning services...");
zc.addEventListener("", e => console.log(e.type,e.hostname)); 

Functions

Zeroconf()

Create a Zeroconf object, which following properties:

zeroconf#addEventListener(type, callback)

Add an discovery listener. The argument type, is either a type name, e.g., http.tcp, or the empty string. The callback argument is a procedure of one argument. It is invoked each time a service is discovered with one object containing the following fields:

zeroconf#publish(name, type, [port, [option1, ...]])

Publish a service.

Types

The TypeScript type declarations are:

export interface DiscoveryEvent {
   interface: number,
   name: string,
   protocol: string,
   domain: string,
   hostname: string,
   port: number,
   address: string,
   options: string[],
   type: string
}
     
type listener = (e: DiscoveryEvent) => void;

export interface Zeroconf {
   backend: string,
   addEventListener: (type: string, proc: listener) => void,
   publish: (name: string, type: string, port?: number, ... opt: string[]) => void
}

export function Zeroconf(): Zeroconf;