百科.dev
全部条目在线工具AI 编程趋势榜开源项目技术资讯提交条目
登录
< 返回工具列表
N

node-srt

> 编程语言
开源

Secure Reliable Transport SDK 的 Nodejs 绑定

98 stars0 点赞2 次浏览
访问官网GitHub

工具介绍

Secure Reliable Transport SDK 的 Nodejs 绑定

    

@eyevinn/srt is a Node.js Native Addon that provides bindings to Secure Reliable Transport SDK.

Install

bash
npm install --save @eyevinn/srt

Installing from NPM downloads and builds SRT SDK and NodeJS addon for your operating system × architecture.

Prerequisities

Please refer to build instructions for your OS of the SRT project.

This is providing a NodeJS binding layer that at its build-time assumes that plain libSRT already can be built on your system.

We will merely pull in an SRT codebase from a GIT repo here (that may be local or remote), and attempt to compile it (using the specific toolchain and commands invoked for each OS). See scripts/build-srt-sdk.js. Then linking the result of it into the compiled NodeJS add-on we provide here via the Gyp tool.

Everything we need on the NodeJS side of things (N-API, Gyp) gets installed via NPM, as you install this package.

However, it is not provided with this any prerequisits of building libSRT itself (we only try to invoke the toolchain correctly, whichever it is, on your OS).

As you install all of the prerequisites, or even build the library already in your environment, this package should work also likewise.

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);
}

API

…

Async API

The N-API binding layer to the SRT SDK is such that every native call are blocking I/O and runs synchroneuosly with the wrapping JS function call. This means that these functions are called from the Node.js proc main-thread / event loop. This creates a throughput limit and in general having blocking operations can impact application performance in an unpredictable way. To address this issue we have an "async variant" of the API where the native blocking calls are put on a JS Worker thread instead (big thanks to @tchakabam for this contribution). The Async API is a candidate to replace the main API in the next major release. Example with async/await:

  const { SRT, AsyncSRT } = require('@eyevinn/srt');

  (async function() {
    const asyncSrt = new AsyncSRT();
    const socket = await asyncSrt.createSocket(false);
    let result = await asyncSrt.bind(socket, "0.0.0.0", 1234);
    result = await asyncSrt.listen(socket, 2);
  })();

or with promises:

…

High-performance read/write use-cases & server/multi-connection implementation

In order to perform on certain use-cases where larger chunks of data split into packets would need to be sent/received in bursts, we provide "modes" and a high-level class called AsyncReaderWriter, which can be initialized an existing AsyncSRT instance, i.e a worker thread, and a given SRT socket identifier. It therefore allows to plug-into any concept of a connection on either side. A client connection instance can therefore just be a socket created with a successful connection state via the SRT API, and then using the reader-writer for any sort of transmission upon it.

Also, we provide a class to allow building a server that can accept multiple incoming connections(SRTServer and its friend SRTConnection). The latter server-side connection object has the method SRTConnection#getReaderWriter() to allow using the reader-writer in order to communicate with the respective client.

The best example to see all this in action at once is taking a look at the respective integration test(s).

These components also all have JSdoc annotations that should help with their usage.

Readable Stream

A custom readable stream API is also available, example (in listener mode):

const fs = require('fs');
const dest = fs.createWriteStream('./output');
const { SRTReadStream } = require('@eyevinn/srt');

const srt = new SRTReadStream('0.0.0.0', 1234);
srt.listen(readStream => {
  readStream.pipe(dest);
});

of in caller mode:

const srt = new SRTReadStream('127.0.0.1', 1234);
srt.connect(readStream => {
  readStream.pipe(dest);
});

Writable Stream

Example of a writable stream

const fs = require('fs');
const source = fs.createReadStream('./input');
const { SRTWriteStream } = require('@eyevinn/srt');

const srt = new SRTWriteStream('127.0.0.1', 1234);
srt.connect(writeStream => {
  source.pipe(writeStream);
});

Contributing

In addition to contributing code, you can help to triage issues. This can include reproducing bug reports, or asking for vital information such as version numbers or reproduction instructions.

License (MIT)

Copyright 2020 Eyevinn Technology

Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.

Support

Join our community on Slack where you can post any questions regarding any of our open source projects. Eyevinn's consulting business can also offer you:

  • Further development of this component
  • Customization and integration of this component into your platform
  • Support and maintenance agreement

Contact [email protected] if you are interested.

About Eyevinn Technology

Eyevinn Technology is an independent video streaming technology consultancy specializing in open-source streaming solutions, cloud-native media infrastructure, and AI-powered media workflows. We are not commercially tied to any platform or technology vendor, which means our recommendations are always based on what is best for your use case. Our engineers actively contribute to and maintain open-source projects across the streaming ecosystem, and we use open platforms to automate complex media workflows at scale. Contact [email protected] to learn how Eyevinn can help you build and evolve your video streaming capabilities.

Issues· 0 开放

查看全部 Issues在 GitHub 打开

暂无开放 Issues,或尚未同步最近议题。

> 标签

JavaScriptlibrary

暂无评论,来聊聊你的看法吧

> 工具信息

发布日期2026年8月1日
最后更新2026年9月18日
分类编程语言
定价开源

> 相关工具

T
TypeScript
JavaScript 的超集,为前端与全栈提供静态类型
P
Python
通用编程语言,广泛用于 Web、数据与 AI
G
Go
Google 推出的简洁高效系统语言