Skip to main content

Intrusion Events

Overview

Intrusion events cover all perimeter and zone-based detections: someone entering a defined zone, crossing a tripwire, loitering in an area, or parking illegally. All intrusion events have category === 'intrusion'.

Events arrive through ViewtronServer's 'event' emitter like any other category. The parseEvent() factory returns a ViewtronEvent object with the same interface regardless of whether the source is an IPC camera or NVR.

Event Types

IPC cameras (v1.x firmware) and NVRs (v2.0 firmware) use different smartType values. The SDK normalizes both into the same ViewtronEvent object.

IPC v1.x Event Types

eventTypeeventDescriptionDescription
PEA'Line Crossing / Intrusion'Perimeter intrusion or tripwire crossing
AOIENTRY'Intrusion Zone Entry'Entry into a defined zone
AOILEAVE'Intrusion Zone Exit'Exit from a defined zone
LOITER'Loitering Detection'Loitering beyond a time threshold
PVD'Illegal Parking'Parking violation detection

PEA handles both zone intrusion and tripwire line crossing on IPC cameras. The raw XML contains either a \<perimeter> block (zone) or a \<tripwire> block (line crossing), but the SDK returns the same event type for both.

NVR v2.0 Event Types

eventTypeeventDescriptionDescription
regionIntrusion'Perimeter Intrusion'Zone / perimeter intrusion
lineCrossing'Line Crossing'Tripwire / line crossing

NVR v2.0 separates intrusion and line crossing into distinct event types. IPC uses PEA for both.

Properties

Every intrusion event includes the common ViewtronEvent properties (source, category, cameraName, timestamp, etc.) plus these intrusion-specific fields.

eventType

The raw smartType value from the camera XML.

Type: string

event.eventType  // 'PEA', 'AOIENTRY', 'regionIntrusion', 'lineCrossing', etc.

eventDescription

Human-readable label for the event type.

Type: string

event.eventDescription  // 'Line Crossing / Intrusion', 'Perimeter Intrusion', etc.

Full mapping:

eventTypeeventDescription
PEA'Line Crossing / Intrusion'
AOIENTRY'Intrusion Zone Entry'
AOILEAVE'Intrusion Zone Exit'
LOITER'Loitering Detection'
PVD'Illegal Parking'
regionIntrusion'Perimeter Intrusion'
lineCrossing'Line Crossing'

targetType

What the camera detected. IPC cameras send numeric IDs that the SDK maps to strings. NVR sends strings directly.

Type: string

ValueMeaning
'person'Human detected
'car'Car detected
'motorcycle'Motorcycle or bicycle detected
event.targetType  // 'person', 'car', 'motorcycle'

IPC mapping: 1 = 'person', 2 = 'car', 4 = 'motorcycle'. The SDK handles this conversion automatically.

eventId

Identifier for the detection event.

Type: string

Source: IPC — from \<perimeter> or \<tripwire> XML block. NVR — from \<eventInfo> block.

event.eventId  // e.g., '1'

targetId

Identifier for the tracked target within the event.

Type: string

Source: IPC — from \<perimeter> or \<tripwire> XML block. NVR — from \<eventInfo> block.

event.targetId  // e.g., '3'

status

IPC only. Lifecycle stage of the detection event.

Type: string

ValueMeaning
'SMART_START'Detection begins
'PROCEDURE'Detection ongoing
'SMART_STOP'Detection ends
event.status  // 'SMART_START', 'PROCEDURE', 'SMART_STOP'

NVR events do not include a status field. This property will be an empty string for NVR events.

boundary

NVR only. The type of boundary that was triggered.

Type: string

ValueMeaning
'area'Zone / perimeter boundary
'tripwire'Tripwire / line crossing
event.boundary  // 'area', 'tripwire'

IPC events do not include a boundary field. For IPC, the boundary type is implicit: PEA events with a \<perimeter> block are zone intrusions, and those with a \<tripwire> block are line crossings. This property will be an empty string for IPC events.

IPC vs NVR Comparison

FeatureIPC v1.xNVR v2.0
Event typesPEA, AOIENTRY, AOILEAVE, LOITER, PVDregionIntrusion, lineCrossing
Target typeNumeric ID in XML, SDK maps to stringString directly from \<targetListInfo>
Event/target IDsFrom \<perimeter> or \<tripwire> blockFrom \<eventInfo> block
Status lifecycleSMART_START / PROCEDURE / SMART_STOPNot available
Boundary typeImplicit (XML block structure)Explicit ('area' or 'tripwire')
Channel IDNot availablechannelId property
Device IP / MACNot availablecameraIp, cameraMac properties

Code Examples

Basic Intrusion Handling

const { ViewtronServer } = require('viewtron-sdk');

const server = new ViewtronServer({ port: 5050 });

server.on('event', (event, clientIP) => {
if (event.category === 'intrusion') {
console.log(`[${event.timestamp}] ${event.eventDescription} on ${event.cameraName}`);
console.log(` Target: ${event.targetType || 'unknown'}`);
}
});

server.start();

Filtering by Event Type

server.on('event', (event, clientIP) => {
if (event.category !== 'intrusion') return;

switch (event.eventType) {
case 'PEA':
case 'regionIntrusion':
console.log('Zone intrusion detected');
break;
case 'lineCrossing':
console.log('Line crossing detected');
break;
case 'LOITER':
console.log('Loitering detected');
break;
case 'AOIENTRY':
console.log('Zone entry');
break;
case 'AOILEAVE':
console.log('Zone exit');
break;
case 'PVD':
console.log('Illegal parking');
break;
}
});

Saving Images

const fs = require('fs');

server.on('event', (event, clientIP) => {
if (event.category !== 'intrusion') return;
if (!event.hasImages) return;

const ts = Date.now();

if (event.sourceImageBytes) {
fs.writeFileSync(`intrusion_${ts}.jpg`, event.sourceImageBytes);
}

if (event.targetImageBytes) {
fs.writeFileSync(`intrusion_target_${ts}.jpg`, event.targetImageBytes);
}
});

sourceImageBytes and targetImageBytes are lazy getters that decode the base64 data to a Buffer on first access. If you only need to check whether images exist, use the hasImages getter to avoid decoding.

Combined with Other Event Types

server.on('event', (event, clientIP) => {
switch (event.category) {
case 'lpr':
console.log(`Plate: ${event.plateNumber}`);
break;
case 'intrusion':
console.log(`Intrusion: ${event.eventDescription}`);
break;
case 'face':
console.log('Face detected');
break;
}
});