Skip to content
项目
群组
代码片段
帮助
正在加载...
登录
切换导航
M
mediasoup
项目
项目
详情
活动
周期分析
仓库
仓库
文件
提交
分支
标签
贡献者
分枝图
比较
统计图
议题
0
议题
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
CI / CD
CI / CD
流水线
作业
日程
统计图
Wiki
Wiki
代码片段
代码片段
成员
成员
折叠边栏
关闭边栏
活动
分枝图
统计图
创建新议题
作业
提交
议题看板
打开侧边栏
聂卓夫
mediasoup
Commits
f8a36121
提交
f8a36121
authored
12月 13, 2015
作者:
Iñaki Baz Castillo
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
- Remove picojson
- Server._getRandomWorker()
上级
70320b06
显示空白字符变更
内嵌
并排
正在显示
5 个修改的文件
包含
60 行增加
和
57 行删除
+60
-57
.gitmodules
.gitmodules
+0
-3
.jshintrc
.jshintrc
+1
-1
Server.js
lib/Server.js
+19
-0
Worker.js
lib/Worker.js
+30
-17
UnixStreamSocket.cpp
worker/src/Control/UnixStreamSocket.cpp
+10
-36
没有找到文件。
.gitmodules
浏览文件 @
f8a36121
...
@@ -4,6 +4,3 @@
...
@@ -4,6 +4,3 @@
[submodule "worker/submodules/jsoncpp"]
[submodule "worker/submodules/jsoncpp"]
path = worker/submodules/jsoncpp
path = worker/submodules/jsoncpp
url = https://github.com/open-source-parsers/jsoncpp.git
url = https://github.com/open-source-parsers/jsoncpp.git
[submodule "worker/submodules/picojson"]
path = worker/submodules/picojson
url = https://github.com/eluck/picojson.git
.jshintrc
浏览文件 @
f8a36121
{
{
"esnext": true,
"esnext": true,
"bitwise":
tru
e,
"bitwise":
fals
e,
"curly": true,
"curly": true,
"eqeqeq": true,
"eqeqeq": true,
"forin": false,
"forin": false,
...
...
lib/Server.js
浏览文件 @
f8a36121
...
@@ -47,6 +47,9 @@ class Server
...
@@ -47,6 +47,9 @@ class Server
// Map of Worker instances
// Map of Worker instances
this
.
_workers
=
new
Map
();
this
.
_workers
=
new
Map
();
// Map of Room instances
this
.
_rooms
=
new
Map
();
if
(
check
.
integer
(
options
.
numWorkers
)
&&
check
.
positive
(
options
.
numWorkers
))
if
(
check
.
integer
(
options
.
numWorkers
)
&&
check
.
positive
(
options
.
numWorkers
))
{
{
numWorkers
=
options
.
numWorkers
;
numWorkers
=
options
.
numWorkers
;
...
@@ -112,6 +115,22 @@ class Server
...
@@ -112,6 +115,22 @@ class Server
}
}
this
.
_workers
.
clear
();
this
.
_workers
.
clear
();
}
}
createRoom
(
options
)
{
debug
(
'createRoom()'
);
let
worker
=
this
.
_getRandomWorker
();
return
worker
.
createRoom
(
options
);
}
_getRandomWorker
()
{
let
workerIds
=
Array
.
from
(
this
.
_workers
.
keys
());
return
this
.
_workers
.
get
(
workerIds
[
workerIds
.
length
*
Math
.
random
()
<<
0
]);
}
}
}
module
.
exports
=
Server
;
module
.
exports
=
Server
;
lib/Worker.js
浏览文件 @
f8a36121
...
@@ -9,11 +9,13 @@ const path = require('path');
...
@@ -9,11 +9,13 @@ const path = require('path');
const
spawn
=
require
(
'child_process'
).
spawn
;
const
spawn
=
require
(
'child_process'
).
spawn
;
const
process
=
require
(
'process'
);
const
process
=
require
(
'process'
);
const
EventEmitter
=
require
(
'events'
).
EventEmitter
;
const
EventEmitter
=
require
(
'events'
).
EventEmitter
;
const
randomString
=
require
(
'random-string'
);
const
WORKER_BIN_PATH
=
path
.
join
(
__dirname
,
'..'
,
'worker'
,
'bin'
,
'mediasoup-worker'
);
const
WORKER_BIN_PATH
=
path
.
join
(
__dirname
,
'..'
,
'worker'
,
'bin'
,
'mediasoup-worker'
);
const
CONTROL_FD
=
3
;
// Set an env variable to tell childs which the Control FD is
// Set an env variable to tell childs which the Control FD is
process
.
env
.
MEDIASOUP_CONTROL_FD
=
'3'
;
process
.
env
.
MEDIASOUP_CONTROL_FD
=
String
(
CONTROL_FD
)
;
class
Worker
extends
EventEmitter
class
Worker
extends
EventEmitter
{
{
...
@@ -21,6 +23,9 @@ class Worker extends EventEmitter
...
@@ -21,6 +23,9 @@ class Worker extends EventEmitter
{
{
super
();
super
();
// TODO: TMP
this
.
id
=
id
;
debug
(
'constructor() [id:%s]'
,
id
);
debug
(
'constructor() [id:%s]'
,
id
);
let
spawnArgs
=
[
id
].
concat
(
parameters
);
let
spawnArgs
=
[
id
].
concat
(
parameters
);
...
@@ -33,29 +38,19 @@ class Worker extends EventEmitter
...
@@ -33,29 +38,19 @@ class Worker extends EventEmitter
// Create the mediasoup-worker child process
// Create the mediasoup-worker child process
this
.
_child
=
spawn
(
WORKER_BIN_PATH
,
spawnArgs
,
spawnOptions
);
this
.
_child
=
spawn
(
WORKER_BIN_PATH
,
spawnArgs
,
spawnOptions
);
// TODO: TMP
// Control unix socket
global
.
p
=
this
.
_child
.
stdio
[
3
];
this
.
_control
=
this
.
_child
.
stdio
[
CONTROL_FD
];
// Set child process events
this
.
_child
.
stdout
.
on
(
'data'
,
(
buffer
)
=>
this
.
_child
.
stdout
.
on
(
'data'
,
(
buffer
)
=>
{
{
buffer
.
toString
(
'utf8'
).
split
(
'
\
n'
).
forEach
((
line
)
=>
buffer
.
toString
(
'utf8'
).
split
(
'
\
n'
).
forEach
((
line
)
=>
line
&&
debug
(
line
));
{
if
(
line
)
{
debug
(
line
);
}
});
});
});
this
.
_child
.
stderr
.
on
(
'data'
,
(
buffer
)
=>
this
.
_child
.
stderr
.
on
(
'data'
,
(
buffer
)
=>
{
{
buffer
.
toString
(
'utf8'
).
split
(
'
\
n'
).
forEach
((
line
)
=>
buffer
.
toString
(
'utf8'
).
split
(
'
\
n'
).
forEach
((
line
)
=>
line
&&
debugerror
(
line
));
{
if
(
line
)
{
debugerror
(
line
);
}
});
});
});
this
.
_child
.
on
(
'exit'
,
(
code
,
signal
)
=>
this
.
_child
.
on
(
'exit'
,
(
code
,
signal
)
=>
...
@@ -80,6 +75,24 @@ class Worker extends EventEmitter
...
@@ -80,6 +75,24 @@ class Worker extends EventEmitter
// Kill child
// Kill child
this
.
_child
.
kill
(
'SIGTERM'
);
this
.
_child
.
kill
(
'SIGTERM'
);
}
}
createRoom
()
{
debug
(
'createRoom()'
);
let
roomId
=
randomString
({
numeric
:
false
,
length
:
8
}).
toLowerCase
();
let
req
=
{
type
:
'request'
,
method
:
'createRoom'
,
room
:
{
id
:
roomId
}
};
this
.
_control
.
write
(
JSON
.
stringify
(
req
));
}
}
}
module
.
exports
=
Worker
;
module
.
exports
=
Worker
;
worker/src/Control/UnixStreamSocket.cpp
浏览文件 @
f8a36121
...
@@ -3,7 +3,6 @@
...
@@ -3,7 +3,6 @@
#include "Control/UnixStreamSocket.h"
#include "Control/UnixStreamSocket.h"
#include "Logger.h"
#include "Logger.h"
#include <json/json.h>
#include <json/json.h>
#include <picojson.h>
#define MESSAGE_MAX_SIZE 65536 // TODO: set proper buffer size
#define MESSAGE_MAX_SIZE 65536 // TODO: set proper buffer size
...
@@ -39,50 +38,25 @@ namespace Control
...
@@ -39,50 +38,25 @@ namespace Control
if
(
reader
.
parse
((
const
char
*
)
data
,
(
const
char
*
)
data
+
len
,
json
))
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_
INFO
(
"jsoncpp: IT IS VALID JSON:
\n\n
%s
\n
"
,
json
.
toStyledString
().
c_str
());
MS_DEBUG
(
"jsoncpp: method : %s"
,
json
[
"method"
].
asCString
());
//
MS_DEBUG("jsoncpp: method : %s", json["method"].asCString());
MS_DEBUG
(
"jsoncpp: room.id : %d"
,
json
[
"room"
][
"id"
].
asInt
());
//
MS_DEBUG("jsoncpp: room.id : %d", json["room"]["id"].asInt());
MS_DEBUG
(
"jsoncpp: room.closed : %s"
,
json
[
"room"
][
"closed"
].
asBool
()
?
"true"
:
"false"
);
//
MS_DEBUG("jsoncpp: room.closed : %s", json["room"]["closed"].asBool() ? "true" : "false");
if
(
json
[
"method"
].
isString
())
//
if (json["method"].isString())
MS_DEBUG
(
"jsoncpp: method is a string"
);
//
MS_DEBUG("jsoncpp: method is a string");
if
(
!
json
.
isMember
(
"kk"
))
//
if (!json.isMember("kk"))
MS_DEBUG
(
"jsoncpp: kk is not member"
);
//
MS_DEBUG("jsoncpp: kk is not member");
if
(
json
[
"parent"
][
"foo"
][
"bar"
].
isNull
())
//
if (json["parent"]["foo"]["bar"].isNull())
MS_DEBUG
(
"jsoncpp: parent.foo.bar is null"
);
//
MS_DEBUG("jsoncpp: parent.foo.bar is null");
}
}
else
else
{
{
MS_ERROR
(
"jsoncpp: INVALID JSON !!!!"
);
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
)
void
UnixStreamSocket
::
userOnUnixStreamSocketClosed
(
bool
is_closed_by_peer
)
...
...
编写
预览
Markdown
格式
0%
重试
或
添加新文件
添加附件
取消
您添加了
0
人
到此讨论。请谨慎行事。
请先完成此评论的编辑!
取消
请
注册
或者
登录
后发表评论