Skip to content
项目
群组
代码片段
帮助
正在加载...
登录
切换导航
M
mediasoup
项目
项目
详情
活动
周期分析
仓库
仓库
文件
提交
分支
标签
贡献者
分枝图
比较
统计图
议题
0
议题
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
CI / CD
CI / CD
流水线
作业
日程
统计图
Wiki
Wiki
代码片段
代码片段
成员
成员
折叠边栏
关闭边栏
活动
分枝图
统计图
创建新议题
作业
提交
议题看板
打开侧边栏
聂卓夫
mediasoup
Commits
98c8253d
提交
98c8253d
authored
12月 22, 2015
作者:
Iñaki Baz Castillo
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
Node: add Server.updateSettings() method.
上级
fbac2062
显示空白字符变更
内嵌
并排
正在显示
9 个修改的文件
包含
147 行增加
和
72 行删除
+147
-72
Server.js
lib/Server.js
+19
-0
Worker.js
lib/Worker.js
+17
-0
Request.h
worker/include/Channel/Request.h
+2
-1
Room.h
worker/include/RTC/Room.h
+6
-2
Settings.h
worker/include/Settings.h
+3
-0
Request.cpp
worker/src/Channel/Request.cpp
+1
-0
Loop.cpp
worker/src/Loop.cpp
+16
-28
Room.cpp
worker/src/RTC/Room.cpp
+54
-41
Settings.cpp
worker/src/Settings.cpp
+29
-0
没有找到文件。
lib/Server.js
浏览文件 @
98c8253d
...
@@ -119,6 +119,25 @@ class Server extends EventEmitter
...
@@ -119,6 +119,25 @@ class Server extends EventEmitter
this
.
emit
(
'close'
,
error
);
this
.
emit
(
'close'
,
error
);
}
}
/**
* Update Server settings
* @param {Object} options Object with modified settings
* @return {Promise}
*/
updateSettings
(
options
)
{
logger
.
debug
(
'updateSettings() [options:%o]'
,
options
);
let
promises
=
[];
this
.
_workers
.
forEach
((
worker
)
=>
{
promises
.
push
(
worker
.
updateSettings
(
options
));
});
return
Promise
.
all
(
promises
);
}
createRoom
(
options
)
createRoom
(
options
)
{
{
logger
.
debug
(
'createRoom() [options:%o]'
,
options
);
logger
.
debug
(
'createRoom() [options:%o]'
,
options
);
...
...
lib/Worker.js
浏览文件 @
98c8253d
...
@@ -129,6 +129,23 @@ class Worker extends EventEmitter
...
@@ -129,6 +129,23 @@ class Worker extends EventEmitter
this
.
emit
(
'close'
,
error
);
this
.
emit
(
'close'
,
error
);
}
}
updateSettings
(
options
)
{
logger
.
debug
(
'updateSettings() [options:%o]'
,
options
);
return
this
.
_channel
.
request
(
'updateSettings'
,
options
)
.
then
(()
=>
{
logger
.
debug
(
'"updateSettings" request succeeded'
);
})
.
catch
((
error
)
=>
{
logger
.
error
(
'"updateSettings" request failed [status:%s, error:"%s"]'
,
error
.
status
,
error
.
message
);
throw
error
;
});
}
createRoom
(
options
)
createRoom
(
options
)
{
{
logger
.
debug
(
'createRoom() [options:%o]'
,
options
);
logger
.
debug
(
'createRoom() [options:%o]'
,
options
);
...
...
worker/include/Channel/Request.h
浏览文件 @
98c8253d
...
@@ -16,7 +16,8 @@ namespace Channel
...
@@ -16,7 +16,8 @@ namespace Channel
public
:
public
:
enum
class
MethodId
enum
class
MethodId
{
{
createRoom
=
1
,
updateSettings
=
1
,
createRoom
,
createPeer
createPeer
};
};
...
...
worker/include/RTC/Room.h
浏览文件 @
98c8253d
...
@@ -4,12 +4,16 @@
...
@@ -4,12 +4,16 @@
#include "RTC/Peer.h"
#include "RTC/Peer.h"
#include "RTC/RTPPacket.h"
#include "RTC/RTPPacket.h"
#include "RTC/RTCPPacket.h"
#include "RTC/RTCPPacket.h"
#include <vector>
#include <unordered_map>
#include <json/json.h>
namespace
RTC
namespace
RTC
{
{
class
Room
:
public
RTC
::
Peer
::
Listener
class
Room
:
public
RTC
::
Peer
::
Listener
{
{
public
:
static
RTC
::
Room
*
Factory
(
Json
::
Value
&
data
);
public
:
public
:
Room
();
Room
();
virtual
~
Room
();
virtual
~
Room
();
...
@@ -23,7 +27,7 @@ namespace RTC
...
@@ -23,7 +27,7 @@ namespace RTC
private
:
private
:
// Others.
// Others.
typedef
std
::
vector
<
RTC
::
Peer
*>
Peers
;
typedef
std
::
unordered_map
<
unsigned
int
,
RTC
::
Peer
*>
Peers
;
Peers
peers
;
Peers
peers
;
};
};
}
}
...
...
worker/include/Settings.h
浏览文件 @
98c8253d
...
@@ -2,9 +2,11 @@
...
@@ -2,9 +2,11 @@
#define MS_SETTINGS_H
#define MS_SETTINGS_H
#include "common.h"
#include "common.h"
#include "Channel/Request.h"
#include <map>
#include <map>
#include <string>
#include <string>
class
Settings
class
Settings
{
{
public
:
public
:
...
@@ -26,6 +28,7 @@ public:
...
@@ -26,6 +28,7 @@ public:
public
:
public
:
static
void
SetConfiguration
(
int
argc
,
char
*
argv
[]);
static
void
SetConfiguration
(
int
argc
,
char
*
argv
[]);
static
void
PrintConfiguration
();
static
void
PrintConfiguration
();
static
void
HandleUpdateRequest
(
Channel
::
Request
*
request
);
private
:
private
:
static
void
SetDefaultRtcListenIP
(
int
requested_family
);
static
void
SetDefaultRtcListenIP
(
int
requested_family
);
...
...
worker/src/Channel/Request.cpp
浏览文件 @
98c8253d
...
@@ -13,6 +13,7 @@ namespace Channel
...
@@ -13,6 +13,7 @@ namespace Channel
std
::
unordered_map
<
std
::
string
,
Request
::
MethodId
>
Request
::
string2MethodId
=
std
::
unordered_map
<
std
::
string
,
Request
::
MethodId
>
Request
::
string2MethodId
=
{
{
{
"updateSettings"
,
Request
::
MethodId
::
updateSettings
},
{
"createRoom"
,
Request
::
MethodId
::
createRoom
},
{
"createRoom"
,
Request
::
MethodId
::
createRoom
},
{
"createPeer"
,
Request
::
MethodId
::
createPeer
}
{
"createPeer"
,
Request
::
MethodId
::
createPeer
}
};
};
...
...
worker/src/Loop.cpp
浏览文件 @
98c8253d
...
@@ -2,6 +2,7 @@
...
@@ -2,6 +2,7 @@
#include "Loop.h"
#include "Loop.h"
#include "DepLibUV.h"
#include "DepLibUV.h"
#include "Settings.h"
#include "MediaSoupError.h"
#include "MediaSoupError.h"
#include "Logger.h"
#include "Logger.h"
#include <string>
#include <string>
...
@@ -104,50 +105,37 @@ void Loop::onChannelRequest(Channel::UnixStreamSocket* channel, Channel::Request
...
@@ -104,50 +105,37 @@ void Loop::onChannelRequest(Channel::UnixStreamSocket* channel, Channel::Request
switch
(
request
->
methodId
)
switch
(
request
->
methodId
)
{
{
case
Channel
:
:
Request
::
MethodId
::
createRoom
:
case
Channel
:
:
Request
::
MethodId
::
updateSettings
:
{
{
MS_DEBUG
(
"'createRoom' method"
);
MS_DEBUG
(
"'updateSettings' method"
);
break
;
}
case
Channel
:
:
Request
::
MethodId
::
createPeer
:
Settings
::
HandleUpdateRequest
(
request
);
{
MS_DEBUG
(
"'createPeer' method"
);
break
;
break
;
}
}
default
:
case
Channel
:
:
Request
::
MethodId
::
createRoom
:
{
{
MS_ABORT
(
"unexpected methodId"
);
MS_DEBUG
(
"'createRoom' method"
);
}
}
// TODO: TMP jeje
if
(
request
->
id
<
25000
)
{
request
->
Accept
();
}
else
if
(
request
->
id
<
50000
)
{
Json
::
Value
data
;
Json
::
Value
data
;
data
[
"jojojo"
]
=
"🐮🐷🐣😡"
;
data
[
"jojojo"
]
=
"🐮🐷🐣😡"
;
request
->
Accept
(
data
);
request
->
Accept
(
data
);
break
;
}
}
else
if
(
request
->
id
<
75000
)
case
Channel
:
:
Request
::
MethodId
::
createPeer
:
{
{
std
::
string
reason
=
"this is a std::string reason"
;
MS_DEBUG
(
"'createPeer' method"
)
;
request
->
Reject
(
400
,
reason
);
request
->
Reject
(
500
,
"lalalala failed to create a Peer because yes!"
);
break
;
}
}
else
default
:
{
{
request
->
Reject
(
500
,
"this is a char* reason"
);
MS_ABORT
(
"unexpected methodId"
);
}
}
}
}
}
...
...
worker/src/RTC/Room.cpp
浏览文件 @
98c8253d
...
@@ -13,6 +13,15 @@
...
@@ -13,6 +13,15 @@
namespace
RTC
namespace
RTC
{
{
/* Class methods. */
RTC
::
Room
*
Room
::
Factory
(
Json
::
Value
&
data
)
{
MS_TRACE
();
return
new
Room
();
}
/* Instance methods. */
/* Instance methods. */
Room
::
Room
()
Room
::
Room
()
...
@@ -42,8 +51,12 @@ namespace RTC
...
@@ -42,8 +51,12 @@ namespace RTC
MS_TRACE
();
MS_TRACE
();
// Close all the Peers.
// Close all the Peers.
for
(
auto
peer
:
this
->
peers
)
for
(
auto
&
kv
:
this
->
peers
)
{
RTC
::
Peer
*
peer
=
kv
.
second
;
peer
->
Close
();
peer
->
Close
();
}
delete
this
;
delete
this
;
}
}
...
@@ -52,54 +65,54 @@ namespace RTC
...
@@ -52,54 +65,54 @@ namespace RTC
{
{
MS_TRACE
();
MS_TRACE
();
int
peer_id
=
*
(
int
*
)
peer
->
GetUserData
();
//
int peer_id = *(int*)peer->GetUserData();
MS_BYTE
payload_type
=
packet
->
GetPayloadType
();
//
MS_BYTE payload_type = packet->GetPayloadType();
MS_4BYTES
original_ssrc
=
packet
->
GetSSRC
();
//
MS_4BYTES original_ssrc = packet->GetSSRC();
MS_DEBUG
(
"valid RTP packet received from Peer %d [ssrc: %llu | payload: %hu]"
,
//
MS_DEBUG("valid RTP packet received from Peer %d [ssrc: %llu | payload: %hu]",
peer_id
,
(
unsigned
long
long
)
packet
->
GetSSRC
(),
(
unsigned
short
)
packet
->
GetPayloadType
());
//
peer_id, (unsigned long long)packet->GetSSRC(), (unsigned short)packet->GetPayloadType());
switch
(
payload_type
)
//
switch (payload_type)
{
//
{
case
PAYLOAD_TYPE_AUDIO
:
//
case PAYLOAD_TYPE_AUDIO:
case
PAYLOAD_TYPE_VIDEO
:
//
case PAYLOAD_TYPE_VIDEO:
break
;
//
break;
default
:
//
default:
MS_ERROR
(
"payload is not OPUS %d nor VP8 %d, packet ignored"
,
PAYLOAD_TYPE_AUDIO
,
PAYLOAD_TYPE_VIDEO
);
//
MS_ERROR("payload is not OPUS %d nor VP8 %d, packet ignored", PAYLOAD_TYPE_AUDIO, PAYLOAD_TYPE_VIDEO);
return
;
//
return;
}
//
}
// Deliver to all the peers.
//
//
Deliver to all the peers.
// TODO: but this one? yes (TODO)
//
//
TODO: but this one? yes (TODO)
for
(
auto
dst_peer
:
this
->
peers
)
//
for (auto dst_peer : this->peers)
{
//
{
// if (dst_peer == peer)
//
// if (dst_peer == peer)
// continue;
//
// continue;
int
dst_peer_id
=
*
(
int
*
)
dst_peer
->
GetUserData
();
//
int dst_peer_id = *(int*)dst_peer->GetUserData();
switch
(
payload_type
)
//
switch (payload_type)
{
//
{
case
PAYLOAD_TYPE_AUDIO
:
//
case PAYLOAD_TYPE_AUDIO:
packet
->
SetSSRC
((
MS_4BYTES
)(
SSRC_AUDIO_BASE
+
(
peer_id
*
10
)
+
dst_peer_id
));
//
packet->SetSSRC((MS_4BYTES)(SSRC_AUDIO_BASE + (peer_id * 10) + dst_peer_id));
break
;
//
break;
case
PAYLOAD_TYPE_VIDEO
:
//
case PAYLOAD_TYPE_VIDEO:
packet
->
SetSSRC
((
MS_4BYTES
)(
SSRC_VIDEO_BASE
+
(
peer_id
*
10
)
+
dst_peer_id
));
//
packet->SetSSRC((MS_4BYTES)(SSRC_VIDEO_BASE + (peer_id * 10) + dst_peer_id));
break
;
//
break;
default
:
//
default:
MS_ABORT
(
"no puede ser!!!"
);
//
MS_ABORT("no puede ser!!!");
return
;
//
return;
}
//
}
MS_DEBUG
(
"sending RTP packet to Peer %d [ssrc: %llu | payload: %hu | size: %zu]"
,
//
MS_DEBUG("sending RTP packet to Peer %d [ssrc: %llu | payload: %hu | size: %zu]",
dst_peer_id
,
(
unsigned
long
long
)
packet
->
GetSSRC
(),
(
unsigned
short
)
packet
->
GetPayloadType
(),
packet
->
GetLength
());
//
dst_peer_id, (unsigned long long)packet->GetSSRC(), (unsigned short)packet->GetPayloadType(), packet->GetLength());
dst_peer
->
SendRTPPacket
(
packet
);
//
dst_peer->SendRTPPacket(packet);
// NOTE: recover the previous SSRC since other peers are going to
//
// NOTE: recover the previous SSRC since other peers are going to
// send this same RTPPacket!
//
// send this same RTPPacket!
packet
->
SetSSRC
(
original_ssrc
);
//
packet->SetSSRC(original_ssrc);
}
//
}
}
}
void
Room
::
onRTCPPacket
(
RTC
::
Peer
*
peer
,
RTC
::
RTCPPacket
*
packet
)
void
Room
::
onRTCPPacket
(
RTC
::
Peer
*
peer
,
RTC
::
RTCPPacket
*
packet
)
...
...
worker/src/Settings.cpp
浏览文件 @
98c8253d
...
@@ -167,6 +167,35 @@ void Settings::PrintConfiguration()
...
@@ -167,6 +167,35 @@ void Settings::PrintConfiguration()
MS_DEBUG
(
"[/configuration]"
);
MS_DEBUG
(
"[/configuration]"
);
}
}
void
Settings
::
HandleUpdateRequest
(
Channel
::
Request
*
request
)
{
MS_TRACE
();
try
{
// Update logLevel if requested.
if
(
request
->
data
[
"logLevel"
].
isString
())
{
std
::
string
logLevel
=
request
->
data
[
"logLevel"
].
asString
();
Settings
::
SetLogLevel
(
logLevel
);
}
}
catch
(
const
MediaSoupError
&
error
)
{
request
->
Reject
(
500
,
error
.
what
());
return
;
}
MS_DEBUG
(
"updated settings:"
);
// Print configuration.
Settings
::
PrintConfiguration
();
request
->
Accept
();
}
void
Settings
::
SetDefaultRtcListenIP
(
int
requested_family
)
void
Settings
::
SetDefaultRtcListenIP
(
int
requested_family
)
{
{
MS_TRACE
();
MS_TRACE
();
...
...
编写
预览
Markdown
格式
0%
重试
或
添加新文件
添加附件
取消
您添加了
0
人
到此讨论。请谨慎行事。
请先完成此评论的编辑!
取消
请
注册
或者
登录
后发表评论