Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

win support #329

Merged
merged 44 commits into from
Oct 6, 2019
Merged
Show file tree
Hide file tree
Changes from 18 commits
Commits
Show all changes
44 commits
Select commit Hold shift + click to select a range
be16bb5
build for win
haiyangwu Aug 26, 2019
e9ee7c3
code style
haiyangwu Aug 26, 2019
27c1307
code style
haiyangwu Aug 26, 2019
f2b060e
scripts
haiyangwu Aug 26, 2019
8de983a
replace duplex pipe with two pipe
haiyangwu Aug 29, 2019
3e57e56
code style
haiyangwu Aug 29, 2019
12b6a3c
add explicit key word
haiyangwu Aug 30, 2019
283351a
move getopt to deps
haiyangwu Aug 30, 2019
9cd71b3
Merge remote-tracking branch 'versatica/v3' into v3. Fix typo
haiyangwu Aug 30, 2019
a15863c
single quotes
haiyangwu Aug 30, 2019
b86a32f
pyc explicit path
haiyangwu Aug 30, 2019
9a66008
delete unused dep
haiyangwu Aug 30, 2019
c20fb5b
log text & code style
haiyangwu Aug 30, 2019
850761f
rename SocketRole to role
haiyangwu Aug 30, 2019
6a1a927
log text & code style
haiyangwu Aug 30, 2019
af693c4
replace _MSC_VER with _WIN32 for better compatibility
haiyangwu Aug 30, 2019
d3f3a4c
add public keyword to separate method and var
haiyangwu Aug 30, 2019
cbc1b1d
Generate sln under worker directory for unifying test:woker logic
haiyangwu Aug 30, 2019
e489d3b
add "getopt" entry in worker/scripts/get-dep.sh
haiyangwu Sep 1, 2019
793900d
code style
haiyangwu Sep 1, 2019
3585288
add comment for skipping test case in win32
haiyangwu Sep 1, 2019
14a38ba
move gulp-clang-format into devDep
haiyangwu Sep 1, 2019
cac00ed
unify name
haiyangwu Sep 1, 2019
3dbf56d
change for lint
haiyangwu Sep 2, 2019
4f10db0
use run-script-os instead of gulp
haiyangwu Sep 2, 2019
174c1dd
use @dr.amaton/run-script-os instead of a git repo
haiyangwu Sep 3, 2019
7b20534
win tasks
haiyangwu Sep 5, 2019
e70535c
remove useless tasks
haiyangwu Sep 7, 2019
a4bed7d
run mediasoup-worker-test
haiyangwu Sep 7, 2019
e566abe
add win-tasks.js to lint
haiyangwu Sep 7, 2019
cda5e7e
code style
haiyangwu Sep 11, 2019
6885c44
code style and readability
haiyangwu Sep 11, 2019
b6775ab
code style
haiyangwu Sep 11, 2019
faa375f
code style
haiyangwu Sep 11, 2019
6578c6b
remove duplicated LF
haiyangwu Sep 11, 2019
6fbcc2a
wrap consumer socket and producer socket
haiyangwu Sep 11, 2019
d0a9005
gitignore
haiyangwu Sep 12, 2019
36e2b4c
code style
haiyangwu Sep 12, 2019
bbdae70
add virtual destructor
haiyangwu Sep 12, 2019
3dddc43
Merge remote-tracking branch 'versatica/devel' into v3
haiyangwu Oct 3, 2019
7ac3a99
add defines for abseil
haiyangwu Oct 3, 2019
461e7a5
include
haiyangwu Oct 3, 2019
96a62bd
Merge remote-tracking branch 'versatica/devel' into v3
haiyangwu Oct 5, 2019
62aeb29
dot at the end of the comment
haiyangwu Oct 6, 2019
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion .eslintrc.js
Original file line number Diff line number Diff line change
Expand Up @@ -172,6 +172,7 @@ module.exports =
'spaced-comment': [ 2, 'always' ],
'strict': 2,
'valid-typeof': 2,
'yoda': 2
'yoda': 2,
'linebreak-style': 0
haiyangwu marked this conversation as resolved.
Show resolved Hide resolved
}
};
14 changes: 14 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,10 @@
# gyp generated stuff.
/worker/out/
/worker/**/*.xcodeproj/
/worker/**/*.sln
/worker/**/*.vcxproj
/worker/**/*.vcxproj.filters
/worker/**/*.vcxproj.user

