@2bad/onvif
ONVIF client for TypeScript with no runtime dependencies.
Install
npm install @2bad/onvif
Needs Node.js 26 or later. ESM only.
Discovery, events, imaging, device management, media and PTZ are in @2bad/onvif-discovery, @2bad/onvif-events, @2bad/onvif-imaging, @2bad/onvif-management, @2bad/onvif-media and @2bad/onvif-ptz.
Quick start
import { Device } from '@2bad/onvif'
using device = await Device.connect({ hostname: '192.0.2.10', username: 'admin', password: 'secret' })
const info = await device.getDeviceInformation()
console.log(info.manufacturer, info.model, info.firmwareVersion) // DVC DCN-BM2220LPR 2.1.0
using closes idle connections at the end of the block.
Examples
- Connecting: every
Device.connect()option - Calling operations: requests, timeouts and cancellation
- Errors: error classes and what they carry
- Security: authentication, TLS and service addresses
- Service packages: management, media and events methods on the device
- Migrating from
onvif:CamandOnvifcalls and options in 2.x
API
class Device {
static connect(options: ConnectOptions): Promise<Device>
getCapabilities(request?, options?: CallOptions): Promise<GetCapabilitiesResponse>
getDeviceInformation(request?, options?: CallOptions): Promise<GetDeviceInformationResponse>
getHostname(request?, options?: CallOptions): Promise<GetHostnameResponse>
getNetworkInterfaces(request?, options?: CallOptions): Promise<GetNetworkInterfacesResponse>
getScopes(request?, options?: CallOptions): Promise<GetScopesResponse>
getServiceCapabilities(request?, options?: CallOptions): Promise<GetServiceCapabilitiesResponse>
getServices(request, options?: CallOptions): Promise<GetServicesResponse>
getSystemDateAndTime(request?, options?: CallOptions): Promise<GetSystemDateAndTimeResponse>
systemReboot(request?, options?: CallOptions): Promise<SystemRebootResponse>
call(operation: Operation, request?: Request, options?: CallOptions): Promise<Response>
use(extension: (device: Device) => Extension): Device & Extension
download(address: string | URL, options?: { signal; timeoutMs }): Promise<{ contentType; body: Uint8Array }>
synchronizeClock(options?: { signal; timeoutMs }): Promise<void>
resolveAddress(address: string): URL // the URL a reported address is sent to
close(): void // closes idle connections, the device still works after it
readonly address: URL // URL of the device service
get services(): ReadonlyMap<string, URL> // service namespace to URL
get clock(): { skewMs: number; source: 'device' | 'local' } // camera time minus local time
get timeoutMs(): number
get serviceAddresses(): 'rewrite' | 'sameHost' | 'reject'
}
Every error is an OnvifError with host, service and action.
License
MIT