Skip to content
项目
群组
代码片段
帮助
正在加载...
登录
切换导航
M
mediasoup
项目
项目
详情
活动
周期分析
仓库
仓库
文件
提交
分支
标签
贡献者
分枝图
比较
统计图
议题
0
议题
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
CI / CD
CI / CD
流水线
作业
日程
统计图
Wiki
Wiki
代码片段
代码片段
成员
成员
折叠边栏
关闭边栏
活动
分枝图
统计图
创建新议题
作业
提交
议题看板
打开侧边栏
聂卓夫
mediasoup
Commits
749ce475
提交
749ce475
authored
1月 06, 2016
作者:
Iñaki Baz Castillo
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
Starting Notifications (events) from worker processes to Node process.
上级
d786c5c4
显示空白字符变更
内嵌
并排
正在显示
6 个修改的文件
包含
116 行增加
和
1 行删除
+116
-1
Channel.js
lib/Channel.js
+13
-1
Room.js
lib/Room.js
+6
-0
Notifier.h
worker/include/Channel/Notifier.h
+27
-0
Loop.h
worker/include/Loop.h
+2
-0
Notifier.cpp
worker/src/Channel/Notifier.cpp
+59
-0
Loop.cpp
worker/src/Loop.cpp
+9
-0
没有找到文件。
lib/Channel.js
浏览文件 @
749ce475
...
@@ -20,6 +20,7 @@ class Channel extends EventEmitter
...
@@ -20,6 +20,7 @@ class Channel extends EventEmitter
logger
.
debug
(
'constructor()'
);
logger
.
debug
(
'constructor()'
);
super
();
super
();
this
.
setMaxListeners
(
Infinity
);
// Unix Socket instance
// Unix Socket instance
this
.
_socket
=
socket
;
this
.
_socket
=
socket
;
...
@@ -258,9 +259,20 @@ class Channel extends EventEmitter
...
@@ -258,9 +259,20 @@ class Channel extends EventEmitter
}
}
}
}
// If a Notification emit it to the corresponding entity
// If a Notification emit it to the corresponding entity
else
if
(
json
.
targetId
&&
json
.
eventName
)
{
let
targetId
=
json
.
targetId
;
let
eventName
=
json
.
eventName
;
logger
.
debug
(
'received Notification [targetId:%s, eventName:%s]'
,
targetId
,
eventName
);
// Emit it
this
.
emit
(
targetId
,
eventName
,
json
.
eventData
);
}
// Otherwise unexpected message
else
else
{
{
// TODO
logger
.
error
(
'received message is not a Response nor a Notification'
);
}
}
}
}
}
}
...
...
lib/Room.js
浏览文件 @
749ce475
...
@@ -27,6 +27,10 @@ class Room extends EventEmitter
...
@@ -27,6 +27,10 @@ class Room extends EventEmitter
this
.
_closed
=
false
;
this
.
_closed
=
false
;
// TODO: subscribe to channel notifications from the worker
// TODO: subscribe to channel notifications from the worker
this
.
_channel
.
on
(
this
.
_internal
.
roomId
,
(
eventName
,
eventData
)
=>
{
logger
.
debug
(
'----- room %s received event "%s" [data:%o]'
,
this
.
_internal
.
roomId
,
eventName
,
eventData
);
});
}
}
get
closed
()
get
closed
()
...
@@ -71,6 +75,8 @@ class Room extends EventEmitter
...
@@ -71,6 +75,8 @@ class Room extends EventEmitter
});
});
}
}
// TODO: unsubscribe from Channel
this
.
emit
(
'close'
,
error
);
this
.
emit
(
'close'
,
error
);
}
}
...
...
worker/include/Channel/Notifier.h
0 → 100644
浏览文件 @
749ce475
#ifndef MS_CHANNEL_NOTIFIER_H
#define MS_CHANNEL_NOTIFIER_H
#include "Channel/UnixStreamSocket.h"
#include <string>
#include <json/json.h>
namespace
Channel
{
class
Notifier
{
public
:
Notifier
(
Channel
::
UnixStreamSocket
*
channel
);
virtual
~
Notifier
();
void
Close
();
void
Emit
(
unsigned
int
targetId
,
std
::
string
eventName
);
void
Emit
(
unsigned
int
targetId
,
std
::
string
eventName
,
Json
::
Value
&
eventData
);
public
:
// Passed by argument.
Channel
::
UnixStreamSocket
*
channel
=
nullptr
;
};
}
#endif
worker/include/Loop.h
浏览文件 @
749ce475
...
@@ -5,6 +5,7 @@
...
@@ -5,6 +5,7 @@
#include "handles/SignalsHandler.h"
#include "handles/SignalsHandler.h"
#include "Channel/UnixStreamSocket.h"
#include "Channel/UnixStreamSocket.h"
#include "Channel/Request.h"
#include "Channel/Request.h"
#include "Channel/Notifier.h"
#include "RTC/Room.h"
#include "RTC/Room.h"
#include <unordered_map>
#include <unordered_map>
...
@@ -41,6 +42,7 @@ private:
...
@@ -41,6 +42,7 @@ private:
SignalsHandler
*
signalsHandler
=
nullptr
;
SignalsHandler
*
signalsHandler
=
nullptr
;
// Others.
// Others.
bool
closed
=
false
;
bool
closed
=
false
;
Channel
::
Notifier
*
notifier
=
nullptr
;
typedef
std
::
unordered_map
<
unsigned
int
,
RTC
::
Room
*>
Rooms
;
typedef
std
::
unordered_map
<
unsigned
int
,
RTC
::
Room
*>
Rooms
;
Rooms
rooms
;
Rooms
rooms
;
};
};
...
...
worker/src/Channel/Notifier.cpp
0 → 100644
浏览文件 @
749ce475
#define MS_CLASS "Channel::Notifier"
#include "Channel/Notifier.h"
#include "Logger.h"
namespace
Channel
{
/* Static variables. */
static
Json
::
Value
empty_data
(
Json
::
objectValue
);
/* Instance methods. */
Notifier
::
Notifier
(
Channel
::
UnixStreamSocket
*
channel
)
:
channel
(
channel
)
{
MS_TRACE
();
}
Notifier
::~
Notifier
()
{
MS_TRACE
();
}
void
Notifier
::
Close
()
{
MS_TRACE
();
delete
this
;
}
void
Notifier
::
Emit
(
unsigned
int
targetId
,
std
::
string
eventName
)
{
MS_TRACE
();
Emit
(
targetId
,
eventName
,
empty_data
);
}
void
Notifier
::
Emit
(
unsigned
int
targetId
,
std
::
string
eventName
,
Json
::
Value
&
eventData
)
{
MS_TRACE
();
static
const
Json
::
StaticString
k_targetId
(
"targetId"
);
static
const
Json
::
StaticString
k_eventName
(
"eventName"
);
static
const
Json
::
StaticString
k_eventData
(
"eventData"
);
Json
::
Value
json
;
json
[
k_targetId
]
=
targetId
;
json
[
k_eventName
]
=
eventName
;
if
(
eventData
.
isObject
())
json
[
k_eventData
]
=
eventData
;
else
json
[
k_eventData
]
=
empty_data
;
this
->
channel
->
Send
(
json
);
}
}
worker/src/Loop.cpp
浏览文件 @
749ce475
...
@@ -22,6 +22,9 @@ Loop::Loop(Channel::UnixStreamSocket* channel) :
...
@@ -22,6 +22,9 @@ Loop::Loop(Channel::UnixStreamSocket* channel) :
// Set us as Channel's listener.
// Set us as Channel's listener.
this
->
channel
->
SetListener
(
this
);
this
->
channel
->
SetListener
(
this
);
// Create the Notifier instance.
this
->
notifier
=
new
Channel
::
Notifier
(
this
->
channel
);
// Set the signals handler.
// Set the signals handler.
this
->
signalsHandler
=
new
SignalsHandler
(
this
);
this
->
signalsHandler
=
new
SignalsHandler
(
this
);
...
@@ -76,6 +79,9 @@ void Loop::Close()
...
@@ -76,6 +79,9 @@ void Loop::Close()
room
->
Close
();
room
->
Close
();
}
}
// Close the Notifier.
this
->
notifier
->
Close
();
// Close the Channel socket.
// Close the Channel socket.
if
(
this
->
channel
)
if
(
this
->
channel
)
this
->
channel
->
Close
();
this
->
channel
->
Close
();
...
@@ -206,6 +212,9 @@ void Loop::onChannelRequest(Channel::UnixStreamSocket* channel, Channel::Request
...
@@ -206,6 +212,9 @@ void Loop::onChannelRequest(Channel::UnixStreamSocket* channel, Channel::Request
MS_DEBUG
(
"Room created [roomId:%u]"
,
roomId
);
MS_DEBUG
(
"Room created [roomId:%u]"
,
roomId
);
request
->
Accept
();
request
->
Accept
();
// TODO: TESTING
this
->
notifier
->
Emit
(
roomId
,
"created"
);
break
;
break
;
}
}
...
...
编写
预览
Markdown
格式
0%
重试
或
添加新文件
添加附件
取消
您添加了
0
人
到此讨论。请谨慎行事。
请先完成此评论的编辑!
取消
请
注册
或者
登录
后发表评论