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 个修改的文件
包含
70 行增加
和
52 行删除
+70
-52
Room.js
lib/Room.js
+16
-14
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 @@
...
@@ -3,6 +3,7 @@
const
EventEmitter
=
require
(
'events'
).
EventEmitter
;
const
EventEmitter
=
require
(
'events'
).
EventEmitter
;
const
logger
=
require
(
'./logger'
)(
'Room'
);
const
logger
=
require
(
'./logger'
)(
'Room'
);
const
utils
=
require
(
'./utils'
);
const
errors
=
require
(
'./errors'
);
const
errors
=
require
(
'./errors'
);
const
Peer
=
require
(
'./Peer'
);
const
Peer
=
require
(
'./Peer'
);
...
@@ -106,34 +107,35 @@ class Room extends EventEmitter
...
@@ -106,34 +107,35 @@ class Room extends EventEmitter
/**
/**
* Create a Peer instance
* Create a Peer instance
* @param {String} [mandatory] peer
Id
Peer identificator
* @param {String} [mandatory] peer
Name
Peer identificator
* @return {Peer}
* @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
)
if
(
this
.
_closed
)
throw
errors
.
Closed
(
'room closed'
);
throw
errors
.
Closed
(
'room closed'
);
if
(
!
peer
Id
||
typeof
peerId
!==
'string'
)
if
(
!
peer
Name
||
typeof
peerName
!==
'string'
)
throw
errors
.
TypeError
(
'wrong `peer
Id
` parameter'
);
throw
errors
.
TypeError
(
'wrong `peer
Name
` parameter'
);
if
(
this
.
_peers
.
has
(
peer
Id
))
if
(
this
.
_peers
.
has
(
peer
Name
))
throw
new
Error
(
`peer already exists [peer
Id:
${
peerId
}
]`
);
throw
new
Error
(
`peer already exists [peer
Name:
${
peerName
}
]`
);
let
internal
=
let
internal
=
{
{
roomId
:
this
.
_internal
.
roomId
,
roomId
:
this
.
_internal
.
roomId
,
peerId
:
peerId
peerId
:
utils
.
randomNumber
(),
peerName
:
peerName
};
};
// Create a Peer instance
// Create a Peer instance
let
peer
=
new
Peer
(
internal
,
this
.
_channel
);
let
peer
=
new
Peer
(
internal
,
this
.
_channel
);
// Store the Peer instance and remove it when closed
// Store the Peer instance and remove it when closed
this
.
_peers
.
set
(
peer
Id
,
peer
);
this
.
_peers
.
set
(
peer
Name
,
peer
);
peer
.
on
(
'close'
,
()
=>
this
.
_peers
.
delete
(
peer
Id
));
peer
.
on
(
'close'
,
()
=>
this
.
_peers
.
delete
(
peer
Name
));
this
.
_channel
.
request
(
'room.createPeer'
,
internal
)
this
.
_channel
.
request
(
'room.createPeer'
,
internal
)
.
then
(()
=>
.
then
(()
=>
...
@@ -152,12 +154,12 @@ class Room extends EventEmitter
...
@@ -152,12 +154,12 @@ class Room extends EventEmitter
/**
/**
* Get Peer
* Get Peer
* @param {String} [mandatory] peer
Id
* @param {String} [mandatory] peer
Name
* @return {Peer}
* @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');
...
@@ -4,7 +4,7 @@ const tap = require('tap');
const
mediasoup
=
require
(
'../'
);
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
();
let
server
=
mediasoup
.
Server
();
...
@@ -23,7 +23,7 @@ tap.test('room.Peer() with `peerId` must succeed', { timeout: 1000 }, (t) =>
...
@@ -23,7 +23,7 @@ tap.test('room.Peer() with `peerId` must succeed', { timeout: 1000 }, (t) =>
setTimeout
(()
=>
peer
.
close
(),
50
);
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
();
let
server
=
mediasoup
.
Server
();
...
@@ -39,7 +39,7 @@ tap.test('room.Peer() without `peerId` must fail', { timeout: 1000 }, (t) =>
...
@@ -39,7 +39,7 @@ tap.test('room.Peer() without `peerId` must fail', { timeout: 1000 }, (t) =>
t
.
end
();
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
();
let
server
=
mediasoup
.
Server
();
...
@@ -57,7 +57,7 @@ tap.test('room.Peer() with same `peerId` must fail', { timeout: 1000 }, (t) =>
...
@@ -57,7 +57,7 @@ tap.test('room.Peer() with same `peerId` must fail', { timeout: 1000 }, (t) =>
t
.
end
();
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
();
let
server
=
mediasoup
.
Server
();
...
@@ -104,7 +104,7 @@ tap.test('room.dump() must succeed', { timeout: 1000 }, (t) =>
...
@@ -104,7 +104,7 @@ tap.test('room.dump() must succeed', { timeout: 1000 }, (t) =>
.
then
((
data
)
=>
.
then
((
data
)
=>
{
{
t
.
pass
(
'room.dump() succeeded'
);
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
();
t
.
end
();
})
})
.
catch
((
error
)
=>
t
.
fail
(
`room.dump() failed:
${
error
}
`
));
.
catch
((
error
)
=>
t
.
fail
(
`room.dump() failed:
${
error
}
`
));
...
...
worker/include/Loop.h
浏览文件 @
1f7cc488
...
@@ -43,8 +43,7 @@ private:
...
@@ -43,8 +43,7 @@ private:
// Others.
// Others.
bool
closed
=
false
;
bool
closed
=
false
;
Channel
::
Notifier
*
notifier
=
nullptr
;
Channel
::
Notifier
*
notifier
=
nullptr
;
typedef
std
::
unordered_map
<
unsigned
int
,
RTC
::
Room
*>
Rooms
;
std
::
unordered_map
<
unsigned
int
,
RTC
::
Room
*>
rooms
;
Rooms
rooms
;
};
};
#endif
#endif
worker/include/RTC/Peer.h
浏览文件 @
1f7cc488
...
@@ -20,7 +20,7 @@ namespace RTC
...
@@ -20,7 +20,7 @@ namespace RTC
};
};
public
:
public
:
Peer
(
Listener
*
listener
,
std
::
string
&
peerId
);
Peer
(
Listener
*
listener
,
unsigned
int
peerId
,
std
::
string
&
peerName
);
virtual
~
Peer
();
virtual
~
Peer
();
void
Close
();
void
Close
();
...
@@ -36,14 +36,14 @@ namespace RTC
...
@@ -36,14 +36,14 @@ namespace RTC
public
:
public
:
// Passed by argument.
// Passed by argument.
std
::
string
peerId
;
unsigned
int
peerId
;
std
::
string
peerName
;
private
:
private
:
// Passed by argument.
// Passed by argument.
Listener
*
listener
=
nullptr
;
Listener
*
listener
=
nullptr
;
// Others.
// Others.
typedef
std
::
unordered_map
<
unsigned
int
,
RTC
::
Transport
*>
Transports
;
std
::
unordered_map
<
unsigned
int
,
RTC
::
Transport
*>
transports
;
Transports
transports
;
};
};
}
}
...
...
worker/include/RTC/Room.h
浏览文件 @
1f7cc488
...
@@ -3,7 +3,6 @@
...
@@ -3,7 +3,6 @@
#include "RTC/Peer.h"
#include "RTC/Peer.h"
#include "Channel/Request.h"
#include "Channel/Request.h"
#include <string>
#include <unordered_map>
#include <unordered_map>
#include <json/json.h>
#include <json/json.h>
...
@@ -28,7 +27,7 @@ namespace RTC
...
@@ -28,7 +27,7 @@ namespace RTC
void
HandleRequest
(
Channel
::
Request
*
request
);
void
HandleRequest
(
Channel
::
Request
*
request
);
private
:
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. */
/* Pure virtual methods inherited from RTC::Peer::Listener. */
public
:
public
:
...
@@ -42,8 +41,7 @@ namespace RTC
...
@@ -42,8 +41,7 @@ namespace RTC
// Passed by argument.
// Passed by argument.
Listener
*
listener
=
nullptr
;
Listener
*
listener
=
nullptr
;
// Others.
// Others.
typedef
std
::
unordered_map
<
std
::
string
,
RTC
::
Peer
*>
Peers
;
std
::
unordered_map
<
unsigned
int
,
RTC
::
Peer
*>
peers
;
Peers
peers
;
};
};
}
}
...
...
worker/src/Loop.cpp
浏览文件 @
1f7cc488
...
@@ -96,7 +96,7 @@ RTC::Room* Loop::GetRoomFromRequest(Channel::Request* request, unsigned int* roo
...
@@ -96,7 +96,7 @@ RTC::Room* Loop::GetRoomFromRequest(Channel::Request* request, unsigned int* roo
auto
jsonRoomId
=
request
->
internal
[
k_roomId
];
auto
jsonRoomId
=
request
->
internal
[
k_roomId
];
if
(
!
jsonRoomId
.
isUInt
())
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 given, fill roomId.
if
(
roomId
)
if
(
roomId
)
...
...
worker/src/RTC/Peer.cpp
浏览文件 @
1f7cc488
...
@@ -8,8 +8,9 @@ namespace RTC
...
@@ -8,8 +8,9 @@ namespace RTC
{
{
/* Instance methods. */
/* Instance methods. */
Peer
::
Peer
(
Listener
*
listener
,
std
::
string
&
peerId
)
:
Peer
::
Peer
(
Listener
*
listener
,
unsigned
int
peerId
,
std
::
string
&
peerName
)
:
peerId
(
peerId
),
peerId
(
peerId
),
peerName
(
peerName
),
listener
(
listener
)
listener
(
listener
)
{
{
MS_TRACE
();
MS_TRACE
();
...
@@ -46,11 +47,14 @@ namespace RTC
...
@@ -46,11 +47,14 @@ namespace RTC
{
{
MS_TRACE
();
MS_TRACE
();
static
const
Json
::
StaticString
k_peerName
(
"peerName"
);
static
const
Json
::
StaticString
k_transports
(
"transports"
);
static
const
Json
::
StaticString
k_transports
(
"transports"
);
Json
::
Value
json
(
Json
::
objectValue
);
Json
::
Value
json
(
Json
::
objectValue
);
Json
::
Value
json_transports
(
Json
::
objectValue
);
Json
::
Value
json_transports
(
Json
::
objectValue
);
json
[
k_peerName
]
=
this
->
peerName
;
for
(
auto
&
kv
:
this
->
transports
)
for
(
auto
&
kv
:
this
->
transports
)
{
{
RTC
::
Transport
*
transport
=
kv
.
second
;
RTC
::
Transport
*
transport
=
kv
.
second
;
...
@@ -70,11 +74,11 @@ namespace RTC
...
@@ -70,11 +74,11 @@ namespace RTC
{
{
case
Channel
:
:
Request
::
MethodId
::
peer_close
:
case
Channel
:
:
Request
::
MethodId
::
peer_close
:
{
{
std
::
string
peerId
=
this
->
peerId
;
unsigned
int
peerId
=
this
->
peerId
;
Close
();
Close
();
MS_DEBUG
(
"Peer closed [peerId:%
s]"
,
peerId
.
c_str
()
);
MS_DEBUG
(
"Peer closed [peerId:%
u]"
,
peerId
);
request
->
Accept
();
request
->
Accept
();
break
;
break
;
...
@@ -162,9 +166,9 @@ namespace RTC
...
@@ -162,9 +166,9 @@ namespace RTC
if
(
!
jsonRtpTransportId
.
isUInt
())
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
;
return
;
}
}
...
@@ -246,7 +250,7 @@ namespace RTC
...
@@ -246,7 +250,7 @@ namespace RTC
auto
jsonTransportId
=
request
->
internal
[
k_transportId
];
auto
jsonTransportId
=
request
->
internal
[
k_transportId
];
if
(
!
jsonTransportId
.
isUInt
())
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 given, fill roomId.
if
(
transportId
)
if
(
transportId
)
...
...
worker/src/RTC/Room.cpp
浏览文件 @
1f7cc488
...
@@ -3,6 +3,7 @@
...
@@ -3,6 +3,7 @@
#include "RTC/Room.h"
#include "RTC/Room.h"
#include "MediaSoupError.h"
#include "MediaSoupError.h"
#include "Logger.h"
#include "Logger.h"
#include <string>
namespace
RTC
namespace
RTC
{
{
...
@@ -55,7 +56,7 @@ namespace RTC
...
@@ -55,7 +56,7 @@ namespace RTC
{
{
RTC
::
Peer
*
peer
=
kv
.
second
;
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
;
json
[
k_peers
]
=
json_peers
;
...
@@ -91,8 +92,11 @@ namespace RTC
...
@@ -91,8 +92,11 @@ namespace RTC
case
Channel
:
:
Request
::
MethodId
::
room_createPeer
:
case
Channel
:
:
Request
::
MethodId
::
room_createPeer
:
{
{
static
const
Json
::
StaticString
k_peerName
(
"peerName"
);
RTC
::
Peer
*
peer
;
RTC
::
Peer
*
peer
;
std
::
string
peerId
;
unsigned
int
peerId
;
std
::
string
peerName
;
try
try
{
{
...
@@ -112,9 +116,19 @@ namespace RTC
...
@@ -112,9 +116,19 @@ namespace RTC
return
;
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
try
{
{
peer
=
new
RTC
::
Peer
(
this
,
peerId
);
peer
=
new
RTC
::
Peer
(
this
,
peerId
,
peerName
);
}
}
catch
(
const
MediaSoupError
&
error
)
catch
(
const
MediaSoupError
&
error
)
{
{
...
@@ -124,7 +138,7 @@ namespace RTC
...
@@ -124,7 +138,7 @@ namespace RTC
this
->
peers
[
peerId
]
=
peer
;
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
();
request
->
Accept
();
break
;
break
;
...
@@ -170,7 +184,7 @@ namespace RTC
...
@@ -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
();
MS_TRACE
();
...
@@ -178,14 +192,14 @@ namespace RTC
...
@@ -178,14 +192,14 @@ namespace RTC
auto
jsonPeerId
=
request
->
internal
[
k_peerId
];
auto
jsonPeerId
=
request
->
internal
[
k_peerId
];
if
(
!
jsonPeerId
.
is
String
())
if
(
!
jsonPeerId
.
is
UInt
())
MS_THROW_ERROR
(
"Request has not
string
.peerId field"
);
MS_THROW_ERROR
(
"Request has not
numeric
.peerId field"
);
// If given, fill peerId.
// If given, fill peerId.
if
(
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
())
if
(
it
!=
this
->
peers
.
end
())
{
{
...
...
worker/src/RTC/Transport.cpp
浏览文件 @
1f7cc488
...
@@ -370,18 +370,18 @@ namespace RTC
...
@@ -370,18 +370,18 @@ namespace RTC
if
(
!
request
->
data
[
k_fingerprint
].
isObject
())
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
;
return
;
}
}
if
(
!
request
->
data
[
k_fingerprint
][
k_algorithm
].
isString
()
||
if
(
!
request
->
data
[
k_fingerprint
][
k_algorithm
].
isString
()
||
!
request
->
data
[
k_fingerprint
][
k_value
].
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
;
return
;
}
}
...
@@ -389,9 +389,9 @@ namespace RTC
...
@@ -389,9 +389,9 @@ namespace RTC
if
(
remoteFingerprint
.
algorithm
==
RTC
::
DTLSTransport
::
FingerprintAlgorithm
::
NONE
)
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
;
return
;
}
}
...
@@ -416,7 +416,7 @@ namespace RTC
...
@@ -416,7 +416,7 @@ namespace RTC
case
RTC
:
:
DTLSTransport
::
Role
::
NONE
:
case
RTC
:
:
DTLSTransport
::
Role
::
NONE
:
MS_ERROR
(
"invalid .role"
);
MS_ERROR
(
"invalid .role"
);
request
->
Reject
(
500
,
"invalid
.role
"
);
request
->
Reject
(
500
,
"invalid
`data.role`
"
);
return
;
return
;
}
}
...
@@ -560,6 +560,7 @@ namespace RTC
...
@@ -560,6 +560,7 @@ namespace RTC
if
(
!
msg
)
if
(
!
msg
)
{
{
MS_DEBUG
(
"ignoring wrong STUN message received"
);
MS_DEBUG
(
"ignoring wrong STUN message received"
);
return
;
return
;
}
}
...
...
编写
预览
Markdown
格式
0%
重试
或
添加新文件
添加附件
取消
您添加了
0
人
到此讨论。请谨慎行事。
请先完成此评论的编辑!
取消
请
注册
或者
登录
后发表评论