node-srt/examples/readable.js

23 lines
518 B
JavaScript
Raw Permalink Normal View History

TypeScript support (definition files) + a few small enhancement proposals (#5) * add typescript definition files for this JS API * server.js: replace console.log by debug() call * server.js: set "iface" and "port" properties on SRTServer listen call + and init them with null in constructor * stream.js: SRTReadStream: init fd property with null in constructor * stream.js: SRTReadStream: add close method (to free the fd aquired with connect()), likewise the writable stream methods * example files: add "use strict"; directive on all * examples/srt.js: correctly state variable fhandle (this would crash in strict mode otherwise) * NAPI: NodeSRT::GetSockOpt: fix error handling to really reach ThrowAsJavaScriptException * add example: srt.ts (TypeScript usage) * add .editoconfig to project root (helps keeping files free of whitespaces and maintain indentation etc) * package.json: improve metadata quality (via npm init call) * package.json: add dev-deps for tsc/ts-node and node type-defs * package.json: add check-tsc script to compile typescript example * gitignore: add tsc-lib (typescript compiler test output) * add tsconfig.json (typescript compiler config) * some end-of-file newline and whitespace fixes * stream.js: add const decls for all the magic numbers in SRTReadStream * enable eslint static analysis to find possible issues upfront + and maintain codestyle * update package-lock * stream.js: fix whitespace and eof * add lint script for src, examples and types modules * types: lint error fix
2020-07-20 11:41:15 +02:00
"use strict";
2020-06-22 11:49:07 +02:00
const fs = require('fs');
const dest = fs.createWriteStream('./output');
const { SRTReadStream } = require('../index.js');
setInterval(() => {
console.log("Hey, I am still alive!");
}, 2000);
2020-06-22 13:03:08 +02:00
if (process.argv[2] === "listener") {
const srt = new SRTReadStream('0.0.0.0', 1234);
srt.listen(readStream => {
readStream.pipe(dest);
});
2020-06-24 12:55:23 +02:00
console.log("async listen");
2020-06-22 13:03:08 +02:00
} else {
const srt = new SRTReadStream('127.0.0.1', 1234);
srt.connect(readStream => {
readStream.pipe(dest);
});
TypeScript support (definition files) + a few small enhancement proposals (#5) * add typescript definition files for this JS API * server.js: replace console.log by debug() call * server.js: set "iface" and "port" properties on SRTServer listen call + and init them with null in constructor * stream.js: SRTReadStream: init fd property with null in constructor * stream.js: SRTReadStream: add close method (to free the fd aquired with connect()), likewise the writable stream methods * example files: add "use strict"; directive on all * examples/srt.js: correctly state variable fhandle (this would crash in strict mode otherwise) * NAPI: NodeSRT::GetSockOpt: fix error handling to really reach ThrowAsJavaScriptException * add example: srt.ts (TypeScript usage) * add .editoconfig to project root (helps keeping files free of whitespaces and maintain indentation etc) * package.json: improve metadata quality (via npm init call) * package.json: add dev-deps for tsc/ts-node and node type-defs * package.json: add check-tsc script to compile typescript example * gitignore: add tsc-lib (typescript compiler test output) * add tsconfig.json (typescript compiler config) * some end-of-file newline and whitespace fixes * stream.js: add const decls for all the magic numbers in SRTReadStream * enable eslint static analysis to find possible issues upfront + and maintain codestyle * update package-lock * stream.js: fix whitespace and eof * add lint script for src, examples and types modules * types: lint error fix
2020-07-20 11:41:15 +02:00
}