DEV Community

Jonas Birmé for Eyevinn Video Dev-Team Blog

Posted on

SRT Server in NodeJS

Part of a series of videos we go through the necessary building blocks to build an SRT to WebRTC gateway in NodeJS. SRT in terms of the transport protocol called Secure Reliable Transport.

In the first episode we go through how to build an SRT server using the NodeJS native bindings provided by our @eyevinn/srt library.

Install the library

npm install --save @eyevinn/srt
Enter fullscreen mode Exit fullscreen mode

This will download the SRT SDK and compile it on your computer. Example of a very simple SRT receiver (in listener mode) using the Readable stream API included in the library.

const fs = require('fs');
const dest = fs.createWriteStream('./output.ts');

const { SRTReadStream } = require('@eyevinn/srt');
const srt = new SRTReadStream('0.0.0.0', 1234);
srt.listen(readStream => {
  console.log("Client connected");
  readStream.pipe(dest);
});

console.log("Waiting for client to connect");
Enter fullscreen mode Exit fullscreen mode

Above example will setup an SRT socket to listen on port 1234 for a connection. Once a connection is established it will read data from the socket and pipe it to a Writable stream that writes to disk.

Oldest comments (2)

Collapse
 
grufft profile image
gruffT

Hey Jonas
Great article.
I've spent the last week building this workflow in another stack but would much prefer to stay all in the JavaScript world. Would you mind sharing the stack you intend to use at a high level here so I can move on?
Cheers

Collapse
 
birme profile image
Jonas Birmé

Hi! Sorry for late reply. My plan was to stay in the JavaScript world by building / using an JS-based demuxer and h264 decoder compiled in WebAssembly