* replace stream module by improved version of readable/writable impl * rm server.js * async api improvments: - better tracing of calls from worker back and forth - fix transferrable handling to avoid copying buffers for r/w - optional debug logs - completed jsdocs annotations - add dispose method - add setLogLevel method (analoguous to added binding) * node-srt C bindings: - add SetLogLevel to get libSRT log output if desired - add OK static member - add #define EPOLL_EVENTS_NUM_MAX 1024 - improve error string thrown in Read (add that it comes from srt_recvmsg) - improve error string thrown in Write (add that it comes from srt_sendmsg2) - misc isofunctional improvements (var names) and comments * add SRT logging related JS-side helper * rewrite flat TypeScript decl files without "module" keyword * add ts enum decl for all libSRT enums * async-worker: enable using transferrable for zero-copy + allow better debugging (like in api/dispatcher side) + misc improvements on code quality * add async-helpers: various functions to help dealing with transferrables + tracing calls to native bindings in debug output * add async read/write modes functions + async-reader-writer class - these will allow for performing high-level r/w operations conveniently at optimum throughput for larger pieces of payload i.e list of packets. * add srt-server and srt-connection (can manage multiple clients), - based on async-api - can be used with reader/writer (i.e the underlying modes) * srt-server/connection typings * async srt spec: add dispose method usage (but commented out as crashing atm) * async srt spec: rm redundant checks on SRT static members (they are done in other spec already) * promises api spec: formal fixes * stream spec: add dummy test * package.json: - put gyp toolchain in runtime deps (since the build happens on install) - add JEST test runner - shorten check-tsc script - rebuild script: check & use all CPU cores available - run rebuild actually on install, not preinstall (fixes deps not being there) - remove preinstall and thus "npm install git-clone" in the package scripts * update package lock * update typings index not to need triple-slashs anymore * in srt.ts example: check for read return value type * build-srt-sdk script: - allow to use any local libSRT code repo - when using make: use all amount of cores available for build - isolate better code running on different platforms * update package main index with new things * add enum typings index * add jest config * add "use strict" on async-srt-await example * add integration/smoke testing for client-to-server one-way burst write * readme: add note on build prerequisites * readme: add infos on new components SRTServer/Connection & AsyncReaderWriter
123 lines
4.1 KiB
JavaScript
Executable file
123 lines
4.1 KiB
JavaScript
Executable file
#!/usr/bin/env node
|
|
|
|
"use strict";
|
|
|
|
const path = require('path');
|
|
const fs = require('fs');
|
|
const process = require('process');
|
|
const clone = require('git-clone');
|
|
const del = require('del');
|
|
const { spawnSync } = require('child_process');
|
|
const os = require('os');
|
|
const env = process.env;
|
|
|
|
const SRT_REPO = env.NODE_SRT_REPO || "https://github.com/Haivision/srt.git";
|
|
const SRT_CHECKOUT = "v1.4.1";
|
|
|
|
const srtRepoPath = env.NODE_SRT_LOCAL_REPO ? `file://${path.join(__dirname, env.NODE_SRT_LOCAL_REPO)}` : SRT_REPO;
|
|
const srtCheckout = env.NODE_SRT_CHECKOUT || SRT_CHECKOUT;
|
|
|
|
const depsPath = path.join(__dirname, '../', 'deps');
|
|
const srtSourcePath = path.join(depsPath, 'srt');
|
|
const buildDir = path.join(depsPath, 'build'); // FIXME: name this srt-build (in case other deps come up)
|
|
const numCpus = os.cpus().length; // NOTE: not the actual physical cores amount btw, see https://www.npmjs.com/package/physical-cpu-count
|
|
|
|
if (!fs.existsSync(depsPath)) {
|
|
console.log('Creating dir:', depsPath)
|
|
fs.mkdirSync(depsPath);
|
|
}
|
|
|
|
if (!fs.existsSync(srtSourcePath)) {
|
|
console.log(`Cloning ${srtRepoPath}#${srtCheckout}`);
|
|
clone(srtRepoPath, srtSourcePath, { checkout: srtCheckout }, (err) => {
|
|
|
|
if (err) {
|
|
console.error(err.message);
|
|
if (fs.existsSync(srtSourcePath)) del.sync(srtSourcePath);
|
|
process.exit(1);
|
|
}
|
|
|
|
build();
|
|
});
|
|
} else {
|
|
build();
|
|
}
|
|
|
|
function build() {
|
|
console.log('Building SRT SDK and prerequisites')
|
|
if (process.platform === "win32") {
|
|
buildWin32();
|
|
} else {
|
|
buildNx();
|
|
}
|
|
}
|
|
|
|
function buildWin32() {
|
|
process.env.SRT_ROOT = srtSourcePath;
|
|
fs.mkdirSync(buildDir);
|
|
|
|
console.log("Building OpenSSL");
|
|
const openssl = spawnSync('vcpkg', [ 'install', 'openssl', '--triplet', `${process.arch}-windows` ], { cwd: process.env.VCPKG_ROOT, shell: true } );
|
|
if (openssl.stdout)
|
|
console.log(openssl.stdout.toString());
|
|
if (openssl.status) {
|
|
console.log(openssl.stderr.toString());
|
|
process.exit(openssl.status);
|
|
}
|
|
|
|
console.log("Building pthreads");
|
|
const pthreads = spawnSync('vcpkg', [ 'install', 'pthreads', '--triplet', `${process.arch}-windows` ], { cwd: process.env.VCPKG_ROOT, shell: true } );
|
|
if (pthreads.stdout)
|
|
console.log(pthreads.stdout.toString());
|
|
if (pthreads.status) {
|
|
console.log(pthreads.stderr.toString());
|
|
process.exit(pthreads.status);
|
|
}
|
|
|
|
console.log("Integrate vcpkg build system");
|
|
const integrate = spawnSync('vcpkg', [ 'integrate', 'install' ], { cwd: process.env.VCPKG_ROOT, shell: true } );
|
|
if (integrate.stdout)
|
|
console.log(integrate.stdout.toString());
|
|
if (integrate.status) {
|
|
console.log(integrate.stderr.toString());
|
|
process.exit(integrate.status);
|
|
}
|
|
|
|
console.log("Running cmake generator");
|
|
const generator = spawnSync('cmake', [ srtSourcePath, '-DCMAKE_BUILD_TYPE=Release', '-G"Visual Studio 16 2019"', '-A', process.arch, '-DCMAKE_TOOLCHAIN_FILE="%VCPKG_ROOT%\\scripts\\buildsystems\\vcpkg.cmake' ], { cwd: buildDir, shell: true } );
|
|
if (generator.stdout)
|
|
console.log(generator.stdout.toString());
|
|
if (generator.status) {
|
|
console.log(generator.stderr.toString());
|
|
process.exit(generator.status);
|
|
}
|
|
|
|
console.log("Running CMake build");
|
|
const build = spawnSync('cmake', [ '--build', buildDir, '--config', 'Release' ], { cwd: buildDir, shell: true } );
|
|
if (build.stdout)
|
|
console.log(build.stdout.toString());
|
|
if (build.status) {
|
|
console.log(build.stderr.toString());
|
|
process.exit(build.status);
|
|
}
|
|
}
|
|
|
|
function buildNx() {
|
|
console.log("Running ./configure");
|
|
const configure = spawnSync('./configure', [ '--prefix', buildDir ], { cwd: srtSourcePath, shell: true, stdio: 'inherit' } );
|
|
if (configure.status) {
|
|
process.exit(configure.status);
|
|
}
|
|
|
|
console.log("Running make with threads:", numCpus);
|
|
const make = spawnSync('make', [`-j${numCpus}`], { cwd: srtSourcePath, shell: true, stdio: 'inherit' });
|
|
if (make.status) {
|
|
process.exit(make.status);
|
|
}
|
|
|
|
console.log("Running make install");
|
|
const install = spawnSync('make', ['install'], { cwd: srtSourcePath, shell: true, stdio: 'inherit' });
|
|
if (install.status) {
|
|
process.exit(install.status);
|
|
}
|
|
}
|