提交 eed02324 authored 作者: Iñaki Baz Castillo's avatar Iñaki Baz Castillo

Add Peer spy option

上级 d9f50248
......@@ -31,6 +31,7 @@ class Peer extends EnhancedEventEmitter
// Peer data.
// - .rtpCapabilities
// - .spy
this._data = data;
// Channel instance.
......@@ -833,6 +834,8 @@ class Peer extends EnhancedEventEmitter
return Promise.reject(new errors.InvalidStateError('RTP capabilities unset'));
else if (!KINDS.has(kind))
return Promise.reject(new TypeError(`unsupported kind: ${kind}`));
else if (this._data.spy)
return Promise.reject(new Error('spy peers cannot create producers'));
let rtpMappingForWorker;
let consumableRtpParameters;
......
......@@ -187,12 +187,12 @@ class Room extends EnhancedEventEmitter
case 'join':
{
const { peerName, rtpCapabilities, appData } = request;
const peer = this._createPeer(peerName, rtpCapabilities, appData);
const { peerName, rtpCapabilities, spy, appData } = request;
const peer = this._createPeer(peerName, rtpCapabilities, spy, appData);
const response =
{
peers : this.peers
.filter((otherPeer) => otherPeer !== peer)
.filter((otherPeer) => otherPeer !== peer && !otherPeer.spy)
.map((otherPeer) =>
{
const consumers = peer.consumers
......@@ -311,7 +311,7 @@ class Room extends EnhancedEventEmitter
});
}
_createPeer(peerName, rtpCapabilities, appData)
_createPeer(peerName, rtpCapabilities, spy, appData)
{
logger.debug('_createPeer() [peerName:"%s]', peerName);
......@@ -320,6 +320,8 @@ class Room extends EnhancedEventEmitter
else if (this._peers.has(peerName))
throw new Error(`duplicated Peer [peerName:"${peerName}"]`);
spy = Boolean(spy);
// Ensure that the given capabilties are a subset of the Room capabilities.
// NOTE: This may throw.
ortc.assertCapabilitiesSubset(rtpCapabilities, this.rtpCapabilities);
......@@ -332,7 +334,8 @@ class Room extends EnhancedEventEmitter
const data =
{
rtpCapabilities
rtpCapabilities,
spy
};
const sandbox =
......@@ -357,18 +360,22 @@ class Room extends EnhancedEventEmitter
peer.appData = appData;
// Store the Peer and remove it when closed. Also notify allthe other Peers.
// Store the Peer and remove it when closed. Also notify allthe other Peers
// (unless it's a spy peer).
this._peers.set(peer.name, peer);
peer.on('@close', (appData2) =>
{
this._peers.delete(peer.name);
for (const otherPeer of this._peers.values())
if (!spy)
{
if (otherPeer === peer)
continue;
for (const otherPeer of this._peers.values())
{
if (otherPeer === peer)
continue;
otherPeer.handlePeerClosed(peer, appData2);
otherPeer.handlePeerClosed(peer, appData2);
}
}
});
......@@ -391,13 +398,16 @@ class Room extends EnhancedEventEmitter
this._handleProducer(producer);
});
// Tell all the Peers (but us) about the new Peer.
for (const otherPeer of this._peers.values())
// Tell all the Peers (but us) about the new Peer (unless this is a spy peer).
if (!spy)
{
if (otherPeer === peer)
continue;
for (const otherPeer of this._peers.values())
{
if (otherPeer === peer)
continue;
otherPeer.handleNewPeer(peer);
otherPeer.handleNewPeer(peer);
}
}
this.safeEmit('newpeer', peer);
......
Markdown 格式
0% 或
您添加了 0 人 到此讨论。请谨慎行事。
请先完成此评论的编辑!
请 注册 或者 后发表评论