{"id":13907753,"url":"https://github.com/Eyevinn/node-srt","last_synced_at":"2025-07-18T06:31:09.972Z","repository":{"id":39696429,"uuid":"271964265","full_name":"Eyevinn/node-srt","owner":"Eyevinn","description":"Nodejs bindings for Secure Reliable Transport SDK","archived":false,"fork":false,"pushed_at":"2023-11-20T12:02:59.000Z","size":483,"stargazers_count":90,"open_issues_count":8,"forks_count":31,"subscribers_count":11,"default_branch":"master","last_synced_at":"2024-11-16T11:07:05.326Z","etag":null,"topics":["library"],"latest_commit_sha":null,"homepage":null,"language":"JavaScript","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/Eyevinn.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":"CONTRIBUTING.md","funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null}},"created_at":"2020-06-13T07:46:27.000Z","updated_at":"2024-10-28T18:57:30.000Z","dependencies_parsed_at":"2023-11-20T10:40:58.636Z","dependency_job_id":"5c4fb39c-b5e0-4d53-a3b8-166db9515fa6","html_url":"https://github.com/Eyevinn/node-srt","commit_stats":{"total_commits":106,"total_committers":8,"mean_commits":13.25,"dds":"0.28301886792452835","last_synced_commit":"79fb0548c591e37d6a837bc2be261f71a338cd71"},"previous_names":[],"tags_count":20,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Eyevinn%2Fnode-srt","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Eyevinn%2Fnode-srt/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Eyevinn%2Fnode-srt/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Eyevinn%2Fnode-srt/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/Eyevinn","download_url":"https://codeload.github.com/Eyevinn/node-srt/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":226361511,"owners_count":17612918,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["library"],"created_at":"2024-08-06T23:02:08.883Z","updated_at":"2024-11-25T16:30:56.386Z","avatar_url":"https://github.com/Eyevinn.png","language":"JavaScript","funding_links":[],"categories":["HarmonyOS"],"sub_categories":["Windows Manager"],"readme":"\u003ch1 align=\"center\"\u003e\n  \u003cimg height=\"100px\" src=\"https://upload.wikimedia.org/wikipedia/commons/d/d9/Node.js_logo.svg\" /\u003e\u0026nbsp;\u0026nbsp;\u0026nbsp;\u0026nbsp;\n  \u003cimg alt=\"SRT\" src=\"http://www.srtalliance.org/wp-content/uploads/SRT_text_hor_logo_grey.png\" width=\"300\"/\u003e\n\u003c/h1\u003e\n\n`@eyevinn/srt` is a Node.js Native Addon that provides bindings to [Secure Reliable Transport SDK](https://github.com/Haivision/srt).\n\n## Install\n\n```\nnpm install --save @eyevinn/srt\n```\n\nInstalling from NPM downloads and builds SRT SDK and NodeJS addon for your operating system × architecture.\n\n## Prerequisities\n\nPlease refer to build instructions for your OS of the [SRT project](https://github.com/Haivision/srt#requirements).\n\nThis is providing a NodeJS binding layer that at its build-time assumes that plain libSRT already *can* be built on your system.\n\nWe 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.\n\nEverything we need on the NodeJS side of things (N-API, Gyp) gets installed via NPM,\nas you install this package.\n\nHowever, 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).\n\nAs you install all of the prerequisites, or even build the library already in your environment, this package should work also likewise.\n\n## Example\n\n```\nconst { SRT } = require('@eyevinn/srt');\n\nconst srt = new SRT();\nconst socket = srt.createSocket();\nsrt.bind(socket, \"0.0.0.0\", 1234);\nsrt.listen(socket, 2);\nconst fd = srt.accept(socket);\nif (fd) {\n  const chunk = srt.read(fd, 1316);\n}\n```\n\n## API\n\n```\nclass SRT {\n  createSocket(sender?:Boolean): socket:Number\n  bind(socket:Number, address:String, port:Number): result:Number\n  listen(socket:Number, backlog:Number): result:Number\n  connect(socket:Number, host:String, port:Number): result:Number\n  accept(socket:Number): fileDescriptor:Number\n  close(socket:Number): result:Number\n  read(socket:Number, chunkSize:Number): chunk:Buffer\n  write(socket:Number, chunk:Buffer): result:Number\n  setSockOpt(socket:Number, option:Number, value): result:Number\n  getSockOpt(socket:Number, option:Number): value\n  getSockState(socket:Number): value:Number\n  epollCreate(): epid:Number\n  epollAddUsock(epid:Number, socket:Number, events:Number): result:Number\n  epollUWait(epid:Number, msTimeOut:Number): events:Array\n  stats(socket:Number, clear:Boolean): stats:SRTStats\n}\n```\n\n### Async API\n\nThe 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](https://github.com/Eyevinn/node-srt/pull/6)). The Async API is a candidate to replace the main API in the next major release. Example with async/await:\n\n```\n  const { SRT, AsyncSRT } = require('@eyevinn/srt');\n\n  (async function() {\n    const asyncSrt = new AsyncSRT();\n    const socket = await asyncSrt.createSocket(false);\n    let result = await asyncSrt.bind(socket, \"0.0.0.0\", 1234);\n    result = await asyncSrt.listen(socket, 2);\n  })();\n```\n\nor with promises:\n\n```\n  const { SRT, AsyncSRT } = require('@eyevinn/srt');\n  const asyncSrt = new AsyncSRT();\n\n  let mySocket;\n  asyncSrt.createSocket(false)\n    .catch((err) =\u003e console.error(err))\n    .then((result) =\u003e {\n      mySocket = result;\n      return result;\n    })\n    .then((socket) =\u003e asyncSrt.bind(socket, \"0.0.0.0\", 1234))\n    .then((result) =\u003e {\n      if (result !== 0) {\n        throw new Error('Failed bind');\n      }\n      return asyncSrt.listen(mySocket, 2);\n    })\n    .then((result) =\u003e {\n      if (!result) {\n        console.log(\"Listen success\");\n      } else {\n        throw new Error('SRT listen error: ' + result);\n      }\n    });  \n```\n\n### High-performance read/write use-cases \u0026 server/multi-connection implementation\n\nIn order to perform on certain use-cases where larger chunks of data split into packets\nwould 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\nconnection on either side. A client connection instance can therefore just be a socket created\nwith a successful connection state via the SRT API, and then using the reader-writer for\nany sort of transmission upon it.\n\nAlso, 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\nin order to communicate with the respective client.\n\nThe best example to see all this in action at once is taking a look at the respective integration test(s).\n\nThese components also all have JSdoc annotations that should help with their usage.\n\n### Readable Stream\nA custom readable stream API is also available, example (in listener mode):\n\n```\nconst fs = require('fs');\nconst dest = fs.createWriteStream('./output');\nconst { SRTReadStream } = require('@eyevinn/srt');\n\nconst srt = new SRTReadStream('0.0.0.0', 1234);\nsrt.listen(readStream =\u003e {\n  readStream.pipe(dest);\n});\n```\n\nof in caller mode:\n\n```\nconst srt = new SRTReadStream('127.0.0.1', 1234);\nsrt.connect(readStream =\u003e {\n  readStream.pipe(dest);\n});\n```\n\n### Writable Stream\n\nExample of a writable stream\n\n```\nconst fs = require('fs');\nconst source = fs.createReadStream('./input');\nconst { SRTWriteStream } = require('@eyevinn/srt');\n\nconst srt = new SRTWriteStream('127.0.0.1', 1234);\nsrt.connect(writeStream =\u003e {\n  source.pipe(writeStream);\n});\n```\n\n## [Contributing](CONTRIBUTING.md)\n\nIn 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. \n\n## License (MIT)\n\nCopyright 2020 Eyevinn Technology\n\nPermission 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:\n\nThe above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.\n\nTHE 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.\n\n## Support\n\nJoin our [community on Slack](http://slack.streamingtech.se) where you can post any questions regarding any of our open source projects. Eyevinn's consulting business can also offer you:\n\n- Further development of this component\n- Customization and integration of this component into your platform\n- Support and maintenance agreement\n\nContact [sales@eyevinn.se](mailto:sales@eyevinn.se) if you are interested.\n\n## About Eyevinn Technology\n\nEyevinn Technology is an independent consultant firm specialized in video and streaming. Independent in a way that we are not commercially tied to any platform or technology vendor.\n\nAt Eyevinn, every software developer consultant has a dedicated budget reserved for open source development and contribution to the open source community. This give us room for innovation, team building and personal competence development. And also gives us as a company a way to contribute back to the open source community.\n\nWant to know more about Eyevinn and how it is to work here. Contact us at work@eyevinn.se!","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2FEyevinn%2Fnode-srt","html_url":"https://awesome.ecosyste.ms/projects/github.com%2FEyevinn%2Fnode-srt","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2FEyevinn%2Fnode-srt/lists"}