ViewtronServer (Node.js)
Classes
ViewtronServer HTTP server that receives events from Viewtron cameras and NVRs. Handles all camera-specific requirements:
HTTP/1.1 persistent connections (cameras use Connection: keep-alive) keepAliveTimeout of 60s (cameras heartbeat every 30s) XML success response on every request Keepalive, traject, and alarm status filtering Connected camera tracking
Events:
'event' (event, clientIP) — Parsed ViewtronEvent
'connect' (clientIP) — First message from a new camera IP
'raw' (xml, clientIP) — Raw XML before parsing (excludes traject)
'unparsed' (xml, clientIp, reason) — Post did not become an event
'listening' ({ port, ip }) — Server started
'error' (err) — Server error
unparsed reasons: unknown-smartType, no-messageType, parse-error,
alarmStatus. Keepalives, traject, and non-XML bodies do not emit it.
raw is unchanged: alarm status, traject, and keepalives still skip it.
Functions
getLanIP() ⇒ string
Get the LAN IP address of this machine.
ViewtronServer
HTTP server that receives events from Viewtron cameras and NVRs.
Handles all camera-specific requirements:
- HTTP/1.1 persistent connections (cameras use Connection: keep-alive)
- keepAliveTimeout of 60s (cameras heartbeat every 30s)
- XML success response on every request
- Keepalive, traject, and alarm status filtering
- Connected camera tracking
Events: 'event' (event, clientIP) — Parsed ViewtronEvent 'connect' (clientIP) — First message from a new camera IP 'raw' (xml, clientIP) — Raw XML before parsing (excludes traject) 'unparsed' (xml, clientIp, reason) — Post did not become an event 'listening' ({ port, ip }) — Server started 'error' (err) — Server error
unparsed reasons: unknown-smartType, no-messageType, parse-error,
alarmStatus. Keepalives, traject, and non-XML bodies do not emit it.
raw is unchanged: alarm status, traject, and keepalives still skip it.
Kind: global class
- ViewtronServer
- new ViewtronServer(options)
- .start() ⇒
Promise.<{port: number, ip: string}> - .stop() ⇒
Promise.<void>
new ViewtronServer(options)
| Param | Type | Default | Description |
|---|---|---|---|
| options | Object | ||
| [options.port] | number | 5050 | Port to listen on |
| [options.maxBodySize] | number | 5242880 | Max POST body size in bytes |
| [options.onEvent] | function | Shorthand for server.on('event', fn) | |
| [options.onConnect] | function | Shorthand for server.on('connect', fn) | |
| [options.onRaw] | function | Shorthand for server.on('raw', fn) | |
| [options.onUnparsed] | function | Shorthand for server.on('unparsed', fn) |
Example
const server = new ViewtronServer({ port: 5050 });
server.on('event', (event, clientIP) => {
console.log(event.category, event.plateNumber);
});
server.start();
viewtronServer.start() ⇒ Promise.<{port: number, ip: string}>
Start the HTTP server.
Kind: instance method of ViewtronServer
Returns: Promise.<{port: number, ip: string}> - Resolves when listening
viewtronServer.stop() ⇒ Promise.<void>
Stop the server gracefully.
Kind: instance method of ViewtronServer
getLanIP() ⇒ string
Get the LAN IP address of this machine.
Kind: global function