Scripting & JS API

There is an embedded JavaScript in Viinex that can execute user code (“script” object in Viinex), which allows our partners to simplify automatic realization of logic in various usage scenarios.

Scripts can be used for filtration or generation of new events, processing external HTTP requests and management of other Viinex objects. Script execution is usually initiated by events that come from other objects. In addition to it we have provided a capability to activate a script using HTTP API provided by Viinex server. Thus, every script can also be a servlet if needed. In other words, external software like a code that is executed by a webpage in a client browser, can directly activate a script in Viinex by sending it HTTP requests and receive HTTP responses formed by this script.

Scripts can be particularly useful when there is a need to secure the reliability of executing the logic chosen by a partner by minimizing the risk of event loss in distributed systems (communication failures, restarting one of the components of the system etc) that this logic is based upon. A case in point could be a realization of PTZ camera control and priority through the use of the scripts, PTZ camera return to presets in some time after being used by an operator or switching to a video stream with a higher resolution if an ONVIF event from this camera detector is received.

Besides, a script can also publish some information that can later be sent to clients in response to their HTTP requests without accessing the script itself. This is important for productivity: a host of remote clients can simultaneously request information published by the script and quickly get a response, while the script will continue processing new events.

It goes without saying that the “script” object, since it is a JavaScript execution context, it keeps its state between activations initiated by consecutive events or HTTP requests. This means that through the use of scripts a more complicated logic can be realized (not only one event being processed at the moment). A script can store some information (“fold”) over received events, and adapt its behaviour. Besides, script can generate new events that Viinex sends to other objects – in particular, to HTTP server (this way script-generated events can be received via WebSocket interface in Viinex) or to an instance of “external process” object, that can be a junction point of Viinex and any external system.

By way of example, this is the script mechanism and link with an external process that we used to create a solution for railcar number recognition.