Skip to content
项目
群组
代码片段
帮助
正在加载...
登录
切换导航
M
mediasoup
项目
项目
详情
活动
周期分析
仓库
仓库
文件
提交
分支
标签
贡献者
分枝图
比较
统计图
议题
0
议题
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
CI / CD
CI / CD
流水线
作业
日程
统计图
Wiki
Wiki
代码片段
代码片段
成员
成员
折叠边栏
关闭边栏
活动
分枝图
统计图
创建新议题
作业
提交
议题看板
打开侧边栏
聂卓夫
mediasoup
Commits
fc9b9c51
提交
fc9b9c51
authored
12月 23, 2015
作者:
Iñaki Baz Castillo
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
room.close() and peer.close() do close their Worker instances.
上级
a9262fec
显示空白字符变更
内嵌
并排
正在显示
10 个修改的文件
包含
178 行增加
和
11 行删除
+178
-11
Peer.js
lib/Peer.js
+20
-0
Room.js
lib/Room.js
+16
-0
Worker.js
lib/Worker.js
+8
-3
test_room.js
test/test_room.js
+23
-0
Request.h
worker/include/Channel/Request.h
+3
-1
Room.h
worker/include/RTC/Room.h
+1
-0
Request.cpp
worker/src/Channel/Request.cpp
+3
-1
Loop.cpp
worker/src/Loop.cpp
+68
-5
Room.cpp
worker/src/RTC/Room.cpp
+36
-0
Settings.cpp
worker/src/Settings.cpp
+0
-1
没有找到文件。
lib/Peer.js
浏览文件 @
fc9b9c51
...
@@ -12,6 +12,9 @@ class Peer extends EventEmitter
...
@@ -12,6 +12,9 @@ class Peer extends EventEmitter
super
();
super
();
// Room identificator
this
.
_roomId
=
options
.
roomId
;
// Peer identificator
// Peer identificator
this
.
_peerId
=
options
.
peerId
;
this
.
_peerId
=
options
.
peerId
;
...
@@ -33,6 +36,23 @@ class Peer extends EventEmitter
...
@@ -33,6 +36,23 @@ class Peer extends EventEmitter
this
.
_closed
=
true
;
this
.
_closed
=
true
;
let
request
=
{
roomId
:
this
.
_roomId
,
peerId
:
this
.
_peerId
};
// Send Channel request
this
.
_channel
.
request
(
'closePeer'
,
request
)
.
then
(()
=>
{
logger
.
debug
(
'"closePeer" request succeeded'
);
})
.
catch
((
error
)
=>
{
logger
.
error
(
'"closePeer" request failed [status:%s, error:"%s"]'
,
error
.
status
,
error
.
message
);
});
this
.
emit
(
'close'
,
error
);
this
.
emit
(
'close'
,
error
);
}
}
}
}
...
...
lib/Room.js
浏览文件 @
fc9b9c51
...
@@ -45,6 +45,22 @@ class Room extends EventEmitter
...
@@ -45,6 +45,22 @@ class Room extends EventEmitter
peer
.
close
();
peer
.
close
();
}
}
let
request
=
{
roomId
:
this
.
_roomId
};
// Send Channel request
this
.
_channel
.
request
(
'closeRoom'
,
request
)
.
then
(()
=>
{
logger
.
debug
(
'"closeRoom" request succeeded'
);
})
.
catch
((
error
)
=>
{
logger
.
error
(
'"closeRoom" request failed [status:%s, error:"%s"]'
,
error
.
status
,
error
.
message
);
});
this
.
emit
(
'close'
,
error
);
this
.
emit
(
'close'
,
error
);
}
}
...
...
lib/Worker.js
浏览文件 @
fc9b9c51
...
@@ -113,6 +113,13 @@ class Worker extends EventEmitter
...
@@ -113,6 +113,13 @@ class Worker extends EventEmitter
{
{
logger
.
debug
(
'close() [error:%s]'
,
error
);
logger
.
debug
(
'close() [error:%s]'
,
error
);
// Close every Room
this
.
_rooms
.
forEach
((
room
)
=>
room
.
close
());
// Kill mediasoup-worker process (let it some time so previous
// requests are properly sent and replied)
setTimeout
(()
=>
{
// Kill child
// Kill child
if
(
this
.
_child
)
if
(
this
.
_child
)
{
{
...
@@ -125,9 +132,7 @@ class Worker extends EventEmitter
...
@@ -125,9 +132,7 @@ class Worker extends EventEmitter
// Close the Channel instance
// Close the Channel instance
this
.
_channel
.
close
();
this
.
_channel
.
close
();
},
100
);
// Close every Room
this
.
_rooms
.
forEach
((
room
)
=>
room
.
close
());
this
.
emit
(
'close'
,
error
);
this
.
emit
(
'close'
,
error
);
}
}
...
...
test/test_room.js
浏览文件 @
fc9b9c51
...
@@ -56,3 +56,26 @@ tap.test('room.createPeer() with same `peerId` must fail', { timeout: 1000 }, (t
...
@@ -56,3 +56,26 @@ tap.test('room.createPeer() with same `peerId` must fail', { timeout: 1000 }, (t
})
})
.
catch
((
error
)
=>
t
.
fail
(
`should not fail:
${
error
}
`
));
.
catch
((
error
)
=>
t
.
fail
(
`should not fail:
${
error
}
`
));
});
});
tap
.
test
(
'room.createPeer() with same `peerId` must succeed if previous peer is closed before'
,
{
timeout
:
1000
},
(
t
)
=>
{
let
server
=
mediasoup
.
Server
();
t
.
tearDown
(()
=>
server
.
close
());
server
.
createRoom
()
.
then
((
room
)
=>
{
room
.
createPeer
(
'alice'
)
.
then
((
peer
)
=>
{
peer
.
close
();
room
.
createPeer
(
'alice'
)
.
then
(()
=>
t
.
end
())
.
catch
((
error
)
=>
t
.
fail
(
`should not fail:
${
error
}
`
));
})
.
catch
((
error
)
=>
t
.
fail
(
`should not fail:
${
error
}
`
));
})
.
catch
((
error
)
=>
t
.
fail
(
`should not fail:
${
error
}
`
));
});
worker/include/Channel/Request.h
浏览文件 @
fc9b9c51
...
@@ -18,7 +18,9 @@ namespace Channel
...
@@ -18,7 +18,9 @@ namespace Channel
{
{
updateSettings
=
1
,
updateSettings
=
1
,
createRoom
,
createRoom
,
createPeer
closeRoom
,
createPeer
,
closePeer
};
};
public
:
public
:
...
...
worker/include/RTC/Room.h
浏览文件 @
fc9b9c51
...
@@ -21,6 +21,7 @@ namespace RTC
...
@@ -21,6 +21,7 @@ namespace RTC
virtual
~
Room
();
virtual
~
Room
();
void
HandleCreatePeerRequest
(
Channel
::
Request
*
request
);
void
HandleCreatePeerRequest
(
Channel
::
Request
*
request
);
void
HandleClosePeerRequest
(
Channel
::
Request
*
request
);
void
Close
();
void
Close
();
private
:
private
:
...
...
worker/src/Channel/Request.cpp
浏览文件 @
fc9b9c51
...
@@ -15,7 +15,9 @@ namespace Channel
...
@@ -15,7 +15,9 @@ namespace Channel
{
{
{
"updateSettings"
,
Request
::
MethodId
::
updateSettings
},
{
"updateSettings"
,
Request
::
MethodId
::
updateSettings
},
{
"createRoom"
,
Request
::
MethodId
::
createRoom
},
{
"createRoom"
,
Request
::
MethodId
::
createRoom
},
{
"createPeer"
,
Request
::
MethodId
::
createPeer
}
{
"closeRoom"
,
Request
::
MethodId
::
closeRoom
},
{
"createPeer"
,
Request
::
MethodId
::
createPeer
},
{
"closePeer"
,
Request
::
MethodId
::
closePeer
}
};
};
/* Class methods. */
/* Class methods. */
...
...
worker/src/Loop.cpp
浏览文件 @
fc9b9c51
...
@@ -76,6 +76,7 @@ void Loop::Close()
...
@@ -76,6 +76,7 @@ void Loop::Close()
if
(
this
->
closed
)
if
(
this
->
closed
)
{
{
MS_ERROR
(
"already closed"
);
MS_ERROR
(
"already closed"
);
return
;
return
;
}
}
this
->
closed
=
true
;
this
->
closed
=
true
;
...
@@ -155,7 +156,6 @@ void Loop::onChannelRequest(Channel::UnixStreamSocket* channel, Channel::Request
...
@@ -155,7 +156,6 @@ void Loop::onChannelRequest(Channel::UnixStreamSocket* channel, Channel::Request
catch
(
const
MediaSoupError
&
error
)
catch
(
const
MediaSoupError
&
error
)
{
{
request
->
Reject
(
500
,
error
.
what
());
request
->
Reject
(
500
,
error
.
what
());
return
;
return
;
}
}
...
@@ -164,7 +164,6 @@ void Loop::onChannelRequest(Channel::UnixStreamSocket* channel, Channel::Request
...
@@ -164,7 +164,6 @@ void Loop::onChannelRequest(Channel::UnixStreamSocket* channel, Channel::Request
MS_ERROR
(
"Room already exists"
);
MS_ERROR
(
"Room already exists"
);
request
->
Reject
(
500
,
"Room already exists"
);
request
->
Reject
(
500
,
"Room already exists"
);
return
;
return
;
}
}
...
@@ -175,11 +174,48 @@ void Loop::onChannelRequest(Channel::UnixStreamSocket* channel, Channel::Request
...
@@ -175,11 +174,48 @@ void Loop::onChannelRequest(Channel::UnixStreamSocket* channel, Channel::Request
MS_ERROR
(
"failed to create Room"
);
MS_ERROR
(
"failed to create Room"
);
request
->
Reject
(
500
,
"failed to create Room"
);
request
->
Reject
(
500
,
"failed to create Room"
);
return
;
return
;
}
}
this
->
rooms
[
roomId
]
=
room
;
this
->
rooms
[
roomId
]
=
room
;
MS_DEBUG
(
"Room created [roomId:%u]"
,
roomId
);
request
->
Accept
();
break
;
}
case
Channel
:
:
Request
::
MethodId
::
closeRoom
:
{
MS_DEBUG
(
"'closeRoom' method"
);
RTC
::
Room
*
room
;
unsigned
int
roomId
;
try
{
room
=
GetRoomFromRequest
(
request
,
&
roomId
);
}
catch
(
const
MediaSoupError
&
error
)
{
request
->
Reject
(
500
,
error
.
what
());
return
;
}
if
(
!
room
)
{
MS_ERROR
(
"Room does not exist"
);
request
->
Reject
(
500
,
"Room does not exist"
);
return
;
}
room
->
Close
();
// TODO: Instead of this, the Room should fire an onRoomClosed() here.
this
->
rooms
.
erase
(
roomId
);
MS_DEBUG
(
"Room closed [roomId:%u]"
,
roomId
);
request
->
Accept
();
request
->
Accept
();
break
;
break
;
...
@@ -198,7 +234,6 @@ void Loop::onChannelRequest(Channel::UnixStreamSocket* channel, Channel::Request
...
@@ -198,7 +234,6 @@ void Loop::onChannelRequest(Channel::UnixStreamSocket* channel, Channel::Request
catch
(
const
MediaSoupError
&
error
)
catch
(
const
MediaSoupError
&
error
)
{
{
request
->
Reject
(
500
,
error
.
what
());
request
->
Reject
(
500
,
error
.
what
());
return
;
return
;
}
}
...
@@ -207,7 +242,6 @@ void Loop::onChannelRequest(Channel::UnixStreamSocket* channel, Channel::Request
...
@@ -207,7 +242,6 @@ void Loop::onChannelRequest(Channel::UnixStreamSocket* channel, Channel::Request
MS_ERROR
(
"Room does not exist"
);
MS_ERROR
(
"Room does not exist"
);
request
->
Reject
(
500
,
"Room does not exist"
);
request
->
Reject
(
500
,
"Room does not exist"
);
return
;
return
;
}
}
...
@@ -216,6 +250,35 @@ void Loop::onChannelRequest(Channel::UnixStreamSocket* channel, Channel::Request
...
@@ -216,6 +250,35 @@ void Loop::onChannelRequest(Channel::UnixStreamSocket* channel, Channel::Request
break
;
break
;
}
}
case
Channel
:
:
Request
::
MethodId
::
closePeer
:
{
MS_DEBUG
(
"'closePeer' method"
);
RTC
::
Room
*
room
;
try
{
room
=
GetRoomFromRequest
(
request
);
}
catch
(
const
MediaSoupError
&
error
)
{
request
->
Reject
(
500
,
error
.
what
());
return
;
}
if
(
!
room
)
{
MS_ERROR
(
"Room does not exist"
);
request
->
Reject
(
500
,
"Room does not exist"
);
return
;
}
room
->
HandleClosePeerRequest
(
request
);
break
;
}
default
:
default
:
{
{
MS_ABORT
(
"unexpected methodId"
);
MS_ABORT
(
"unexpected methodId"
);
...
...
worker/src/RTC/Room.cpp
浏览文件 @
fc9b9c51
...
@@ -88,6 +88,42 @@ namespace RTC
...
@@ -88,6 +88,42 @@ namespace RTC
}
}
this
->
peers
[
peerId
]
=
peer
;
this
->
peers
[
peerId
]
=
peer
;
MS_DEBUG
(
"Peer created [peerId:%s]"
,
peerId
.
c_str
());
request
->
Accept
();
}
void
Room
::
HandleClosePeerRequest
(
Channel
::
Request
*
request
)
{
MS_TRACE
();
RTC
::
Peer
*
peer
;
std
::
string
peerId
;
try
{
peer
=
GetPeerFromRequest
(
request
,
&
peerId
);
}
catch
(
const
MediaSoupError
&
error
)
{
request
->
Reject
(
500
,
error
.
what
());
return
;
}
if
(
!
peer
)
{
MS_ERROR
(
"Peer does not exist"
);
request
->
Reject
(
500
,
"Peer does not exist"
);
return
;
}
peer
->
Close
();
// TODO: Instead of this, the Peer should fire an onPeerClosed() here.
this
->
peers
.
erase
(
peerId
);
MS_DEBUG
(
"Peer closed [peerId:%s]"
,
peerId
.
c_str
());
request
->
Accept
();
request
->
Accept
();
}
}
...
...
worker/src/Settings.cpp
浏览文件 @
fc9b9c51
...
@@ -186,7 +186,6 @@ void Settings::HandleUpdateRequest(Channel::Request* request)
...
@@ -186,7 +186,6 @@ void Settings::HandleUpdateRequest(Channel::Request* request)
catch
(
const
MediaSoupError
&
error
)
catch
(
const
MediaSoupError
&
error
)
{
{
request
->
Reject
(
500
,
error
.
what
());
request
->
Reject
(
500
,
error
.
what
());
return
;
return
;
}
}
...
...
编写
预览
Markdown
格式
0%
重试
或
添加新文件
添加附件
取消
您添加了
0
人
到此讨论。请谨慎行事。
请先完成此评论的编辑!
取消
请
注册
或者
登录
后发表评论