Support for scripting

Big news: Viinex 2.0 has received the support for scripting.

The idea was to have a JavaScript engine inside of Viinex 2.0, an engine which could execute a custom code in order to filter or generate new events, and control some of Viinex 2.0 objects just like they can be controlled via their HTTP API.

We took the Duktape engine, which implements ECMAScript 5. We introduced a new Viinex 2.0 object of type “script”, which represents a JS execution context. Each instance of a “script” is an isolated JS context, so multiple scripts in one instance of Viinex 2.0 can run in parallel, executing the same or different JavaScript source code.

The execution of a script is driven mostly by events coming from other Viinex 2.0 objects; however we have also implemented the feature of calling the script directly from HTTP interface exposed by Viinex 2.0. In this way, each script can be a “servlet”, if it wants to. Let me say it again: yes, Viinex 2.0 allows the scripts to receive HTTP calls and generate HTTP responses to that calls. And the script can also “publish” some part of its state, so that this part can be further served via HTTP without recourse to the script, only by Viinex 2.0 HTTP server, — which means a lot, because this can be done in parallel to many HTTP clients, meanwhile the script can be processing new events.

Of course, a “script”, being a JS execution context, preserves its state between sequential activations initiated by received events or HTTP requests. This means that a complex custom logic, which takes into account the history of incoming events (not only one single event which has happened just now) can be implemented with a script. A script can accumulate some knowledge (“fold”) over received events, and adjust its behavior accordingly. A script can also generate new events which are sent to other objects in Viinex 2.0, in particular — to the HTTP server (and thus events generated by scripts can be made available via WebSocket interface provided by Viinex 2.0) or to an instance of “external process” object, which can represent the interface to an arbitrary third-party system.

Regarding the API available for scripts to control other Viinex 2.0 objects, — this JavaScript API is new, and therefore it is not as comprehensive as HTTP API yet. Currently the following Viinex 2.0 objects can be managed by scripts: recording controller (a script may start and stop video recording), PTZ control (a script may control a PTZ device), and the layout control (that is – a script may control a video renderer, modify the layout it displays in the output video stream). If you think certain features available via HTTP API should be also made available via JS API in the first place, — let us know about that.

Check out the documentation for more information on scripting in Viinex 2.0. We do think that support for scripting can make the use of Viinex 2.0 easier in many scenarios, and we hope you’ll be able to get a confirmation for that by your own experience.

Leave a Reply