Skip to content
项目
群组
代码片段
帮助
正在加载...
登录
切换导航
M
mediasoup
项目
项目
详情
活动
周期分析
仓库
仓库
文件
提交
分支
标签
贡献者
分枝图
比较
统计图
议题
0
议题
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
CI / CD
CI / CD
流水线
作业
日程
统计图
Wiki
Wiki
代码片段
代码片段
成员
成员
折叠边栏
关闭边栏
活动
分枝图
统计图
创建新议题
作业
提交
议题看板
打开侧边栏
聂卓夫
mediasoup
Commits
70320b06
提交
70320b06
authored
12月 13, 2015
作者:
Iñaki Baz Castillo
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
jsoncpp vs picojson
上级
6d71f5f5
隐藏空白字符变更
内嵌
并排
正在显示
6 个修改的文件
包含
83 行增加
和
17 行删除
+83
-17
.gitignore
.gitignore
+1
-1
.gitmodules
.gitmodules
+3
-0
Server.js
lib/Server.js
+19
-10
Worker.js
lib/Worker.js
+5
-5
Makefile
worker/Makefile
+1
-0
UnixStreamSocket.cpp
worker/src/Control/UnixStreamSocket.cpp
+54
-1
没有找到文件。
.gitignore
浏览文件 @
70320b06
/node_modules/
/worker/submodules/
/worker/**/*.o
/worker/submodules/
/worker/bin/
/worker/cldoc/
/worker/mediasoup-tester.sh
...
...
.gitmodules
浏览文件 @
70320b06
...
...
@@ -4,3 +4,6 @@
[submodule "worker/submodules/jsoncpp"]
path = worker/submodules/jsoncpp
url = https://github.com/open-source-parsers/jsoncpp.git
[submodule "worker/submodules/picojson"]
path = worker/submodules/picojson
url = https://github.com/eluck/picojson.git
lib/Server.js
浏览文件 @
70320b06
...
...
@@ -7,6 +7,7 @@ debugerror.log = console.error.bind(console);
const
process
=
require
(
'process'
);
const
os
=
require
(
'os'
);
const
path
=
require
(
'path'
);
const
check
=
require
(
'check-types'
);
const
randomString
=
require
(
'random-string'
);
...
...
@@ -22,6 +23,7 @@ const VALID_PARAMETERS =
// Set of Server instances
var
servers
=
new
Set
();
// On process exit close all the Servers
process
.
on
(
'exit'
,
()
=>
{
for
(
let
server
of
servers
)
...
...
@@ -42,15 +44,25 @@ class Server
options
=
options
||
{};
// Map of Worker instances
this
.
_workers
=
new
Map
();
if
(
check
.
integer
(
options
.
numWorkers
)
&&
check
.
positive
(
options
.
numWorkers
))
{
numWorkers
=
options
.
numWorkers
;
}
// Map of Worker instances
this
.
_workers
=
new
Map
();
if
(
check
.
nonEmptyString
(
options
.
dtlsCertificateFile
))
{
options
.
dtlsCertificateFile
=
path
.
resolve
(
options
.
dtlsCertificateFile
);
}
// Add the server to the set
if
(
check
.
nonEmptyString
(
options
.
dtlsPrivateKeyFile
))
{
options
.
dtlsPrivateKeyFile
=
path
.
resolve
(
options
.
dtlsPrivateKeyFile
);
}
// Add this Server to the Set
servers
.
add
(
this
);
for
(
let
key
of
Object
.
keys
(
options
))
...
...
@@ -63,13 +75,12 @@ class Server
debug
(
'constructor() [worker parameters:"%s"]'
,
parameters
.
join
(
' '
));
// Create
mediasoup-worker child process
es
// Create
Worker instanc
es
for
(
let
i
=
1
;
i
<=
numWorkers
;
i
++
)
{
let
worker
;
let
workerId
=
serverId
+
'#'
+
i
;
// Create a Worker instance
worker
=
new
Worker
(
workerId
,
parameters
);
worker
.
on
(
'exit'
,
()
=>
...
...
@@ -82,7 +93,7 @@ class Server
this
.
_workers
.
delete
(
workerId
);
});
// Add the
worker to the m
ap
// Add the
Worker to the M
ap
this
.
_workers
.
set
(
workerId
,
worker
);
}
}
...
...
@@ -91,16 +102,14 @@ class Server
{
debug
(
'close()'
);
// Remove this
server from the s
et
// Remove this
Server from the S
et
servers
.
delete
(
this
);
// Close every
w
orker
// Close every
W
orker
for
(
let
worker
of
this
.
_workers
.
values
())
{
worker
.
close
();
}
// Clear the workers map
this
.
_workers
.
clear
();
}
}
...
...
lib/Worker.js
浏览文件 @
70320b06
...
...
@@ -12,7 +12,7 @@ const EventEmitter = require('events').EventEmitter;
const
WORKER_BIN_PATH
=
path
.
join
(
__dirname
,
'..'
,
'worker'
,
'bin'
,
'mediasoup-worker'
);
// Set an env variable to tell
worker
s which the Control FD is
// Set an env variable to tell
child
s which the Control FD is
process
.
env
.
MEDIASOUP_CONTROL_FD
=
'3'
;
class
Worker
extends
EventEmitter
...
...
@@ -30,7 +30,7 @@ class Worker extends EventEmitter
stdio
:
[
'pipe'
,
'pipe'
,
'pipe'
,
'pipe'
]
};
// Create the worker child process
// Create the
mediasoup-
worker child process
this
.
_child
=
spawn
(
WORKER_BIN_PATH
,
spawnArgs
,
spawnOptions
);
// TODO: TMP
...
...
@@ -60,14 +60,14 @@ class Worker extends EventEmitter
this
.
_child
.
on
(
'exit'
,
(
code
,
signal
)
=>
{
debug
(
'
worker
process closed [id:%s, code:%s, signal:%s]'
,
id
,
code
,
signal
);
debug
(
'
child
process closed [id:%s, code:%s, signal:%s]'
,
id
,
code
,
signal
);
this
.
emit
(
'exit'
,
code
,
signal
);
});
this
.
_child
.
on
(
'error'
,
(
error
)
=>
{
debugerror
(
'
worker
process error [id:%s]: %s'
,
id
,
error
);
debugerror
(
'
child
process error [id:%s]: %s'
,
id
,
error
);
this
.
emit
(
'error'
,
error
);
});
...
...
@@ -77,7 +77,7 @@ class Worker extends EventEmitter
{
debug
(
'close()'
);
// Kill
worker
child
// Kill child
this
.
_child
.
kill
(
'SIGTERM'
);
}
}
...
...
worker/Makefile
浏览文件 @
70320b06
...
...
@@ -57,6 +57,7 @@ DEP_SOURCES += ./submodules/jsoncpp/dist/jsoncpp.cpp
DEP_HEADERS_DIRS
:=
DEP_HEADERS_DIRS
+=
./submodules/jsoncpp/dist
DEP_HEADERS_DIRS
+=
./submodules/usrsctp/usrsctplib
DEP_HEADERS_DIRS
+=
./submodules/picojson
# Dependencies static libraries to link with.
DEP_LIBS
:=
...
...
worker/src/Control/UnixStreamSocket.cpp
浏览文件 @
70320b06
...
...
@@ -2,6 +2,8 @@
#include "Control/UnixStreamSocket.h"
#include "Logger.h"
#include <json/json.h>
#include <picojson.h>
#define MESSAGE_MAX_SIZE 65536 // TODO: set proper buffer size
...
...
@@ -27,9 +29,60 @@ namespace Control
std
::
string
kk
((
const
char
*
)
data
,
len
);
MS_WARN
(
"---------- readed
kk
: %s"
,
kk
.
c_str
());
MS_WARN
(
"---------- readed
data
: %s"
,
kk
.
c_str
());
this
->
bufferDataLen
=
0
;
Json
::
Value
json
;
Json
::
Reader
reader
;
if
(
reader
.
parse
((
const
char
*
)
data
,
(
const
char
*
)
data
+
len
,
json
))
{
MS_DEBUG
(
"jsoncpp: IT IS VALID JSON:
\n
%s"
,
json
.
toStyledString
().
c_str
());
MS_DEBUG
(
"jsoncpp: method : %s"
,
json
[
"method"
].
asCString
());
MS_DEBUG
(
"jsoncpp: room.id : %d"
,
json
[
"room"
][
"id"
].
asInt
());
MS_DEBUG
(
"jsoncpp: room.closed : %s"
,
json
[
"room"
][
"closed"
].
asBool
()
?
"true"
:
"false"
);
if
(
json
[
"method"
].
isString
())
MS_DEBUG
(
"jsoncpp: method is a string"
);
if
(
!
json
.
isMember
(
"kk"
))
MS_DEBUG
(
"jsoncpp: kk is not member"
);
if
(
json
[
"parent"
][
"foo"
][
"bar"
].
isNull
())
MS_DEBUG
(
"jsoncpp: parent.foo.bar is null"
);
}
else
{
MS_ERROR
(
"jsoncpp: INVALID JSON !!!!"
);
}
picojson
::
value
v
;
std
::
string
err
;
picojson
::
parse
(
v
,
(
const
char
*
)
data
,
(
const
char
*
)
data
+
len
,
&
err
);
if
(
!
err
.
empty
())
{
MS_ERROR
(
"picojson: INVALID JSON: %s"
,
err
.
c_str
());
}
MS_DEBUG
(
"picojson: IT IS VALID JSON:
\n
%s"
,
v
.
serialize
().
c_str
());
MS_DEBUG
(
"picojson: method : %s"
,
v
.
get
(
"method"
).
get
<
std
::
string
>
().
c_str
());
MS_DEBUG
(
"picojson: room.id : %d"
,
(
int
)
v
.
get
(
"room"
).
get
(
"id"
).
get
<
double
>
());
MS_DEBUG
(
"picojson: room.closed : %s"
,
v
.
get
(
"room"
).
get
(
"closed"
).
get
<
bool
>
()
?
"true"
:
"false"
);
if
(
v
.
get
(
"method"
).
is
<
std
::
string
>
())
MS_DEBUG
(
"picojson: method is a string"
);
if
(
v
.
get
(
"kk"
).
is
<
picojson
::
null
>
())
MS_DEBUG
(
"picojson: kk is null"
);
// ESTO CASCA: ganador: jsoncpp
if
(
v
.
get
(
"parent"
).
get
(
"foo"
).
get
(
"bar"
).
is
<
picojson
::
null
>
())
MS_DEBUG
(
"picojson: parent.foo.bar is null"
);
}
void
UnixStreamSocket
::
userOnUnixStreamSocketClosed
(
bool
is_closed_by_peer
)
...
...
编写
预览
Markdown
格式
0%
重试
或
添加新文件
添加附件
取消
您添加了
0
人
到此讨论。请谨慎行事。
请先完成此评论的编辑!
取消
请
注册
或者
登录
后发表评论