Hikvision ISAPI: the alert stream and the documents a monitoring tool reads, from an NVR or a camera.
Print motion alerts with the channel's name
Print motion alerts with the channel's name
import { alertStream, inputProxyChannels, request, stream } from "@hertzg/hikvision-api"; const nvr = { baseUrl: "http://192.0.2.10", username: "admin", password: "hunter2" }; const names = new Map( (await request(nvr, inputProxyChannels)).map((channel) => [channel.id, channel.name]), ); for await (const alert of await stream(nvr, alertStream, { signal: AbortSignal.timeout(60_000) })) { if (alert.eventType === "VMD" && alert.eventState === "active") { console.log(alert.at, names.get(alert.channel), "motion"); } }
Read a camera's motion grid
Read a camera's motion grid
import { motionDetection, request } from "@hertzg/hikvision-api"; const camera = { baseUrl: "http://192.0.2.21", username: "admin", password: "hunter2" }; const motion = await request(camera, motionDetection({ channel: 1 })); console.log(motion.grid?.map((row) => row.map((cell) => cell ? "#" : ".").join("")).join("\n"));
Every call carries the credentials to the resource's path
Every call carries the credentials to the resource's path
import { assertEquals } from "@std/assert"; import { resolvesNext, spy } from "@std/testing/mock"; import { deviceInfo, request } from "@hertzg/hikvision-api"; const fetch = spy(resolvesNext([ new Response( "<DeviceInfo><model>DS-7608NI-Q2/8P</model>" + "<firmwareVersion>V4.75.207</firmwareVersion><deviceType>NVR</deviceType></DeviceInfo>", ), ])); const nvr = { baseUrl: "http://192.0.2.10", username: "admin", password: "hunter2", fetch }; const info = await request(nvr, deviceInfo); assertEquals(info.deviceType, "NVR"); assertEquals(fetch.calls[0].args[0], "http://192.0.2.10/ISAPI/System/deviceInfo"); const init = fetch.calls[0].args[1] as RequestInit; assertEquals(new Headers(init.headers).get("authorization"), "Basic YWRtaW46aHVudGVyMg==");
A failed ISAPI request: a status outside 2xx, a failing
<ResponseStatus> in the body, or both.
-
httpStatus: number
The HTTP status, when outside 2xx.
-
statusCode: number
The
<statusCode>of the body, when it was a<ResponseStatus>. -
statusString: string
The
<statusString>of the body, such asInvalid Operation. -
subStatusCode: string
The
<subStatusCode>of the body, such asnotSupport. -
url: string
The URL that was requested, or the
<requestURL>the device named.
Decodes a <gridMap> into rows of booleans.
Encodes rows of booleans as a <gridMap>.
The field detection (intrusion) document of one channel.
The line crossing document of one channel.
The motion detection resource of one channel.
The motion detection capabilities resource of one channel.
Parses one <EventNotificationAlert> document.
Reads the standard-time UTC offset out of a POSIX TZ string.
Sends one request to a path and returns the response as is.
The region rule document of one type and channel.
Opens a streamed resource.
One <EventNotificationAlert>, with the time it arrived.
-
activePostCount: number
<activePostCount>: on an NVR, how many channels have an active event right now;0on the heartbeat. Not a count of posts. -
at: string
When the alert arrived, as an ISO 8601 string.
-
channel: number
The channel the alert is about:
<dynChannelID>when present, else<channelID>, else0. On an NVR, IP cameras are 1..n;0is the NVR itself. A camera reports1. -
channelName: string
<channelName>, which cameras send and NVRs do not. -
dateTime: string
<dateTime>as the device wrote it, zone or not.""when missing. -
eventDescription: string
<eventDescription>, such asMotion alarm. -
eventState: string
<eventState>:activeorinactive. VMD only ever postsactive; smart events postinactiveon some firmware when the rule clears. -
eventType: string
<eventType>, such asVMD,videoloss,fielddetectionorlinedetection. -
ipAddress: string
<ipAddress>of the device that posted. -
macAddress: string
<macAddress>of the device that posted. -
pictureTransport: string
<detectionPictureTransType>:urlwhen the snapshot is at Alert.pictureUrl,binarywhen it follows as an image part of the stream. -
pictureUrl: string
<bkgUrl>: where to fetch the snapshot the device took for a smart event, with the same credentials (<URLCertificationType>says which scheme, usuallydigest). Sent whenpictureTransportisurl. -
regions: AlertRegion[]
The regions of a smart event, when the alert carries a
<DetectionRegionList>.
A region reported with a smart event, from <DetectionRegionList>.
-
coordinates: Point[]
The region's corners, from
<RegionCoordinatesList>;[]when the list is empty. -
detectionTarget: string[]
<detectionTarget>split on commas, such as["human"]. -
id: number
<regionID>, when present. Rules count from 0 here, from 1 insmart/rules.ts. -
sensitivityLevel: number
<sensitivityLevel>, when present. -
targetRect: TargetRect
The box around what was detected, from
<TargetRect>, when present and whole: a<TargetRect>with an empty or unreadable number is no box.
Where a device is and how to log in.
-
baseUrl: string
Scheme, host and port, such as
http://192.0.2.10orhttp://192.0.2.10:65001. -
fetch: globalThis.fetch
The
fetchto use. Defaults to the global one. -
password: string
The ISAPI password.
-
username: string
The ISAPI user name.
The fields of <DeviceInfo>.
-
deviceID: string
<deviceID>, a UUID. -
deviceName: string
<deviceName>, as set by the owner. -
deviceType: string
<deviceType>:NVR,IPCameraor another ISAPI device type. -
firmwareReleasedDate: string
<firmwareReleasedDate>, such asbuild 250101. -
firmwareVersion: string
<firmwareVersion>, such asV4.75.207. -
macAddress: string
<macAddress>. -
model: string
<model>, such asDS-7608NI-Q2/8P. -
serialNumber: string
<serialNumber>.
The fields of <Time>.
-
localTime: string
<localTime>: the device clock as ISO 8601 text, such as2026-10-22T11:33:52+04:00. Some firmware leaves the offset out. -
platformType: string
<platformType>, such asEZVIZ, whentimeModeisplatform. -
timeMode: string
<timeMode>: where the clock comes from.NTP,manual,local,satelliteortimecorrect; an NVR enrolled with a cloud platform reportsplatform. -
timeZone: string
<timeZone>: a POSIXTZstring such asCST-4:00:00. -
utcOffsetMinutes: number
The standard-time UTC offset of
timeZonein minutes, ISO-style:CST-4:00:00gives240. Absent whentimeZonedoes not parse.
The fields of <FieldDetection>, whose type is FieldDetection.
One <FieldDetectionRegion>: a polygon that raises fielddetection.
One <InputProxyChannel>: an IP camera as the NVR sees it.
-
id: number
<id>, the channel number from 1. -
ipAddress: string
<ipAddress>of the camera. -
managePortNo: number
<managePortNo>of the camera, usually8000. -
name: string
<name>, as set on the NVR. -
proxyProtocol: string
<proxyProtocol>, such asHIKVISIONorONVIF. -
srcInputPort: number
<srcInputPort>: which of the camera's inputs this channel shows.
One <InputProxyChannelStatus>: the NVR's view of one IP camera.
-
chanDetectResult: string
<chanDetectResult>: why the camera is in the state it is in. -
connMode: string
<connMode>:plugplayfor a PoE camera,manualfor one added by address. -
id: number
<id>, the channel number from 1. -
ipAddress: string
<ipAddress>of the camera. -
managePortNo: number
<managePortNo>of the camera, usually8000. -
online: boolean
<online>: whether the NVR is receiving the camera's stream. -
passwordStatus: string
<SecurityStatus><PasswordStatus>:strong,medium,weakorrisk. -
proxyProtocol: string
<proxyProtocol>, such asHIKVISIONorONVIF. -
srcInputPort: number
<srcInputPort>: which of the camera's inputs this channel shows. -
streamingProxyChannelIds: number[]
<streamingProxyChannelIdList>: the streaming channel numbers that play this camera, such as101(main stream) and102(sub stream). -
url: string
<url>: the camera's web address. For a plug-and-play camera this is the NVR's virtual host, such ashttp://192.0.2.10:65001for PoE port 1.
What an IsapiError knows about the failure.
-
httpStatus: number
The HTTP status, when the failure came with one outside 2xx.
-
status: ResponseStatus
The
<ResponseStatus>in the body, when there was one. -
url: string
The URL that was requested, or the
<requestURL>the device named.
The fields of <LineDetection>.
-
channel: number
<id>: the video channel the lines apply to. -
enabled: boolean
<enabled>: whether line crossing detection runs at all. -
lines: LineDetectionLine[]
The lines, in document order.
-
normalizedScreenSize: NormalizedScreenSize
<normalizedScreenSize>, when present.
One <LineItem>: a line whose crossing raises linedetection.
The fields of <MotionDetection>.
-
columns: number
<columnGranularity>: columns in the grid, when<Grid>is present. -
enableHighlight: boolean
<enableHighlight>: draw motion on the live picture, when present. -
enabled: boolean
<enabled>;falsewhen the element is missing. -
endTriggerTimeMs: number
<endTriggerTime>: milliseconds of stillness before the alarm ends, when present. -
grid: boolean[][]
<gridMap>decoded,grid[row][column]beingtruewhere motion counts. -
regionType: "grid" | "roi" | "none" | "region" | (string & Record<never, never>)
<regionType>:grid,roi,none,region, or whatever else the device sent. -
regions: MotionRegion[]
The
<RegionList>polygons in document order, when there is at least one. -
rows: number
<rowGranularity>: rows in the grid, when<Grid>is present. -
samplingIntervalFrames: number
<samplingInterval>: frames between two compared pictures, when present. -
sensitivityLevel: number
<sensitivityLevel>, 0 to 100. -
startTriggerTimeMs: number
<startTriggerTime>: milliseconds of motion before the alarm starts, when present. -
targetType: string[]
<targetType>split on commas, such as["human", "vehicle"]; newer cameras only.
What …/motionDetection/capabilities allows for a channel.
-
columns: number
<columnGranularity>: columns in the grid, when<Grid>is present. -
regionEdges: { min?: number; max?: number; }
<regionEdgesNum min max>: how many corners a region may have, when present. -
regionTypes: string[]
<regionType opt>: the region types the device accepts;[]without one. -
rows: number
<rowGranularity>: rows in the grid, when<Grid>is present. -
sensitivityLevel: { min?: number; max?: number; step?: number; }
<sensitivityLevel min max step>, when present; each attribute the device states. -
targetTypes: string[]
<targetType opt>: the detection targets the device accepts;[]without one.
Which motion detection document to read.
-
channel: number
The channel number, from 1.
-
proxy: boolean
truereads the NVR's copy under/ISAPI/ContentMgmt/InputProxy,false(the default) the device's own video input.
One <Region> under <RegionList>: a drawn polygon.
-
coordinates: Point[]
The polygon's corners in the normalized 1000 x 1000 screen space.
-
id: number
<id>, from 1.
<normalizedScreenSize>: the space the coordinates are drawn in.
-
height: number
<normalizedScreenHeight>, usually1000. -
width: number
<normalizedScreenWidth>, usually1000.
A point in a device's normalized 1000 x 1000 screen space.
One ISAPI resource: where it is and how to read it.
-
codec: Document<T>
How to read the reply.
-
path: string
The ISAPI path, starting with
/.
The fields of a <ResponseStatus> document.
-
requestURL: string
The path the device is answering about.
-
statusCode: number
0or1OK,2Device Busy,3Device Error,4Invalid Operation,5Invalid XML Format,6Invalid XML Content,7Reboot Required,9Additional Error.7can come on a 200 after a PUT. -
statusString: string
A short description, such as
Invalid Operation. -
subStatusCode: string
The precise reason, such as
notSupport,lowPrivilegeorbadAuthorization.
& { timeThresholdSec?: number; objectOccupationPercent?: number; humanMisinfoFilterEnabled?: boolean; vehicleMisinfoFilterEnabled?: boolean; }
One region of a region rule, such as a <FieldDetectionRegion>.
What a region and a crossing line have in common.
-
alarmConfidence: string
<alarmConfidence>:low,mediumLow,mediumHighorhigh. -
coordinates: Point[]
The shape's points in the normalized screen space.
-
detectionTarget: string[]
<detectionTarget>split on commas, such as["human", "vehicle"], or["all"]on some firmware. -
enabled: boolean
<enabled>. -
id: number
<id>, from 1. -
sensitivityLevel: number
<sensitivityLevel>, 0 to 100.
The fields of a region rule document, such as <FieldDetection>.
-
channel: number
<id>: the video channel the rules apply to. -
enabled: boolean
<enabled>: whether the rule runs at all. -
humanMisinfoFilterEnabled: boolean
<humanMisinfoFilterEnabled>at the root, when present. -
normalizedScreenSize: NormalizedScreenSize
<normalizedScreenSize>, when present. -
regions: SmartRegion[]
The regions, in document order.
-
type: string
The root element's local name, such as
FieldDetectionorRegionEntrance. -
vehicleMisinfoFilterEnabled: boolean
<vehicleMisinfoFilterEnabled>at the root, when present.
A region rule's path segment: every key of SMART_RULE_TYPES but LineDetection.
Options for stream.
-
signal: AbortSignal
Aborting it ends the stream.
Where a smart event saw its target, from <TargetRect>.
-
height: number
<height>. -
width: number
<width>. -
x: number
<X>of the top-left corner. -
y: number
<Y>of the top-left corner.
The alert stream: GET /ISAPI/Event/notification/alertStream, a
multipart/mixed response that never ends, one <EventNotificationAlert>
per part. Each alert is stamped with at, the time its part was decoded,
which is the time it arrived.
The device info resource, /ISAPI/System/deviceInfo.
The device time resource, /ISAPI/System/time.
The channel list resource, /ISAPI/ContentMgmt/InputProxy/channels.
The channel status list resource,
/ISAPI/ContentMgmt/InputProxy/channels/status.
The smart rule types by path segment, each mapped to the <eventType>
its alerts carry on the event stream.