# clang-fuzzer stuff is too big.
/worker/deps/clang-fuzzer
Expand All @@ -22,3 +26,13 @@

# Mac Stuff.
.DS_Store

# python win generated Stuff.
haiyangwu marked this conversation as resolved.
Show resolved Hide resolved
/worker/scripts/configure.pyc

# vistual studio generated Stuff.
haiyangwu marked this conversation as resolved.
Show resolved Hide resolved
/worker/**/Debug/
/worker/**/Release/

# VS stuff.
haiyangwu marked this conversation as resolved.
Show resolved Hide resolved
/worker/.vs/
38 changes: 38 additions & 0 deletions gulpfile.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
const gulp = require('gulp');
const shell = require('gulp-shell');
const clangFormat = require('gulp-clang-format');
const os = require('os');
ibc marked this conversation as resolved.
Show resolved Hide resolved

ibc marked this conversation as resolved.
Show resolved Hide resolved
const workerFiles =
[
Expand Down Expand Up @@ -37,3 +39,39 @@ gulp.task('format:worker', () =>
.pipe(clangFormat.format('file'))
.pipe(gulp.dest('.'));
});

gulp.task('win:build', shell.task(
[
'echo build for windows',
'python ./worker/scripts/configure.py --format=msvs',
`MSBuild ./worker/mediasoup-worker.sln /p:Configuration=${process.env.MEDIASOUP_BUILDTYPE === 'Debug' ?'Debug' : 'Release'} -t:mediasoup-worker `
],
{
verbose : true
}
));

gulp.task('make:build', shell.task(
[
'make -C worker'
],
{
verbose : true
}
));

gulp.task('build', gulp.series(os.platform() === 'win32'? 'win:build' : 'make:build'));

gulp.task('test:win:worker', shell.task(
[
'echo not support yet!!! run test in visual studio!!!'
]
));

gulp.task('test:make:worker', shell.task(
[
'make test -C worker'
]
));

gulp.task('test:worker', gulp.series(os.platform() === 'win32'? 'test:win:worker' : 'test:make:worker'));
30 changes: 20 additions & 10 deletions lib/Channel.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ class Channel extends EnhancedEventEmitter
/**
* @private
*/
constructor({ socket, pid })
constructor({ producerSocket, consumerSocket, pid })
{
const logger = new Logger(`Channel[pid:${pid}]`);
const workerLogger = new Logger(`worker[pid:${pid}]`);
Expand All @@ -30,7 +30,8 @@ class Channel extends EnhancedEventEmitter

// Unix Socket instance.
// @type {net.Socket}
this._socket = socket;
this._producerSocket = producerSocket;
this._consumerSocket = consumerSocket;

// Next request id.
// @type {Number}
Expand All @@ -45,7 +46,7 @@ class Channel extends EnhancedEventEmitter
this._recvBuffer = null;

// Read Channel responses/notifications from the worker.
this._socket.on('data', (buffer) =>
this._consumerSocket.on('data', (buffer) =>
{
if (!this._recvBuffer)
{
Expand Down Expand Up @@ -147,8 +148,11 @@ class Channel extends EnhancedEventEmitter
}
});

this._socket.on('end', () => this._logger.debug('Channel ended by the worker process'));
this._socket.on('error', (error) => this._logger.error('Channel error: %s', String(error)));
this._consumerSocket.on('end', () => this._logger.debug('Consumer Channel ended by the worker process'));
this._consumerSocket.on('error', (error) => this._logger.error('Consumer Channel error: %s', String(error)));

this._producerSocket.on('end', () => this._logger.debug('Producer Channel ended by the worker process'));
this._producerSocket.on('error', (error) => this._logger.error('Producer Channel error: %s', String(error)));
}

/**
Expand All @@ -171,14 +175,20 @@ class Channel extends EnhancedEventEmitter

// Remove event listeners but leave a fake 'error' hander to avoid
// propagation.
this._socket.removeAllListeners('end');
this._socket.removeAllListeners('error');
this._socket.on('error', () => {});
this._consumerSocket.removeAllListeners('end');
this._consumerSocket.removeAllListeners('error');
this._consumerSocket.on('error', () => {});

this._producerSocket.removeAllListeners('end');
this._producerSocket.removeAllListeners('error');
this._producerSocket.on('error', () => {});

// Destroy the socket after a while to allow pending incoming messages.
setTimeout(() =>
{
try { this._socket.destroy(); }
try { this._producerSocket.destroy(); }
catch (error) {}
try { this._consumerSocket.destroy(); }
catch (error) {}
}, 200);
}
Expand Down Expand Up @@ -206,7 +216,7 @@ class Channel extends EnhancedEventEmitter
throw new Error('Channel request too big');

// This may throw if closed or remote side ended.
this._socket.write(ns);
this._producerSocket.write(ns);

return new Promise((pResolve, pReject) =>
{
Expand Down
10 changes: 6 additions & 4 deletions lib/Worker.js
Original file line number Diff line number Diff line change
Expand Up @@ -90,9 +90,10 @@ class Worker extends EnhancedEventEmitter
* fd 0 (stdin) : Just ignore it.
* fd 1 (stdout) : Pipe it for 3rd libraries that log their own stuff.
* fd 2 (stderr) : Same as stdout.
* fd 3 (channel) : Channel fd.
* fd 3 (channel) : Producer Channel fd.
* fd 4 (channel) : Consumer Channel fd.
*/
stdio : [ 'ignore', 'pipe', 'pipe', 'pipe' ]
stdio : [ 'ignore', 'pipe', 'pipe', 'pipe', 'pipe' ]
});

