提交 9a2d8e14 authored 作者: Iñaki Baz Castillo's avatar Iñaki Baz Castillo

Start Node server.

上级 c290cb2b
/node_modules/
/mediasoup-worker/**/*.o /mediasoup-worker/**/*.o
/mediasoup-worker/bin/ /mediasoup-worker/bin/
/mediasoup-worker/mediasoup-tester.sh /mediasoup-worker/mediasoup-tester.sh
......
{
"disallowDanglingUnderscores": null,
"disallowMixedSpacesAndTabs": true,
"disallowMultipleLineBreaks": true,
"disallowMultipleSpaces": null,
"disallowNamedUnassignedFunctions": true,
"disallowOperatorBeforeLineBreak": null,
"disallowSpaceBeforeSemicolon": true,
"disallowSpacesInFunction":
{
"beforeOpeningRoundBrace": true
},
"disallowSpacesInCallExpression": true,
"disallowSpacesInsideParentheses": true,
"disallowSpacesInsideParenthesizedExpression": true,
"disallowTrailingComma": true,
"disallowTrailingWhitespace": true,
"disallowYodaConditions": true,
"requireAlignedMultilineParams": "firstParam",
"requireCamelCaseOrUpperCaseIdentifiers": true,
"requireCommaBeforeLineBreak": true,
"requireFunctionDeclarations": true,
"requireNewlineBeforeBlockStatements": true,
"requirePaddingNewLineAfterVariableDeclaration": true,
"requireSemicolons": true,
"requireSpaceAfterBinaryOperators": true,
"requireSpaceAfterComma": true,
"requireSpaceAfterKeywords":
[
"do",
"for",
"if",
"else",
"switch",
"case",
"try",
"void",
"while",
"with",
"return",
"typeof"
],
"requireSpaceBeforeBinaryOperators": true,
"requireSpaceBeforeBlockStatements": true,
"requireSpaceBetweenArguments": true,
"requireSpacesInConditionalExpression": true,
"requireSpacesInForStatement": true,
"requireSpacesInsideObjectBrackets": "allButNested",
"requireVarDeclFirst": null,
"validateIndentation": "\t",
"validateParameterSeparator": ", ",
"validateQuoteMarks": "'"
}
{
"esnext": true,
"bitwise": true,
"curly": true,
"eqeqeq": true,
"forin": false,
"freeze": true,
"latedef": "function",
"noarg": true,
"nonbsp": true,
"nonew": true,
"plusplus": false,
"undef": true,
"unused": true,
"strict": true,
"maxparams": 5,
"maxdepth": 4,
"maxstatements": false,
"maxlen": 200,
"proto": true,
"sub": false,
"browser": false,
"browserify": false,
"devel": false,
"jquery": false,
"mocha": true,
"node": true,
"shelljs": false,
"worker": false
}
'use strict';
const gulp = require('gulp');
const jshint = require('gulp-jshint');
const jscs = require('gulp-jscs');
const stylish = require('gulp-jscs-stylish');
gulp.task('lint', () =>
{
let src = ['gulpfile.js', 'mediasoup-hub/index.js', 'mediasoup-hub/lib/**/*.js'];
return gulp.src(src)
.pipe(jshint('.jshintrc'))
.pipe(jscs('.jscsrc'))
.pipe(stylish.combineWithHintResults())
.pipe(jshint.reporter('jshint-stylish', { verbose: true }))
.pipe(jshint.reporter('fail'));
});
gulp.task('default', gulp.series('lint'));
'use strict';
const debug = require('debug')('mediasoup');
const debugerror = require('debug')('mediasoup:ERROR');
debugerror.log = console.error.bind(console);
const Server = require('./lib/Server');
module.exports =
{
createServer : function(options)
{
debug('createServer() [options:%o]', options);
return new Server(options);
}
};
'use strict';
const path = require('path');
const spawn = require('child_process').spawn;
const process = require('process');
const os = require('os');
const debug = require('debug')('mediasoup:Server');
const debugerror = require('debug')('mediasoup:ERROR:Server');
debugerror.log = console.error.bind(console);
const check = require('check-types');
const randomString = require('random-string');
const DEFAULT_NUM_WORKERS = Object.keys(os.cpus()).length;
const MEDIASOUP_WORKER_BIN_PATH = path.join(__dirname, '..', '..', 'mediasoup-worker', 'bin', 'mediasoup-worker');
var servers = new Set();
process.on('exit', () =>
{
for (let server of servers)
{
server.close();
}
});
class Server
{
constructor(options)
{
debug('constructor() [options:%o]', options);
let serverId = randomString({ numeric: false, length: 6 }).toLowerCase();
let numWorkers;
options = options || {};
if (check.integer(options.numWorkers) && check.positive(options.numWorkers))
{
numWorkers = options.numWorkers;
}
else
{
numWorkers = DEFAULT_NUM_WORKERS;
}
debug('constructor() [serverId:%s, numWorkers:%d]', serverId, numWorkers);
// mediasoup-worker child processes within this room
this._workers = new Map();
// Create mediasoup worker child processes
for (let i = 1; i <= numWorkers; i++)
{
let workerId = serverId + '#' + i;
let worker = spawn(MEDIASOUP_WORKER_BIN_PATH, [ workerId ]);
// Store worker id within the worker process
worker.workerId = workerId;
worker.stdout.on('data', (buffer) =>
{
buffer.toString('utf8').split('\n').forEach((line) =>
{
if (line)
{
debug(line);
}
});
});
worker.stderr.on('data', (buffer) =>
{
buffer.toString('utf8').split('\n').forEach((line) =>
{
if (line)
{
debugerror(line);
}
});
});
worker.on('close', (code) =>
{
debug('worker process closed [workerId:%s, code:%s]', worker.workerId, code);
});
worker.on('error', (error) =>
{
debugerror('worker process failed to start [workerId:%s]: %s', worker.workerId, error);
});
// Add the worker to the map
this._workers.set(workerId, worker);
}
// Add the server to the set
servers.add(this);
}
close()
{
debug('close()');
for (let worker of this._workers.values())
{
// TODO: set proper signal
worker.kill();
}
}
}
module.exports = Server;
{
"name": "mediasoup",
"version": "0.0.1",
"description": "Node/C++ multiconference media server ready for WebRTC",
"main": "mediasoup-hub/index.js",
"repository": {
"type": "git",
"url": "https://github.com/ibc/mediasoup.git"
},
"author": "Iñaki Baz Castillo <ibc@aliax.net>",
"license": "ISC",
"bugs": {
"url": "https://github.com/ibc/mediasoup/issues"
},
"homepage": "https://github.com/ibc/mediasoup/",
"engines": {
"node": ">=4.0.0"
},
"dependencies": {
"bluebird": "^3.0.6",
"check-types": "^5.1.0",
"debug": "^2.2.0",
"random-string": "^0.1.2"
},
"devDependencies": {
"gulp": "git://github.com/gulpjs/gulp.git#4.0",
"gulp-jscs": "^3.0.2",
"gulp-jscs-stylish": "^1.2.1",
"gulp-jshint": "^2.0.0",
"jshint-stylish": "^2.0.1"
}
}
Markdown 格式
0% 或
您添加了 0 人 到此讨论。请谨慎行事。
请先完成此评论的编辑!
请 注册 或者 后发表评论