Skip to main content

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

new ViewtronServer(options)​

ParamTypeDefaultDescription
optionsObject
[options.port]number5050Port to listen on
[options.maxBodySize]number5242880Max POST body size in bytes
[options.onEvent]functionShorthand for server.on('event', fn)
[options.onConnect]functionShorthand for server.on('connect', fn)
[options.onRaw]functionShorthand for server.on('raw', fn)
[options.onUnparsed]functionShorthand 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