Skip to content
项目
群组
代码片段
帮助
正在加载...
登录
切换导航
M
mediasoup
项目
项目
详情
活动
周期分析
仓库
仓库
文件
提交
分支
标签
贡献者
分枝图
比较
统计图
议题
0
议题
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
CI / CD
CI / CD
流水线
作业
日程
统计图
Wiki
Wiki
代码片段
代码片段
成员
成员
折叠边栏
关闭边栏
活动
分枝图
统计图
创建新议题
作业
提交
议题看板
打开侧边栏
聂卓夫
mediasoup
Commits
1f7cc488
提交
1f7cc488
authored
1月 06, 2016
作者:
Iñaki Baz Castillo
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
Use unsigned int for peerId rather than a string.
上级
749ce475
显示空白字符变更
内嵌
并排
正在显示
9 个修改的文件
包含
69 行增加
和
51 行删除
+69
-51
Room.js
lib/Room.js
+15
-13
test_room.js
test/test_room.js
+5
-5
Loop.h
worker/include/Loop.h
+1
-2
Peer.h
worker/include/RTC/Peer.h
+4
-4
Room.h
worker/include/RTC/Room.h
+2
-4
Loop.cpp
worker/src/Loop.cpp
+1
-1
Peer.cpp
worker/src/RTC/Peer.cpp
+10
-6
Room.cpp
worker/src/RTC/Room.cpp
+23
-9
Transport.cpp
worker/src/RTC/Transport.cpp
+8
-7
没有找到文件。
lib/Room.js
浏览文件 @
1f7cc488
...
...
@@ -3,6 +3,7 @@
const
EventEmitter
=
require
(
'events'
).
EventEmitter
;
const
logger
=
require
(
'./logger'
)(
'Room'
);
const
utils
=
require
(
'./utils'
);
const
errors
=
require
(
'./errors'
);
const
Peer
=
require
(
'./Peer'
);
...
...
@@ -106,34 +107,35 @@ class Room extends EventEmitter
/**
* Create a Peer instance
* @param {String} [mandatory] peer
Id
Peer identificator
* @param {String} [mandatory] peer
Name
Peer identificator
* @return {Peer}
*/
Peer
(
peer
Id
)
Peer
(
peer
Name
)
{
logger
.
debug
(
'Peer() [peer
Id:%s]'
,
peerId
);
logger
.
debug
(
'Peer() [peer
Name:%s]'
,
peerName
);
if
(
this
.
_closed
)
throw
errors
.
Closed
(
'room closed'
);
if
(
!
peer
Id
||
typeof
peerId
!==
'string'
)
throw
errors
.
TypeError
(
'wrong `peer
Id
` parameter'
);
if
(
!
peer
Name
||
typeof
peerName
!==
'string'
)
throw
errors
.
TypeError
(
'wrong `peer
Name
` parameter'
);
if
(
this
.
_peers
.
has
(
peer
Id
))
throw
new
Error
(
`peer already exists [peer
Id:
${
peerId
}
]`
);
if
(
this
.
_peers
.
has
(
peer
Name
))
throw
new
Error
(
`peer already exists [peer
Name:
${
peerName
}
]`
);
let
internal
=
{
roomId
:
this
.
_internal
.
roomId
,
peerId
:
peerId
peerId
:
utils
.
randomNumber
(),
peerName
:
peerName
};
// Create a Peer instance
let
peer
=
new
Peer
(
internal
,
this
.
_channel
);
// Store the Peer instance and remove it when closed
this
.
_peers
.
set
(
peer
Id
,
peer
);
peer
.
on
(
'close'
,
()
=>
this
.
_peers
.
delete
(
peer
Id
));
this
.
_peers
.
set
(
peer
Name
,
peer
);
peer
.
on
(
'close'
,
()
=>
this
.
_peers
.
delete
(
peer
Name
));
this
.
_channel
.
request
(
'room.createPeer'
,
internal
)
.
then
(()
=>
...
...
@@ -152,12 +154,12 @@ class Room extends EventEmitter
/**
* Get Peer
* @param {String} [mandatory] peer
Id
* @param {String} [mandatory] peer
Name
* @return {Peer}
*/
getPeer
(
peer
Id
)
getPeer
(
peer
Name
)
{
return
this
.
_peers
.
get
(
peer
Id
);
return
this
.
_peers
.
get
(
peer
Name
);
}
/**
...
...
test/test_room.js
浏览文件 @
1f7cc488
...
...
@@ -4,7 +4,7 @@ const tap = require('tap');
const
mediasoup
=
require
(
'../'
);
tap
.
test
(
'room.Peer() with `peer
Id
` must succeed'
,
{
timeout
:
1000
},
(
t
)
=>
tap
.
test
(
'room.Peer() with `peer
Name
` must succeed'
,
{
timeout
:
1000
},
(
t
)
=>
{
let
server
=
mediasoup
.
Server
();
...
...
@@ -23,7 +23,7 @@ tap.test('room.Peer() with `peerId` must succeed', { timeout: 1000 }, (t) =>
setTimeout
(()
=>
peer
.
close
(),
50
);
});
tap
.
test
(
'room.Peer() without `peer
Id
` must fail'
,
{
timeout
:
1000
},
(
t
)
=>
tap
.
test
(
'room.Peer() without `peer
Name
` must fail'
,
{
timeout
:
1000
},
(
t
)
=>
{
let
server
=
mediasoup
.
Server
();
...
...
@@ -39,7 +39,7 @@ tap.test('room.Peer() without `peerId` must fail', { timeout: 1000 }, (t) =>
t
.
end
();
});
tap
.
test
(
'room.Peer() with same `peer
Id
` must fail'
,
{
timeout
:
1000
},
(
t
)
=>
tap
.
test
(
'room.Peer() with same `peer
Name
` must fail'
,
{
timeout
:
1000
},
(
t
)
=>
{
let
server
=
mediasoup
.
Server
();
...
...
@@ -57,7 +57,7 @@ tap.test('room.Peer() with same `peerId` must fail', { timeout: 1000 }, (t) =>
t
.
end
();
});
tap
.
test
(
'room.Peer() with same `peer
Id
` must succeed if previous peer was closed before'
,
{
timeout
:
1000
},
(
t
)
=>
tap
.
test
(
'room.Peer() with same `peer
Name
` must succeed if previous peer was closed before'
,
{
timeout
:
1000
},
(
t
)
=>
{
let
server
=
mediasoup
.
Server
();
...
...
@@ -104,7 +104,7 @@ tap.test('room.dump() must succeed', { timeout: 1000 }, (t) =>
.
then
((
data
)
=>
{
t
.
pass
(
'room.dump() succeeded'
);
t
.
strictSame
(
Object
.
keys
(
data
.
peers
),
[
'alice'
,
'bob'
]
,
'room.dump() should retrieve two peers'
);
t
.
equal
(
Object
.
keys
(
data
.
peers
).
length
,
2
,
'room.dump() should retrieve two peers'
);
t
.
end
();
})
.
catch
((
error
)
=>
t
.
fail
(
`room.dump() failed:
${
error
}
`
));
...
...
worker/include/Loop.h
浏览文件 @
1f7cc488
...
...
@@ -43,8 +43,7 @@ private:
// Others.
bool
closed
=
false
;
Channel
::
Notifier
*
notifier
=
nullptr
;
typedef
std
::
unordered_map
<
unsigned
int
,
RTC
::
Room
*>
Rooms
;
Rooms
rooms
;
std
::
unordered_map
<
unsigned
int
,
RTC
::
Room
*>
rooms
;
};
#endif
worker/include/RTC/Peer.h
浏览文件 @
1f7cc488
...
...
@@ -20,7 +20,7 @@ namespace RTC
};
public
:
Peer
(
Listener
*
listener
,
std
::
string
&
peerId
);
Peer
(
Listener
*
listener
,
unsigned
int
peerId
,
std
::
string
&
peerName
);
virtual
~
Peer
();
void
Close
();
...
...
@@ -36,14 +36,14 @@ namespace RTC
public
:
// Passed by argument.
std
::
string
peerId
;
unsigned
int
peerId
;
std
::
string
peerName
;
private
:
// Passed by argument.
Listener
*
listener
=
nullptr
;
// Others.
typedef
std
::
unordered_map
<
unsigned
int
,
RTC
::
Transport
*>
Transports
;
Transports
transports
;
std
::
unordered_map
<
unsigned
int
,
RTC
::
Transport
*>
transports
;
};
}
...
...
worker/include/RTC/Room.h
浏览文件 @
1f7cc488
...
...
@@ -3,7 +3,6 @@
#include "RTC/Peer.h"
#include "Channel/Request.h"
#include <string>
#include <unordered_map>
#include <json/json.h>
...
...
@@ -28,7 +27,7 @@ namespace RTC
void
HandleRequest
(
Channel
::
Request
*
request
);
private
:
RTC
::
Peer
*
GetPeerFromRequest
(
Channel
::
Request
*
request
,
std
::
string
*
peerId
=
nullptr
);
RTC
::
Peer
*
GetPeerFromRequest
(
Channel
::
Request
*
request
,
unsigned
int
*
peerId
=
nullptr
);
/* Pure virtual methods inherited from RTC::Peer::Listener. */
public
:
...
...
@@ -42,8 +41,7 @@ namespace RTC
// Passed by argument.
Listener
*
listener
=
nullptr
;
// Others.
typedef
std
::
unordered_map
<
std
::
string
,
RTC
::
Peer
*>
Peers
;
Peers
peers
;
std
::
unordered_map
<
unsigned
int
,
RTC
::
Peer
*>
peers
;
};
}
...
...
worker/src/Loop.cpp
浏览文件 @
1f7cc488
...
...
@@ -96,7 +96,7 @@ RTC::Room* Loop::GetRoomFromRequest(Channel::Request* request, unsigned int* roo
auto
jsonRoomId
=
request
->
internal
[
k_roomId
];
if
(
!
jsonRoomId
.
isUInt
())
MS_THROW_ERROR
(
"Request has not numeric
.roomId field
"
);
MS_THROW_ERROR
(
"Request has not numeric
`internal.roomId`
"
);
// If given, fill roomId.
if
(
roomId
)
...
...
worker/src/RTC/Peer.cpp
浏览文件 @
1f7cc488
...
...
@@ -8,8 +8,9 @@ namespace RTC
{
/* Instance methods. */
Peer
::
Peer
(
Listener
*
listener
,
std
::
string
&
peerId
)
:
Peer
::
Peer
(
Listener
*
listener
,
unsigned
int
peerId
,
std
::
string
&
peerName
)
:
peerId
(
peerId
),
peerName
(
peerName
),
listener
(
listener
)
{
MS_TRACE
();
...
...
@@ -46,11 +47,14 @@ namespace RTC
{
MS_TRACE
();
static
const
Json
::
StaticString
k_peerName
(
"peerName"
);
static
const
Json
::
StaticString
k_transports
(
"transports"
);
Json
::
Value
json
(
Json
::
objectValue
);
Json
::
Value
json_transports
(
Json
::
objectValue
);
json
[
k_peerName
]
=
this
->
peerName
;
for
(
auto
&
kv
:
this
->
transports
)
{
RTC
::
Transport
*
transport
=
kv
.
second
;
...
...
@@ -70,11 +74,11 @@ namespace RTC
{
case
Channel
:
:
Request
::
MethodId
::
peer_close
:
{
std
::
string
peerId
=
this
->
peerId
;
unsigned
int
peerId
=
this
->
peerId
;
Close
();
MS_DEBUG
(
"Peer closed [peerId:%
s]"
,
peerId
.
c_str
()
);
MS_DEBUG
(
"Peer closed [peerId:%
u]"
,
peerId
);
request
->
Accept
();
break
;
...
...
@@ -162,9 +166,9 @@ namespace RTC
if
(
!
jsonRtpTransportId
.
isUInt
())
{
MS_ERROR
(
"Request has not numeric
.rtpTransportId field
"
);
MS_ERROR
(
"Request has not numeric
`internal.rtpTransportId`
"
);
request
->
Reject
(
500
,
"Request has not numeric
.rtpTransportId field
"
);
request
->
Reject
(
500
,
"Request has not numeric
`internal.rtpTransportId`
"
);
return
;
}
...
...
@@ -246,7 +250,7 @@ namespace RTC
auto
jsonTransportId
=
request
->
internal
[
k_transportId
];
if
(
!
jsonTransportId
.
isUInt
())
MS_THROW_ERROR
(
"Request has not numeric
.transportId field
"
);
MS_THROW_ERROR
(
"Request has not numeric
`internal.transportId`
"
);
// If given, fill roomId.
if
(
transportId
)
...
...
worker/src/RTC/Room.cpp
浏览文件 @
1f7cc488
...
...
@@ -3,6 +3,7 @@
#include "RTC/Room.h"
#include "MediaSoupError.h"
#include "Logger.h"
#include <string>
namespace
RTC
{
...
...
@@ -55,7 +56,7 @@ namespace RTC
{
RTC
::
Peer
*
peer
=
kv
.
second
;
json_peers
[
peer
->
peerId
]
=
peer
->
toJson
();
json_peers
[
std
::
to_string
(
peer
->
peerId
)
]
=
peer
->
toJson
();
}
json
[
k_peers
]
=
json_peers
;
...
...
@@ -91,8 +92,11 @@ namespace RTC
case
Channel
:
:
Request
::
MethodId
::
room_createPeer
:
{
static
const
Json
::
StaticString
k_peerName
(
"peerName"
);
RTC
::
Peer
*
peer
;
std
::
string
peerId
;
unsigned
int
peerId
;
std
::
string
peerName
;
try
{
...
...
@@ -112,9 +116,19 @@ namespace RTC
return
;
}
if
(
!
request
->
internal
[
k_peerName
].
isString
())
{
MS_ERROR
(
"Request has not string `internal.peerName`"
);
request
->
Reject
(
500
,
"Request has not string `internal.peerName`"
);
return
;
}
peerName
=
request
->
internal
[
k_peerName
].
asString
();
try
{
peer
=
new
RTC
::
Peer
(
this
,
peerId
);
peer
=
new
RTC
::
Peer
(
this
,
peerId
,
peerName
);
}
catch
(
const
MediaSoupError
&
error
)
{
...
...
@@ -124,7 +138,7 @@ namespace RTC
this
->
peers
[
peerId
]
=
peer
;
MS_DEBUG
(
"Peer created [peerId:%
s]"
,
peerId
.
c_str
());
MS_DEBUG
(
"Peer created [peerId:%
u, peerName:'%s']"
,
peerId
,
peerName
.
c_str
());
request
->
Accept
();
break
;
...
...
@@ -170,7 +184,7 @@ namespace RTC
}
}
RTC
::
Peer
*
Room
::
GetPeerFromRequest
(
Channel
::
Request
*
request
,
std
::
string
*
peerId
)
RTC
::
Peer
*
Room
::
GetPeerFromRequest
(
Channel
::
Request
*
request
,
unsigned
int
*
peerId
)
{
MS_TRACE
();
...
...
@@ -178,14 +192,14 @@ namespace RTC
auto
jsonPeerId
=
request
->
internal
[
k_peerId
];
if
(
!
jsonPeerId
.
is
String
())
MS_THROW_ERROR
(
"Request has not
string
.peerId field"
);
if
(
!
jsonPeerId
.
is
UInt
())
MS_THROW_ERROR
(
"Request has not
numeric
.peerId field"
);
// If given, fill peerId.
if
(
peerId
)
*
peerId
=
jsonPeerId
.
as
String
();
*
peerId
=
jsonPeerId
.
as
UInt
();
auto
it
=
this
->
peers
.
find
(
jsonPeerId
.
as
String
());
auto
it
=
this
->
peers
.
find
(
jsonPeerId
.
as
UInt
());
if
(
it
!=
this
->
peers
.
end
())
{
...
...
worker/src/RTC/Transport.cpp
浏览文件 @
1f7cc488
...
...
@@ -370,18 +370,18 @@ namespace RTC
if
(
!
request
->
data
[
k_fingerprint
].
isObject
())
{
MS_ERROR
(
"missing
.fingerprint
"
);
MS_ERROR
(
"missing
`data.fingerprint`
"
);
request
->
Reject
(
500
,
"missing
.fingerprint
"
);
request
->
Reject
(
500
,
"missing
`data.fingerprint`
"
);
return
;
}
if
(
!
request
->
data
[
k_fingerprint
][
k_algorithm
].
isString
()
||
!
request
->
data
[
k_fingerprint
][
k_value
].
isString
())
{
MS_ERROR
(
"missing
.fingerprint.algorithm and/or .fingerprint.value
"
);
MS_ERROR
(
"missing
`data.fingerprint.algorithm` and/or `data.fingerprint.value`
"
);
request
->
Reject
(
500
,
"missing
.fingerprint.algorithm and/or .fingerprint.value
"
);
request
->
Reject
(
500
,
"missing
`data.fingerprint.algorithm` and/or `data.fingerprint.value`
"
);
return
;
}
...
...
@@ -389,9 +389,9 @@ namespace RTC
if
(
remoteFingerprint
.
algorithm
==
RTC
::
DTLSTransport
::
FingerprintAlgorithm
::
NONE
)
{
MS_ERROR
(
"unsupported
.fingerprint.algorithm
"
);
MS_ERROR
(
"unsupported
`data.fingerprint.algorithm`
"
);
request
->
Reject
(
500
,
"unsupported
.fingerprint.algorithm
"
);
request
->
Reject
(
500
,
"unsupported
`data.fingerprint.algorithm`
"
);
return
;
}
...
...
@@ -416,7 +416,7 @@ namespace RTC
case
RTC
:
:
DTLSTransport
::
Role
::
NONE
:
MS_ERROR
(
"invalid .role"
);
request
->
Reject
(
500
,
"invalid
.role
"
);
request
->
Reject
(
500
,
"invalid
`data.role`
"
);
return
;
}
...
...
@@ -560,6 +560,7 @@ namespace RTC
if
(
!
msg
)
{
MS_DEBUG
(
"ignoring wrong STUN message received"
);
return
;
}
...
...
编写
预览
Markdown
格式
0%
重试
或
添加新文件
添加附件
取消
您添加了
0
人
到此讨论。请谨慎行事。
请先完成此评论的编辑!
取消
请
注册
或者
登录
后发表评论