onvif-node-client
v1.6.3
Published
Modular ONVIF client library for Node.js (TypeScript): WS-Discovery scan, discovery, events, and audio backchannel.
Maintainers
Readme
onvif-node-client
Node.js / TypeScript library for ONVIF devices: LAN network scan (WS-Discovery), capability discovery, media profiles, events, and audio backchannel (PC → speaker) with optional Ogg recording.
Typed ESM package. Zero runtime dependencies (ffmpeg on PATH is required only for Ogg recording).
Compatibility note. ONVIF is a standard, but vendors often ship non-literal / quirky implementations (custom RTSP paths, odd SDP, auth quirks, half-working backchannel, etc.). This library aims to grow support for those unconventional cases over time. It does not guarantee that every device or firmware will work out of the box.
If something fails, please open an issue and include everything useful to reproduce and support it: manufacturer / brand, model, firmware version, ONVIF/profile info if known, how you connect (host, ports, HTTP vs RTSP), relevant logs/SDP/SOAP faults, and steps to reproduce.
Every contribution is welcome — bug reports, device notes, tests, and pull requests.
If this library helps you, you can support the project:
Table of contents
- Install
- Requirements
- Concepts
- Connection options
- OnvifNetworkScanService — scan a LAN
- OnvifSupportService — discovery
- OnvifBackchannelAudioService — talk to the speaker
- Audio format
- Recording
- Tunnel / NAT / port-forward
- OnvifClient — low-level API
- ONVIF events
- Complete examples
- API exports
- Build & release
- Troubleshooting
Install
From the npm registry:
npm i onvif-node-clientOr from a GitHub Release asset (built dist/, no token):
npm i https://github.com/midoelhawy/onvif-node-client/releases/download/v1.5.0/onvif-node-client-1.5.0.tgzOr from source (CI/prepare builds dist/ if missing):
npm i github:midoelhawy/onvif-node-client#v1.5.0import {
OnvifNetworkScanService,
OnvifSupportService,
OnvifBackchannelAudioService,
OnvifClient
} from "onvif-node-client";ESM module ("type": "module"). Node.js 18+ recommended.
Requirements
| Component | When needed |
| -------------------------------------------- | ------------------------------------- |
| Reachable ONVIF HTTP (typically port 80/443) | Always |
| Reachable RTSP (typically port 554) | Backchannel / talk |
| Device credentials | Almost always (auth) |
| ffmpeg on PATH | Only when using recordTo (Ogg Opus) |
ONVIF SOAP and RTSP use different ports: an HTTP-only tunnel is not enough to talk to the speaker.
Concepts