this._workerLogger = new Logger(`worker[pid:${this._child.pid}]`);
Expand All @@ -105,8 +106,9 @@ class Worker extends EnhancedEventEmitter
// @type {Channel}
this._channel = new Channel(
{
socket : this._child.stdio[3],
pid : this._pid
producerSocket : this._child.stdio[3],
consumerSocket : this._child.stdio[4],
pid : this._pid
});

// Closed flag.
Expand Down
22 changes: 10 additions & 12 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -19,22 +19,19 @@
"sfu",
"nodejs"
],
"os": [
"!win32"
],
"engines": {
"node": ">=8.6.0"
},
"scripts": {
"lint": "npm run lint:node && npm run lint:worker",
"lint:node": "eslint -c .eslintrc.js gulpfile.js lib test",
"lint:worker": "make lint -C worker",
"format:worker": "make format -C worker",
"lint:worker": "gulp lint:worker",
"format:worker": "gulp format:worker",
"test": "npm run test:node && npm run test:worker",
"test:node": "make -C worker && jest",
"test:worker": "make test -C worker",
"coverage:node": "make -C worker && jest --coverage && open-cli coverage/lcov-report/index.html",
"postinstall": "make -C worker"
"test:node": "gulp build && jest",
"test:worker": "gulp test:worker",
"coverage:node": "gulp build && jest --coverage && open-cli coverage/lcov-report/index.html",
"postinstall": "gulp build"
},
"jest": {
"verbose": true,
Expand All @@ -46,13 +43,14 @@
"h264-profile-level-id": "^1.0.0",
"netstring": "^0.3.0",
"random-number": "^0.0.9",
"uuid": "^3.3.2"
"uuid": "^3.3.2",
"gulp": "^4.0.2",
"gulp-clang-format": "^1.0.27",
ibc marked this conversation as resolved.
Show resolved Hide resolved
"gulp-shell": "^0.6.5"
},
"devDependencies": {
"eslint": "^6.1.0",
"eslint-plugin-jest": "^22.13.6",
"gulp": "^4.0.2",
"gulp-clang-format": "^1.0.27",
"jest": "^24.8.0",
"jest-tobetype": "^1.2.3",
"open-cli": "^5.0.0",
Expand Down
4 changes: 4 additions & 0 deletions test/test-Worker.js
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
const os = require('os');
const process = require('process');
const { toBeType } = require('jest-tobetype');
const mediasoup = require('../');
Expand Down Expand Up @@ -194,6 +195,9 @@ test('Worker emits "died" if worker process died unexpectedly', async () =>

test('worker process ignores PIPE, HUP, ALRM, USR1 and USR2 signals', async () =>
{
if (os.platform() === 'win32')
ibc marked this conversation as resolved.
Show resolved Hide resolved
haiyangwu marked this conversation as resolved.
Show resolved Hide resolved
return;

worker = await createWorker({ logLevel: 'warn' });

await new Promise((resolve, reject) =>
Expand Down
Loading