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

Add room.getCapabilities() and remove options in server.Room()

上级 1068feff
...@@ -21,7 +21,7 @@ $ npm install mediasoup --save ...@@ -21,7 +21,7 @@ $ npm install mediasoup --save
## Design goals ## Design goals
* Be a Node.js module: `npm install mediasoup` * Be a Node.js module
* Be minimalist: just handle the media layer * Be minimalist: just handle the media layer
* Expose a modern ECMAScript 6 [API](/api/) in sync with [ORTC](http://ortc.org/) * Expose a modern ECMAScript 6 [API](/api/) in sync with [ORTC](http://ortc.org/)
* Work with current [WebRTC](https://webrtc.org) client implementations * Work with current [WebRTC](https://webrtc.org) client implementations
......
...@@ -15,7 +15,7 @@ let tests = ...@@ -15,7 +15,7 @@ let tests =
'test/test_Transport.js', 'test/test_Transport.js',
'test/test_RtpReceiver.js', 'test/test_RtpReceiver.js',
'test/test_extra.js' 'test/test_extra.js'
// NOTE: Unable his test until fixed // NOTE: Disable this test until fixed
// 'test/test_scene_1.js' // 'test/test_scene_1.js'
]; ];
...@@ -43,4 +43,8 @@ gulp.task('test-debug', shell.task( ...@@ -43,4 +43,8 @@ gulp.task('test-debug', shell.task(
} }
)); ));
gulp.task('t', gulp.series('test'));
gulp.task('td', gulp.series('test-debug'));
gulp.task('default', gulp.series('lint')); gulp.task('default', gulp.series('lint'));
...@@ -197,6 +197,33 @@ class Room extends EventEmitter ...@@ -197,6 +197,33 @@ class Room extends EventEmitter
{ {
return this._peers.get(peerName); return this._peers.get(peerName);
} }
/**
* Get room capabilities.
*
* @return {Promise}
*/
getCapabilities()
{
logger.debug('getCapabilities()');
if (this._closed)
return Promise.reject(new errors.InvalidStateError('Room closed'));
return this._channel.request('room.getCapabilities', this._internal)
.then((data) =>
{
logger.debug('"room.getCapabilities" request succeeded');
return data;
})
.catch((error) =>
{
logger.error('"room.getCapabilities" request failed: %s', error);
throw error;
});
}
} }
module.exports = Room; module.exports = Room;
...@@ -181,21 +181,18 @@ class Server extends EventEmitter ...@@ -181,21 +181,18 @@ class Server extends EventEmitter
/** /**
* Create a Room instance. * Create a Room instance.
* *
* @param {Object} [options]
* @param {boolean} [options.forceUniquePayloadTypes=false]
* @return {Room} * @return {Room}
*/ */
Room(options) Room(options)
{ {
logger.debug('Room() [options:%o]', options); logger.debug('Room()');
if (this._closed) if (this._closed)
throw new errors.InvalidStateError('Server closed'); throw new errors.InvalidStateError('Server closed');
let worker = this._getRandomWorker(); let worker = this._getRandomWorker();
return worker.Room(options); return worker.Room();
} }
_addWorker(worker) _addWorker(worker)
......
...@@ -169,9 +169,9 @@ class Worker extends EventEmitter ...@@ -169,9 +169,9 @@ class Worker extends EventEmitter
}); });
} }
Room(options) Room()
{ {
logger.debug('Room() [options:%o]', options); logger.debug('Room()');
let internal = let internal =
{ {
...@@ -185,7 +185,7 @@ class Worker extends EventEmitter ...@@ -185,7 +185,7 @@ class Worker extends EventEmitter
this._rooms.add(room); this._rooms.add(room);
room.on('close', () => this._rooms.delete(room)); room.on('close', () => this._rooms.delete(room));
this._channel.request('worker.createRoom', internal, options) this._channel.request('worker.createRoom', internal)
.then(() => logger.debug('"worker.createRoom" request succeeded')) .then(() => logger.debug('"worker.createRoom" request succeeded'))
.catch((error) => .catch((error) =>
{ {
......
...@@ -92,6 +92,42 @@ tap.test('room.Peer() with same peerName must succeed if previous peer was close ...@@ -92,6 +92,42 @@ tap.test('room.Peer() with same peerName must succeed if previous peer was close
setTimeout(() => peer2.close(), 50); setTimeout(() => peer2.close(), 50);
}); });
tap.test('room.peers must retrieve existing peers', { timeout: 2000 }, (t) =>
{
let server = mediasoup.Server();
t.tearDown(() => server.close());
let room = server.Room();
let alice = room.Peer('alice');
let bob = room.Peer('bob');
let carol = room.Peer('carol');
bob.close();
t.same(room.peers, [ alice, carol ], 'room.peers() must retrieve "alice" and "carol" peers');
t.end();
});
tap.test('room.getCapabilities() must retrieve current room capabilities', { timeout: 2000 }, (t) =>
{
let server = mediasoup.Server();
t.tearDown(() => server.close());
let room = server.Room();
room.getCapabilities()
.then((capabilities) =>
{
t.pass('room.getCapabilities() succeeded');
t.end();
})
.catch((error) => t.fail(`room.getCapabilities() failed: ${error}`));
});
tap.test('room.dump() must succeed', { timeout: 2000 }, (t) => tap.test('room.dump() must succeed', { timeout: 2000 }, (t) =>
{ {
let server = mediasoup.Server(); let server = mediasoup.Server();
......
...@@ -23,6 +23,7 @@ namespace Channel ...@@ -23,6 +23,7 @@ namespace Channel
room_close, room_close,
room_dump, room_dump,
room_createPeer, room_createPeer,
room_getCapabilities,
peer_close, peer_close,
peer_dump, peer_dump,
peer_createTransport, peer_createTransport,
......
...@@ -25,14 +25,8 @@ namespace RTC ...@@ -25,14 +25,8 @@ namespace RTC
virtual void onRoomClosed(RTC::Room* room) = 0; virtual void onRoomClosed(RTC::Room* room) = 0;
}; };
private:
struct Options
{
bool forceUniquePayloadTypes = false;
};
public: public:
Room(Listener* listener, Channel::Notifier* notifier, uint32_t roomId, Json::Value& data); Room(Listener* listener, Channel::Notifier* notifier, uint32_t roomId);
virtual ~Room(); virtual ~Room();
void Close(); void Close();
...@@ -62,7 +56,6 @@ namespace RTC ...@@ -62,7 +56,6 @@ namespace RTC
// Others. // Others.
std::unordered_map<uint32_t, RTC::Peer*> peers; std::unordered_map<uint32_t, RTC::Peer*> peers;
std::unordered_map<RTC::RtpReceiver*, std::unordered_set<RTC::RtpSender*>> mapRtpReceiverRtpSenders; std::unordered_map<RTC::RtpReceiver*, std::unordered_set<RTC::RtpSender*>> mapRtpReceiverRtpSenders;
Options options;
}; };
} }
......
...@@ -16,6 +16,7 @@ namespace Channel ...@@ -16,6 +16,7 @@ namespace Channel
{ "room.close", Request::MethodId::room_close }, { "room.close", Request::MethodId::room_close },
{ "room.dump", Request::MethodId::room_dump }, { "room.dump", Request::MethodId::room_dump },
{ "room.createPeer", Request::MethodId::room_createPeer }, { "room.createPeer", Request::MethodId::room_createPeer },
{ "room.getCapabilities", Request::MethodId::room_getCapabilities },
{ "peer.close", Request::MethodId::peer_close }, { "peer.close", Request::MethodId::peer_close },
{ "peer.dump", Request::MethodId::peer_dump }, { "peer.dump", Request::MethodId::peer_dump },
{ "peer.createTransport", Request::MethodId::peer_createTransport }, { "peer.createTransport", Request::MethodId::peer_createTransport },
......
...@@ -197,7 +197,7 @@ void Loop::onChannelRequest(Channel::UnixStreamSocket* channel, Channel::Request ...@@ -197,7 +197,7 @@ void Loop::onChannelRequest(Channel::UnixStreamSocket* channel, Channel::Request
try try
{ {
room = new RTC::Room(this, this->notifier, roomId, request->data); room = new RTC::Room(this, this->notifier, roomId);
} }
catch (const MediaSoupError &error) catch (const MediaSoupError &error)
{ {
...@@ -216,6 +216,7 @@ void Loop::onChannelRequest(Channel::UnixStreamSocket* channel, Channel::Request ...@@ -216,6 +216,7 @@ void Loop::onChannelRequest(Channel::UnixStreamSocket* channel, Channel::Request
case Channel::Request::MethodId::room_close: case Channel::Request::MethodId::room_close:
case Channel::Request::MethodId::room_dump: case Channel::Request::MethodId::room_dump:
case Channel::Request::MethodId::room_createPeer: case Channel::Request::MethodId::room_createPeer:
case Channel::Request::MethodId::room_getCapabilities:
case Channel::Request::MethodId::peer_close: case Channel::Request::MethodId::peer_close:
case Channel::Request::MethodId::peer_dump: case Channel::Request::MethodId::peer_dump:
case Channel::Request::MethodId::peer_createTransport: case Channel::Request::MethodId::peer_createTransport:
......
...@@ -10,26 +10,12 @@ namespace RTC ...@@ -10,26 +10,12 @@ namespace RTC
{ {
/* Instance methods. */ /* Instance methods. */
Room::Room(Listener* listener, Channel::Notifier* notifier, uint32_t roomId, Json::Value& data) : Room::Room(Listener* listener, Channel::Notifier* notifier, uint32_t roomId) :
roomId(roomId), roomId(roomId),
listener(listener), listener(listener),
notifier(notifier) notifier(notifier)
{ {
MS_TRACE(); MS_TRACE();
static const Json::StaticString k_audioCodec("audioCodec");
static const Json::StaticString k_videoCodec("videoCodec");
static const Json::StaticString k_forceUniquePayloadTypes("forceUniquePayloadTypes");
// `audioCodec` is optional.
// if (data[k_audioCodec].isString())
// `videoCodec` is optional.
// if (data[k_videoCodec].isString())
// `forceUniquePayloadTypes` is optional.
if (data[k_forceUniquePayloadTypes].isBool())
this->options.forceUniquePayloadTypes = data[k_forceUniquePayloadTypes].asBool();
} }
Room::~Room() Room::~Room()
...@@ -72,32 +58,16 @@ namespace RTC ...@@ -72,32 +58,16 @@ namespace RTC
MS_TRACE(); MS_TRACE();
static const Json::StaticString k_roomId("roomId"); static const Json::StaticString k_roomId("roomId");
static const Json::StaticString k_options("options");
static const Json::StaticString k_audioCodec("audioCodec");
static const Json::StaticString k_videoCodec("videoCodec");
static const Json::StaticString k_forceUniquePayloadTypes("forceUniquePayloadTypes");
static const Json::StaticString k_peers("peers"); static const Json::StaticString k_peers("peers");
static const Json::StaticString k_mapRtpReceiverRtpSenders("mapRtpReceiverRtpSenders"); static const Json::StaticString k_mapRtpReceiverRtpSenders("mapRtpReceiverRtpSenders");
Json::Value json(Json::objectValue); Json::Value json(Json::objectValue);
Json::Value json_options(Json::objectValue);
Json::Value json_peers(Json::arrayValue); Json::Value json_peers(Json::arrayValue);
Json::Value json_mapRtpReceiverRtpSenders(Json::objectValue); Json::Value json_mapRtpReceiverRtpSenders(Json::objectValue);
// Add `roomId`. // Add `roomId`.
json[k_roomId] = (Json::UInt)this->roomId; json[k_roomId] = (Json::UInt)this->roomId;
// Add `options.audioCodec`.
// json_options[k_audioCodec] = // TODO
// Add `options.videoCodec`.
// json_options[k_videoCodec] = // TODO
// Add `options.forceUniquePayloadTypes`.
json_options[k_forceUniquePayloadTypes] = this->options.forceUniquePayloadTypes;
json[k_options] = json_options;
// Add `peers`. // Add `peers`.
for (auto& kv : this->peers) for (auto& kv : this->peers)
{ {
...@@ -232,6 +202,17 @@ namespace RTC ...@@ -232,6 +202,17 @@ namespace RTC
break; break;
} }
case Channel::Request::MethodId::room_getCapabilities:
{
// TODO
Json::Value json(Json::objectValue);
request->Accept(json);
break;
}
case Channel::Request::MethodId::peer_close: case Channel::Request::MethodId::peer_close:
case Channel::Request::MethodId::peer_dump: case Channel::Request::MethodId::peer_dump:
case Channel::Request::MethodId::peer_createTransport: case Channel::Request::MethodId::peer_createTransport:
......
Markdown 格式
0% 或
您添加了 0 人 到此讨论。请谨慎行事。
请先完成此评论的编辑!
请 注册 或者 后发表评论