In this article, I will walk you through the process of building a real-world video analytics application using React.
For this example, I am going to use an open source library called rasterjs.
It’s a JavaScript library for rendering and manipulating 3D shapes.
The library comes with a very robust API, and the core code itself is free and open source.
You can find the full source code at github.com/rasterjs/rasters.js, which is hosted under the MIT License.
The API is easy to use, and you can easily set up a server to run a live feed or generate reports for your analytics team.
To get started, we’ll create a simple AngularJS application using raster js.
In the app directory, we will create a new project and add the raster.js dependencies.
From the command line, run the following command: $ npm install –save-dev raster-js We will then create a single AngularJS file and name it raster_app.js.
The file is located at /app/assets/javascripts/app.min.js .
Open up the file and add a new function that returns a new object called rasters.
We’ll call it rasters() and we will also create a data source, a URL, and a callback function.
In our rasters function, we are just passing in the object we just created and passing the data source and the callback function as arguments.
We then pass in the number of seconds since the start of the video and we call the callback in our raster object.
If the browser supports WebSockets, we can also pass in WebSocket as a WebSocket port number.
For our data source URL, we just need to specify a custom URL that points to a GitHub repo with a link to the data.
To set up the data, we simply need to define a property for our source URL.
Next, we need to add a method for our callback function that will return the number in milliseconds since the beginning of the stream.
Finally, we define our callback in the rasters object.
We will call our function with the data we just generated.
Now, let’s start creating the server.
We can use the command-line tools from the AngularJS terminal emulator to create a server file and a directory structure.
Open up your server.js file and change the content to look like the following: const {RasterJS} = require(‘raster-sdk’); const app = angular.module(‘rasters’, []); app.set(‘rakers’, rasters); This is where the actual data is generated.
In this code, we declare two functions, rasters and rasters_callback, and then we create a third function, raster() , which returns a reference to the rasts object.
When you run the server, you will see the following output: rasters: 0.3 seconds since start rasters is now in progress rasters started: 1.6 seconds since end rasters finished: 0 seconds since resuming rasters in progress: 0 milliseconds since starting rasters done: 0 minutes since resumption rasters stopped: 0 msec since stopping rasters complete: 0 ms since resettling rasters ready: 0ms since starting