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
This commit is contained in:
parent
25db0b005b
commit
7973c63f2a
20 changed files with 1320 additions and 28 deletions
|
|
@ -1,3 +1,5 @@
|
|||
"use strict";
|
||||
|
||||
const fs = require('fs');
|
||||
const { SRTWriteStream } = require('../index.js');
|
||||
|
||||
|
|
@ -8,9 +10,9 @@ srt.connect(writeStream => {
|
|||
});
|
||||
srt.on('error', err => {
|
||||
console.error(err.message);
|
||||
})
|
||||
});
|
||||
|
||||
process.on('SIGINT', () => {
|
||||
console.log("Closing connection");
|
||||
srt.close();
|
||||
});
|
||||
});
|
||||
|
|
|
|||
|
|
@ -1,10 +1,12 @@
|
|||
"use strict";
|
||||
|
||||
const { SRT } = require('../index.js');
|
||||
|
||||
const srt = new SRT();
|
||||
const socket = srt.createSocket();
|
||||
if (socket !== -1) {
|
||||
console.log("Created socket: " + socket);
|
||||
}
|
||||
}
|
||||
|
||||
let result;
|
||||
|
||||
|
|
@ -41,7 +43,7 @@ while (true) {
|
|||
} else {
|
||||
while (true) {
|
||||
const chunk = srt.read(event.socket, 1316);
|
||||
console.log("Read chunk: " + chunk.length);
|
||||
console.log("Read chunk: " + chunk.length);
|
||||
}
|
||||
}
|
||||
});
|
||||
|
|
|
|||
|
|
@ -1,3 +1,5 @@
|
|||
"use strict";
|
||||
|
||||
const fs = require('fs');
|
||||
const dest = fs.createWriteStream('./output');
|
||||
const { SRTReadStream } = require('../index.js');
|
||||
|
|
@ -17,4 +19,4 @@ if (process.argv[2] === "listener") {
|
|||
srt.connect(readStream => {
|
||||
readStream.pipe(dest);
|
||||
});
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1,3 +1,5 @@
|
|||
"use strict";
|
||||
|
||||
const fs = require('fs');
|
||||
const { SRTReadStream } = require('../index.js');
|
||||
|
||||
|
|
|
|||
|
|
@ -1,10 +1,12 @@
|
|||
"use strict";
|
||||
|
||||
const { SRT } = require('../index.js');
|
||||
|
||||
const srt = new SRT();
|
||||
const socket = srt.createSocket();
|
||||
if (socket !== -1) {
|
||||
console.log("Created socket: " + socket);
|
||||
}
|
||||
}
|
||||
|
||||
let result;
|
||||
result = srt.bind(socket, "0.0.0.0", 1234);
|
||||
|
|
@ -22,10 +24,10 @@ if (!result) {
|
|||
}
|
||||
|
||||
console.log("Waiting for client to connect");
|
||||
fhandle = srt.accept(socket);
|
||||
const fhandle = srt.accept(socket);
|
||||
|
||||
if (fhandle) {
|
||||
console.log("Client connected");
|
||||
const chunk = srt.read(fhandle, 1316);
|
||||
console.log("Read chunk: " + chunk.length);
|
||||
}
|
||||
}
|
||||
|
|
|
|||
31
examples/srt.ts
Normal file
31
examples/srt.ts
Normal file
|
|
@ -0,0 +1,31 @@
|
|||
import {SRT} from '../index';
|
||||
|
||||
const srt = new SRT();
|
||||
const socket = srt.createSocket();
|
||||
if (socket !== -1) {
|
||||
console.log("Created socket: " + socket);
|
||||
}
|
||||
|
||||
let result;
|
||||
result = srt.bind(socket, "0.0.0.0", 1234);
|
||||
if (!result) {
|
||||
console.log("Bind success");
|
||||
} else {
|
||||
console.log(result);
|
||||
}
|
||||
|
||||
result = srt.listen(socket, 2);
|
||||
if (!result) {
|
||||
console.log("Listen success");
|
||||
} else {
|
||||
console.log(result);
|
||||
}
|
||||
|
||||
console.log("Waiting for client to connect");
|
||||
const fhandle = srt.accept(socket);
|
||||
|
||||
if (fhandle) {
|
||||
console.log("Client connected");
|
||||
const chunk = srt.read(fhandle, 1316);
|
||||
console.log("Read chunk: " + chunk.length);
|
||||
}
|
||||
|
|
@ -1,3 +1,5 @@
|
|||
"use strict";
|
||||
|
||||
const fs = require('fs');
|
||||
const source = fs.createReadStream(process.argv[2], { highWaterMark: 1316 });
|
||||
const { SRTWriteStream } = require('../index.js');
|
||||
|
|
@ -5,4 +7,4 @@ const { SRTWriteStream } = require('../index.js');
|
|||
const srt = new SRTWriteStream('127.0.0.1', 1234);
|
||||
srt.connect(writeStream => {
|
||||
source.pipe(writeStream);
|
||||
});
|
||||
});
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue