Node.js Native Addon for Secure Reliable Transport
--
@eyevinn/srt
is a Node.js Native Addon that provides bindings to SRTEyevinn joined the SRT Alliance earlier this year and our first contribution back to this community is a Node.js native addon for Secure Reliable Transport (SRT*) based on the open sourced SDK. This addon is also available as open source.
Why would you want SRT support in a Javascript based application one could ask? The use cases where you want to process video in Javascript might be limited but there might be other types of data that you in a secure and reliable way want to transport between two applications.
Node.js provides a mechanism where you can dynamically load C++ Addons as ordinary Node.js modules providing an interface between Javascript and C++ libraries. The SRT Alliance provides an open source SDK for the implementation of SRT that is written in C++. What we have developed is an Node.js library that binds these two things together. This library is written in C++ and based on the N-API framework. By building the Addon on N-API you don’t have to compile the library for a specific Node.js version as this API is Application Binary Interface (ABI) stable across versions of Node.js.
To install the library:
npm install --save @eyevinn/srt
When installing this Node.js library it will download and build the latest version of the SRT SDK before building the Node.js Addon. The build system is based on node-gyp that comes bundled with Node Package Manager (npm). And once installed you can write this “hello world”-example.
const { SRT } = require('@eyevinn/srt');const srt = new SRT();
const socket = srt.createSocket();
srt.bind(socket, "0.0.0.0", 1234);
srt.listen(socket, 2);
const fd = srt.accept(socket);
if (fd) {
const chunk = srt.read(fd, 1316);
}
This example will create an SRT socket that is bound to any interface and port 1234. On this port the application will listen for new connection and when a client connects start to read data.
An alpha-alpha version of this library is available already today here: https://www.npmjs.com/package/@eyevinn/srt and it is not yet fully feature-complete with the SRT SDK. It will be evolved and we will show you some more use cases and examples in blog posts here. So make sure you follow this blog if you are interested in this. We are also happy for contributions so we can evolve this together. The source code is available on Github.
The Node.js community is a large community with many open source initiatives providing building blocks to build awesome applications. Eyevinn is an active contributor to the open source community in video and we believe it is important when building services and applications, where some open source components are used, to also give something back.
If you have any further questions and comments on this blog drop a comment below or tweet the author on Twitter (@JonasBirme).
Eyevinn Technology is leading specialists in video technology and media distribution, and proud organizer of the yearly nordic conference Streaming Tech Sweden.
(*) SRT is an open source video transport protocol and technology stack that optimizes streaming performance across unpredictable networks with secure streams and easy firewall traversal, bringing the best quality live video over the worst networks.