
Scripting & JS API
Viinex includes embedded JavaScript engine that can execute user code (the “script” object in Viinex), which enables our partners to simplify the automatic realization of logic in various usage scenarios.
Scripts can be used for filtering or generating new events, processing external HTTP requests, and managing other Viinex objects. Script execution is usually initiated by events coming from other objects. In addition to this, we have provided the capability to activate a script using the HTTP API. Thus, every script can also be a servlet if needed. In other words, external software, such as code executed by a webpage in a client browser, can directly activate a script in Viinex by sending HTTP requests and receiving HTTP responses formed by the script.
Scripts can be particularly useful when there is a need to ensure the reliability of executing partner-chosen logic by minimizing the risk of event loss in distributed systems, such as communication failures or the restarting of one of the system’s components, that this logic is based on. An example could be the realization of PTZ camera control and priority through the use of scripts, such as PTZ camera returning to presets 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.
Additionally, a script can also publish information that can later be sent to clients in response to their HTTP requests without accessing the script itself. This is important for productivity: multiple remote clients can simultaneously request information published by the script and quickly receive a response while the script continues processing new events.
It is worth noting that since the “script” object 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, more complex logic can be realized beyond the processing of a single event. A script can store some information over received events and adapt its behavior. Besides, a script can generate new events that Viinex sends to other objects, particularly to the HTTP server.