onvif
    Preparing search index...

    Class DiscoverySingleton

    Class for Discovery singleton. Prefer the exported Discovery instance.

    import { Discovery, type Onvif } from 'onvif';

    const USERNAME = 'admin';
    const PASSWORD = 'admin';

    Discovery.on('error', (err, xml) => {
    console.error('WS-Discovery error', err.message, xml?.slice(0, 200));
    });

    Discovery.on('device', async (cam, rinfo) => {
    // Fired as soon as each NVT replies (before probe() settles).
    if (typeof (cam as Onvif).connect !== 'function') return;
    const onvif = cam as Onvif;
    onvif.username = USERNAME;
    onvif.password = PASSWORD;
    try {
    await onvif.connect();
    const info = await onvif.device.getDeviceInformation();
    console.log(`Live: ${rinfo.address} → ${info.manufacturer} ${info.model}`);
    } catch (e) {
    console.warn(`Skip ${onvif.hostname}:`, e);
    }
    });

    (async () => {
    const devices = await Discovery.probe({
    timeout: 8000,
    // Optional: bind to a specific NIC (Linux: eth0 / enp0s3)
    // device: 'eth0',
    // types default to ['tds:Device']; narrow further if needed:
    // types: ['dn:NetworkVideoTransmitter'],
    scopes: ['onvif://www.onvif.org/Profile/T'],
    });

    // probe() always resolves; bad replies only emit 'error'
    const cams = devices.filter((d): d is Onvif => typeof (d as Onvif).connect === 'function');
    console.log(`Probe finished: ${cams.length} Onvif instance(s)`);

    await Promise.all(
    cams.map(async (cam) => {
    cam.username ??= USERNAME;
    cam.password ??= PASSWORD;
    if (cam.timeShift === undefined) await cam.connect();
    const profiles = await cam.media.getProfiles();
    const uri = await cam.media.getStreamUri({ protocol: 'RTSP' });
    console.log(cam.hostname, profiles[0]?.name, uri.uri);
    }),
    );
    })().catch(console.error);

    Hierarchy

    • EventEmitter
      • DiscoverySingleton
    Index
    • Discover NVT devices in the subnetwork. Always resolves with found devices (or []); bad Probe responses and socket failures are emitted on DiscoverySingleton.error and do not reject.

      Parameters

      Returns Promise<(Record<string, unknown> | Onvif)[]>

      import { Discovery } from 'onvif';
      Discovery.on('device', async (cam) => {
      // function would be called as soon as NVT responses
      cam.username = <USERNAME>;
      cam.password = <PASSWORD>;
      await cam.connect();
      })
      Discovery.probe();
      import { Discovery } from 'onvif';
      (async () => {
      const cams = Promise.all((await Discovery.probe()).map(camera => camera.connect());
      console.log(await cams[0]?.getSystemDateAndTime());
      })();
    device: "device" = ...

    Fires when device found

    Onvif instance Onvif or just information object about found device device

    discovery.on('device', console.log);
    
    error: "error" = ...

    Indicates a problem with a Probe response or UDP socket. Always an Error (often OnvifResponseError / parser error). DiscoverySingleton.probe always resolves (possibly with an empty array); bad responses and socket failures are reported only via this event.

    Error instance

    Optional raw SOAP that triggered the error error

    discovery.on('error', console.error);
    
    status: "status" = ...

    Progress text while DiscoverySingleton.probe enumerates NICs and sends Probes. Informational only (not an error). Emitted once per local interface found, then once per Probe send (family, source address, interface name, destination host:port).

    Human-readable status line status

    Discovery.on('status', console.log);
    // Found interface eth0
    // Sending IPv4 from 192.168.1.10 (eth0) to 239.255.255.250:3702