npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2026 – Pkg Stats / Ryan Hefner

dahua-rpc2

v1.0.4

Published

Node.js/TypeScript client for Dahua devices over the RPC2 protocol: login, keep-alive, parking & traffic control (barrier/strobe, screen, voice), and record management.

Readme

dahua-rpc2

Node.js / TypeScript client for Dahua devices (IP cameras, ANPR / parking and traffic units) over the device RPC2 protocol. It handles the global.login digest-authentication handshake, session keep-alive, common device actions (reboot, screen/voice, parking strobe), and the RecordFinder / RecordUpdater APIs used to query and manage on-device record sets such as traffic allow-lists.

Installation

npm install dahua-rpc2

Quick start

import { DahuaRpc } from "dahua-rpc2";

(async () => {
  const dahua = new DahuaRpc("192.168.1.108", "admin", "YOUR_PASSWORD");

  try {
    await dahua.login();                 // digest handshake, stores a session id
    await dahua.keepAlive();             // keep the session alive

    await dahua.setScreenDisplay("Welcome");
    await dahua.setVoiceBroadcast("Gate opening");
    await dahua.openStrobe("Normal");    // raise the barrier / strobe
    await dahua.closeStrobe();
  } catch (error) {
    console.error("Error:", (error as Error).message);
  }
})();

JavaScript (CommonJS):

const { DahuaRpc } = require("dahua-rpc2");

const dahua = new DahuaRpc("192.168.1.108", "admin", "YOUR_PASSWORD");
dahua.login().then(() => dahua.keepAlive());

Constructor

new DahuaRpc(host: string, username: string, password: string)
  • host — device IP or hostname (requests are sent to http://<host>/RPC2).
  • username / password — device credentials.

The instance also exposes a public idName field you can set to tag/identify an instance in your own collections:

dahua.idName = "gate-01";

DahuaRpc methods

All methods are async and throw an Error (with a descriptive message) when the device returns result: false or the request fails.

| Method | Description | | --- | --- | | login() | Performs the global.login challenge/response handshake and stores the session id. | | keepAlive() | Sends global.keepAlive; resolves to true while the session is valid. | | setConfig(params) | Calls configManager.setConfig with the given config object. | | reboot() | Reboots the device (magicBox.reboot). | | setScreenDisplay(text) | Sets custom text on the device screen (trafficParking.setScreenDisplay). | | setVoiceBroadcast(text) | Sets a custom voice-broadcast message (trafficParking.setVoiceBroadcast). | | testSpaceLight() | Tests the parking space light (trafficParking.testSpaceLight). | | openStrobe(openType, plateNumber?) | Opens the barrier/strobe (trafficSnap.openStrobe). | | closeStrobe() | Closes the barrier/strobe (trafficSnap.closeStrobe). | | RecordUpdater() | Returns the record-updater helper (see below). | | RecordFinder() | Returns the record-finder helper (see below). |

RecordFinder

dahua.RecordFinder() returns a helper for querying on-device record tables (e.g. TrafficRedList). Typical flow: create → startFind → doFind → destroy.

const finder = dahua.RecordFinder();
const object = await finder.create("TrafficRedList"); // object/factory handle
await finder.startFind({}, object);
const result = await finder.doFind(100, object);
console.log(result.params.found, result.params.records);
await finder.destroy(object);

| Method | Signature | | --- | --- | | create | (name) => Promise<string> | | startFind | (condition, object) => Promise<any> | | doFind | (count, object) => Promise<RecordFinderResponse> | | doSeekFind | (offset, count, object) => Promise<any> | | stopFind | (object) => Promise<any> | | getQuerySize | (object) => Promise<any> | | destroy | (object) => Promise<void> |

RecordFinderResponse and the Record shape (plate number/color, card id, park no, times, etc.) are exported from the package types.

RecordUpdater

dahua.RecordUpdater() returns a helper for creating, inserting, updating, removing and importing/exporting records.

const updater = dahua.RecordUpdater();
const instance = await updater.instance("TrafficRedList");
await updater.insert({ PlateNumber: "1234ABC" }, instance);

| Method | Signature | | --- | --- | | instance | (name) => Promise<{ id: number; result: number; session: string }> | | insert | (record, object) => Promise<void> | | update | (recno, record, object) => Promise<void> | | remove | (recno, object) => Promise<void> | | clear | (object) => Promise<void> | | imports | (records, object) => Promise<void> | | importFile / exportFile / exportAsyncFile | (filename, format, code, object) => Promise<void> | | getFileImportState / getFileImportData / getFileExportState | (object) => Promise<void> | | getSchema | (object) => Promise<void> |

Error handling

Every method throws on failure, so wrap calls in try/catch:

try {
  await dahua.login();
} catch (error) {
  console.error("Login failed:", (error as Error).message);
}

License

ISC