This is a short recipe referring to a way of altering the default behavior of the recctl object as it is implemented within viinex.
As of viinex build 986 the script `recctl.js` is included to make it possible to make the recctl object
- turn on the recording at system startup, without the need for additional external call, and
- implement the “synchronous” version of the flush operation.
The first item is pretty obvious, can be required in certain scenarios, and the need for an explicit call to turn on the recording can be extremely inconvenient within a distributed application.
The second one, the “synchronous” flush, can be useful when the application needs to make sure that a particular media data becomes available for reading, say, in playback or media export operations.
The idea of the script is simple: it uses the “onupdate” handler to respond to API calls, and to implement the synchronous semantics for the flush operation, it makes use of promises. In particular, the script returns a promise from the onupdate handler. The promise itself gets resolved when the script receives the event from the media storage: then the script may examine that event to see if the camera id in it matches the camera id of our interest, and if it does — the script knows that the next media fragment was written to the storage, and thus the promise may be fulfilled.
Respective configuration may look as shown in this gist
The takeaways as for the config:
- one need to create the “recctl” object which does the actual job, and link it with a media source and media archive, as usual;
- instead of linking that recctl with an HTTP server or a WAMP client, — it’s linked with the script.
- The script is created to use the code from module “recctl.js”. It may have “init.subject” to mention the default camera id.
- The script should be linked with the recctl object (because the script needs to control that recctl) and the media storage object (because the script needs to receive events from the media storage).
- Also, for issuing commands to be executed by the script, the latter should be linked with an HTTP server, or a WAMP client.
Usage of that script may look as follows:
$ curl -X POST localhost:8880/v1/svc/cam3_recctl_script --data-binary '{"method":"flush", "subject": "cam3"}'
{"subject":"cam3","success":true,"time_boundary":"2026-01-04T17:54:19.009Z"}
So this is a normal call to the Updateable interface of a viinex object. As an argument, a JSON object is passed, having the property “method” set to “flush”. This is recognized by the script. In response, if the operation was successful, the script returns the right boundary of the timeline for this specific media source, as it was just reported by the media storage. The application can be sure that if it exports the media data up to this right boundary — it’ll actually get the result.
Of course this is just a basic example. This script can be extended by the user to handle additional rules for recording media: for example, these can be predicates on motion alarms from the camera, or a schedule.