- Discovery (
OnvifSupportService): what the device exposes (services, profiles, backchannel yes/no). - Talk (
OnvifBackchannelAudioService): opens an RTSP backchannel session and sends PCM audio. - OnvifClient: granular SOAP client (media, events, device IO, …) when you need fine control.
Recommended flow:
discover() → if backchannel.supported → open({ support }) → pushPcm16le() → close()Connection options
Type: OnvifDeviceConnectionOptions (extends OnvifClientOptions).
import type { OnvifDeviceConnectionOptions } from "onvif-node-client";
const conn: OnvifDeviceConnectionOptions = {
host: "192.168.1.50",
port: 80,
path: "/onvif",
secure: false,
auth: {
mode: "auto",
username: "admin",
password: "secret"
},
timeoutMs: 15_000,
// RTSP (backchannel)
rtspHost: "192.168.1.50",
rtspPort: 554,
// or a full URL:
// rtspUrl: "rtsp://192.168.1.50:554/stream?mode=real&idc=1&ids=1",
// profileToken: "Profile0s0",
// Tunnel: Host header expected by the device
// httpHostHeader: "192.168.1.50",
allowInsecureTls: true
};Main fields
| Field | Default | Description |
| ----------------------- | ----------------- | --------------------------------------------------------- |
| host | — | Host/IP as seen by Node (also 127.0.0.1 when tunneling) |
| port | 80 / 443 | ONVIF HTTP(S) port |
| path | /onvif | Service base path (…/device_service) |
| secure | false | HTTPS |
| auth.mode | — | none | auto | wsse | http-basic | http-digest |
| auth.mode: "auto" | — | Tries multiple auth methods (recommended) |
| httpHostHeader | — | Override Host header (tunnels / picky firmware) |
| allowInsecureTls | false | Accept self-signed certificates |
| timeoutMs | transport default | Request timeout |
| rtspUrl | — | Skip GetStreamUri, use this RTSP URL |
| rtspHost / rtspPort | — | Rewrite host/port from GetStreamUri |
| profileToken | first stream | Preferred Media profile |
OnvifNetworkScanService
Scan a LAN subnet (or IP range) for ONVIF devices using WS-Discovery (UDP 3702), with optional HTTP fallback.
import { OnvifNetworkScanService } from "onvif-node-client";
const scanner = new OnvifNetworkScanService();
const result = await scanner.scan(
{
network: "192.168.1.0/24", // also: "192.168.1.1-192.168.1.50" or a single IP
timeoutMs: 2000,
concurrency: 64,
includeMulticast: true, // default true — also probes 239.255.255.250:3702
httpFallback: false, // optional: HTTP GetSystemDateAndTime on :80/:8080/…
enrichDeviceInfo: true, // default true — parse scopes + optional GetDeviceInformation
// auth: { username: "admin", password: "secret" }, // helps enrich when the device requires auth
// signal: AbortSignal.timeout(30_000)
},
(p) => {
console.log(p.phase, `${p.checked}/${p.total}`, "found=", p.found, p.current ?? "");
}
);
for (const d of result.devices) {
console.log(d.address, d.manufacturer, d.model, d.mac, d.xAddrs);
}How it works
- Multicast WS-Discovery Probe →
239.255.255.250:3702(devices on the same L2/L3 that route multicast). - Unicast WS-Discovery Probe to every host in the CIDR/range on UDP
3702. - Optional HTTP fallback: TCP + SOAP
GetSystemDateAndTimeon common ports for devices that ignore discovery. - Identity enrichment (default): parse ONVIF scopes (
name,hardware,MAC, …) and, when possible, callGetDeviceInformationfor manufacturer / model / firmware / serial.
scan() options
| Option | Default | Description |
| ------------------ | ------------------ | ----------------------------------------------------------------------------- |
| network | — | CIDR (192.168.1.0/24), range (a-b), or single IP (prefix must be >= 16) |
| timeoutMs | 2500 | Per-host wait / HTTP timeout budget |
| concurrency | 64 | Parallel unicast probes |
| discoveryPort | 3702 | WS-Discovery UDP port |
| includeMulticast | true | Send multicast Probe first |
| multicastAddress | 239.255.255.250 | Multicast group |
| probeTypes | NVT + Device | WS-Discovery Types filter |
| httpFallback | false | Also probe HTTP ONVIF endpoints |
| httpPorts | 80,8080,8000,443 | Ports for HTTP fallback |
| enrichDeviceInfo | true | Parse scopes + GetDeviceInformation when possible |
| auth | — | Optional credentials for enrich (username / password) |
| signal | — | Abort mid-scan |
Result
{
network: string;
scannedHosts: number;
durationMs: number;
devices: Array<{
address: string;
port: number;
xAddrs: string[];
types: string[];
scopes: string[];
manufacturer?: string;
model?: string;
name?: string;
hardware?: string;
mac?: string;
location?: string;
profiles?: string[];
firmwareVersion?: string;
serialNumber?: string;
hardwareId?: string;
metadataVersion?: string;
}>;
}After a scan, feed a found XAddr host into OnvifSupportService / talk:
const hit = result.devices[0];
if (hit) {
const report = await new OnvifSupportService({
host: hit.address,
port: hit.port,
auth: { mode: "auto", username: "admin", password: "secret" },
rtspHost: hit.address,
rtspPort: 554
}).discover();
}OnvifSupportService
Discovers identity, services, media profiles, Device IO audio outputs, and RTSP backchannel support.
import { OnvifSupportService } from "onvif-node-client";
const support = new OnvifSupportService(conn);
const report = await support.discover();
if (!report.reachable) {
console.error(report.error, report.hints);
process.exit(1);
}
console.log(report.device);
// { manufacturer, model, firmwareVersion, serialNumber, hardwareId }
console.log(report.backchannel.supported); // true/false
console.log(report.backchannel.g711); // "PCMU" | "PCMA" | undefined
console.log(report.profiles);
console.log(report.streams);
console.log(report.audioOutputs);
console.log(report.hints);OnvifDeviceSupportReport
| Field | Type | Meaning |
| ----------------------- | -------------- | ------------------------------------ |
| reachable | boolean | init() / GetCapabilities succeeded |
| error | string? | Error when unreachable |
| device | device info | From GetDeviceInformation |
| resolvedServices | XAddr map | Device / Media / Events / Analytics |
| capabilityEndpoints | list | All XAddrs from GetCapabilities |
| serviceDirectory | list? | From GetServices (if supported) |
| profiles | Media profiles | Video/audio encoder when present |
| streams | GetStreamUri | RTSP URIs (credentials masked) |
| audioOutputs | token[] | Device IO GetAudioOutputs |
| backchannel.supported | boolean | SDP has m=audio + a=sendonly |
| backchannel.rtspUrl | string? | Prepared RTSP URL (for talk reuse) |
| backchannel.g711 | PCMU/PCMA? | Codec from SDP |
| backchannel.notes | string[] | Probe details |
| hints | string[] | Operational hints |
| probedAt | ISO string | Timestamp |
The report is reusable: pass it to OnvifBackchannelAudioService.open({ support }) without probing again.
OnvifBackchannelAudioService
Opens an ONVIF RTSP backchannel session (TCP interleaved), accepts PCM, and sends it to the speaker.
import { OnvifBackchannelAudioService } from "onvif-node-client";
const audio = new OnvifBackchannelAudioService(conn);
const session = await audio.open({
support: report, // optional: reuse discover()
verifySupport: false, // default: true if `support` is missing
recordTo: "/tmp/talks", // dir → timestamp.ogg or a full .ogg path
skipRecvOnlySetup: true, // default true (sendonly track only)
connectTimeoutMs: 15_000
});
console.log(session.g711, session.sampleRate, session.recordingPath);
// Mono PCM signed 16-bit LE @ 8 kHz
session.pushPcm16le(pcmChunk);
const { recordingPath } = await session.close();open() options
| Option | Default | Description |
| ------------------- | ----------------- | ------------------------------------ |
| support | — | Report from discover() |
| verifySupport | !support | If true, runs discover again |
| recordTo | — | .ogg file path or directory |
| skipRecvOnlySetup | true | Skip SETUP for recv-only video/audio |
| connectTimeoutMs | timeoutMs / 15s | RTSP TCP connect timeout |
Session
| Member | Description |
| ------------------ | ------------------------------------ |
| g711 | PCMU or PCMA negotiated from SDP |
| sampleRate | Always 8000 |
| payloadType | RTP payload type |
| rtspUrl | URL in use (password masked) |
| recordingPath | Ogg path when recordTo is set |
| support | Report used for this session |
| pushPcm16le(buf) | Send (and record) PCM |
| close() | TEARDOWN + flush recording |
If the device has no backchannel, open() throws:
ONVIF audio backchannel not supported: …Audio format
The library expects:
PCM signed 16-bit little-endian
mono
8000 HzThe RTP codec toward the device (μ-law / A-law) is chosen automatically from SDP (PCMU / PCMA).
Generate test PCM with ffmpeg
ffmpeg -f lavfi -i "sine=frequency=880:sample_rate=8000" -t 3 \
-ac 1 -ar 8000 -f s16le pipe:1From WebM/Opus (browser MediaRecorder)
In your app (same pattern as the local web-talk sample):
WebM chunks → ffmpeg → s16le 8 kHz → session.pushPcm16le()ffmpeg -f webm -i pipe:0 -ac 1 -ar 8000 -f s16le pipe:1Recording
Requires ffmpeg with the libopus encoder.
// Exact file
await audio.open({ recordTo: "/tmp/call-2026.ogg" });
// Directory → /tmp/talks/YYYY-MM-DD_HH-mm-ss.ogg
await audio.open({ recordTo: "/tmp/talks" });The recording is the same PCM sent to the speaker (before G.711 RTP encoding).
Exported helpers:
import {
resolveOggRecordingPath,
startOggPcm16Recorder,
formatRecordingTimestamp
} from "onvif-node-client";Tunnel / NAT / port-forward
Typical setup: ONVIF HTTP on 127.0.0.1:2020 → device 192.168.1.50:80, RTSP on 127.0.0.1:554 → device :554.
const conn = {
host: "127.0.0.1",
port: 2020,
auth: { mode: "auto" as const, username: "admin", password: "secret" },
// many firmwares want Host = real LAN IP
httpHostHeader: "192.168.1.50",
rtspHost: "127.0.0.1",
rtspPort: 554
};GetStreamUri often returns rtsp://192.168.1.50:554/.... With rtspHost / rtspPort the library rewrites host/port for the tunnel.
Helpers:
import { prepareRtspUrl, maskRtspCredentials } from "onvif-node-client";
const url = prepareRtspUrl(rawFromDevice, conn);
console.log(maskRtspCredentials(url));OnvifClient
Low-level SOAP client (lazy init()).
import { OnvifClient } from "onvif-node-client";
const client = new OnvifClient(conn);
await client.init();
const info = await client.getDeviceInformation();
const clock = await client.getSystemDateAndTime();
console.log(clock.utc?.toISOString(), clock.dateTimeType, clock.timeZone);
// Fix broken camera time from host clock (preserves TZ/DST)
const after = await client.syncSystemDateAndTime();
console.log("synced →", after.utc?.toISOString());
const profiles = await client.getProfilesDetailed();
const streams = await client.getStreams();
const caps = await client.getAdvertisedCapabilityEndpoints();
const services = await client.getServiceDirectory();
const outputs = await client.getAudioOutputSummaries();
const bc = await client.probeRtspAudioBackchannel({
// rtspUrl: "...",
// profileToken: "Profile0s0",
timeoutMs: 10_000
});
console.log(bc?.sdpSuggestsAudioBackchannel, bc?.sdpPreview);Fix camera clock
// Fix clock + OSD (default: align TZ/DST to host, verify local skew)
const synced = await client.syncSystemDateAndTime();
console.log(synced.sync.ok, synced.sync.localSkewMs, synced.timeZone);
// Only push UTC, keep camera TZ (can leave OSD 1h off in summer)
await client.syncSystemDateAndTime({ alignTimeZoneToHost: false });
// Explicit style (POSIX signs are inverted: UTC+2 → "GMT-2")
await client.syncSystemDateAndTime({
timeZoneStyle: "posix" // or "vendor" → "GMT+02:00"
});
// Explicit instant + TZ
await client.syncSystemDateAndTime({
date: new Date(),
timeZone: "GMT-2",
daylightSavings: false
});
// Low-level SetSystemDateAndTime (Manual)
await client.setSystemDateAndTime({
dateTimeType: "Manual",
daylightSavings: false,
timeZone: "UTC0",
utcDateTime: new Date()
});
// Switch device to NTP mode (device must already have NTP servers configured)
await client.setSystemDateAndTime({
dateTimeType: "NTP",
daylightSavings: false
});Reboot camera
const { message } = await client.systemReboot();
console.log(message ?? "reboot requested");Main methods
| Method | Description |
| ----------------------------------------- | ----------------------------------- |
| init() | Resolve XAddrs from GetCapabilities |
| getDeviceInformation() | Device identity |
| getSystemDateAndTime() | Read camera clock / mode |
| setSystemDateAndTime() | Set Manual UTC or NTP mode |
| syncSystemDateAndTime() | Push host UTC (fix broken clocks); use alignTimeZoneToHost for OSD hour |
| systemReboot() | Soft-reboot the device |
| getProfiles() / getProfilesDetailed() | Media profiles |
| getStreams() | All GetStreamUri results |
| getAdvertisedCapabilityEndpoints() | XAddr table |
| getServiceDirectory() | GetServices |
| getAudioOutputSummaries() | Device IO audio outputs |
| probeRtspAudioBackchannel() | DESCRIBE-only backchannel probe |
| createPullPointSubscription() | Events PullPoint |
| pullMessages() | Pull events |
| listenToEvents() | Async iterator for events |
| normalizeServiceUrl() | Rewrite XAddr to local host/port |
| getResolvedServices() | Resolved service map |
ONVIF events
import { OnvifClient, eventMessageToJson } from "onvif-node-client";
const client = new OnvifClient(conn);
const controller = new AbortController();
setTimeout(() => controller.abort(), 30_000);
for await (const msg of client.listenToEvents({
signal: controller.signal,
pullTimeout: "PT5S",
messageLimit: 10
})) {
console.log(eventMessageToJson(msg));
}Or manual PullPoint:
const sub = await client.createPullPointSubscription({
initialTerminationTime: "PT60S"
});
if (!sub) throw new Error("Events not available");
const pulled = await client.pullMessages(sub.referenceAddress, {
timeout: "PT5S",
messageLimit: 10
});Complete examples
0. Scan a network, then discover each device
import {
OnvifNetworkScanService,
OnvifSupportService
} from "onvif-node-client";
const { devices } = await new OnvifNetworkScanService().scan({
network: "192.168.1.0/24",
httpFallback: true
});
for (const d of devices) {
const report = await new OnvifSupportService({
host: d.address,
auth: { mode: "auto", username: "admin", password: "secret" },
rtspPort: 554
}).discover();
console.log(d.address, report.device?.model, report.backchannel.supported);
}1. Discovery only
import { OnvifSupportService } from "onvif-node-client";
const report = await new OnvifSupportService({
host: "192.168.1.50",
port: 80,
auth: { mode: "auto", username: "admin", password: "secret" },
rtspPort: 554
}).discover();
console.log(JSON.stringify({
device: report.device,
backchannel: report.backchannel.supported,
g711: report.backchannel.g711,
profiles: report.profiles.map((p) => ({
token: p.token,
name: p.name,
video: p.video,
audio: p.audio
}))
}, null, 2));2. Discover + talk + record
import { spawn } from "node:child_process";
import {
OnvifSupportService,
OnvifBackchannelAudioService
} from "onvif-node-client";
const conn = {
host: "192.168.1.50",
port: 80,
auth: { mode: "auto" as const, username: "admin", password: "secret" },
rtspPort: 554
};
const report = await new OnvifSupportService(conn).discover();
if (!report.backchannel.supported) {
throw new Error(report.backchannel.notes.join("; "));
}
const session = await new OnvifBackchannelAudioService(conn).open({
support: report,
recordTo: "/tmp/suka"
});
const ff = spawn(
"ffmpeg",
[
"-nostdin", "-loglevel", "error", "-re",
"-f", "lavfi", "-i", "sine=frequency=880:sample_rate=8000",
"-t", "3", "-ac", "1", "-ar", "8000", "-f", "s16le", "pipe:1"
],
{ stdio: ["ignore", "pipe", "pipe"] }
);
await new Promise<void>((resolve, reject) => {
ff.stdout!.on("data", (c: Buffer) => session.pushPcm16le(c));
ff.on("error", reject);
ff.on("exit", (code) => (code ? reject(new Error(`ffmpeg ${code}`)) : resolve()));
});
const { recordingPath } = await session.close();
console.log("saved", recordingPath);3. Talk without an explicit discover
open() verifies support itself when support is omitted:
const session = await new OnvifBackchannelAudioService(conn).open({
recordTo: "/tmp/out.ogg"
});
session.pushPcm16le(chunk);
await session.close();4. WebM pipeline (browser-like app)
import { spawn } from "node:child_process";
import { OnvifBackchannelAudioService } from "onvif-node-client";
const session = await new OnvifBackchannelAudioService(conn).open({
recordTo: "/tmp/suka"
});
const ff = spawn(
"ffmpeg",
[
"-nostdin", "-loglevel", "error",
"-fflags", "+genpts+discardcorrupt",
"-f", "webm", "-i", "pipe:0",
"-ac", "1", "-ar", "8000", "-f", "s16le", "pipe:1"
],
{ stdio: ["pipe", "pipe", "pipe"] }
);
ff.stdout!.on("data", (pcm: Buffer) => session.pushPcm16le(pcm));
// From your app: each MediaRecorder chunk
function onWebmChunk(chunk: Buffer) {
ff.stdin!.write(chunk);
}
async function stop() {
ff.stdin!.end();
await new Promise((r) => ff.on("exit", r));
await session.close();
}5. Low-level live session
When you already have an RTSP URL:
import { openLiveOnvifBackchannelTalk } from "onvif-node-client";
const live = await openLiveOnvifBackchannelTalk({
rtspContentUrl: "rtsp://admin:[email protected]:554/stream?mode=real&idc=1&ids=1",
skipRecvOnlySetup: true
});
live.pushPcm16le(pcm);
await live.close();6. One-shot backchannel probe
import { probeRtspBackchannelDescribe } from "onvif-node-client";
const r = await probeRtspBackchannelDescribe(
"rtsp://admin:[email protected]:554/stream?mode=real&idc=1&ids=1",
{ timeoutMs: 8000 }
);
console.log(r.sdpSuggestsAudioBackchannel, r.rtspStatusLine, r.notes);7. Built-in tone / numbers helper
import { talkOnvifBackchannelPcmu } from "onvif-node-client";
const r = await talkOnvifBackchannelPcmu({
rtspContentUrl: "rtsp://admin:[email protected]:554/stream?mode=real&idc=1&ids=1",
audio: "numbers", // "tone" | "tick" | "numbers" | "mic"
seconds: 10,
skipRecvOnlySetup: true,
onNumber: (n) => console.log("digit", n)
});
console.log(r.ok, r.message);API exports
Full list of public exports: docs/README.md.
Build & release
On tag v*, GitHub Actions builds the package, runs npm pack, and creates a GitHub Release with the .tgz asset. dist/ is not committed. npm publish is a separate local step and is not part of that workflow.
# working tree clean, on main
npm run release:patch # bump → tag vX.Y.Z → push (CI publishes the GitHub Release)Publish the current version to npm (requires npm login, does not bump or push):
npm run publish:npm:dry # pack preview, nothing uploaded
npm run publish:npm # npm publish --access publicInstall:
npm i onvif-node-client
# or from the GitHub Release asset
npm i https://github.com/midoelhawy/onvif-node-client/releases/download/v1.5.0/onvif-node-client-1.5.0.tgzLocal build:
npm ci
npm run buildTroubleshooting
| Symptom | Check |
| ---------------------------------------------------- | ----------------------------------------------------------------------------------------------------------------- |
| Scan finds nothing | Multicast filtered by Wi‑Fi AP? Try httpFallback: true. Ensure UDP 3702 is allowed. Run from the same LAN/VLAN. |
| Scan too slow | Lower timeoutMs, raise concurrency, use a tighter CIDR (/28 instead of /24) |
| reachable: false | host/port, credentials, HTTP vs HTTPS, httpHostHeader when tunneling |
| backchannel.supported: false + ECONNREFUSED :554 | Forward RTSP; set rtspHost / rtspPort |
| SETUP 400 Bad Request | Some firmware (e.g. Qualvision) needs …?query/audioback URLs — handled by this library |
| No sound | SDP codec (PCMA vs PCMU) is automatic; confirm PCM is 8 kHz mono and device volume |
| Recording fails | Is ffmpeg installed? Is libopus available? |
| Empty events | Not all speakers expose Events; NVT cameras often do |
Qualvision / similar firmware notes
Some NVTs require a non-standard control URL:
rtsp://host/stream?mode=real&idc=1&ids=1/audioback(the library performs this join). Vendor web UIs sometimes also document:
rtsp://IP:554/mode=real&idc=1&ids=1Both can work as presentation URLs when the device accepts them on DESCRIBE.
License
GPL-3.0 (GNU General Public License v3.0)
If this library helps you, you can support the project:
