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

Add options to server.Room() method.

上级 15f1fb7d
......@@ -196,18 +196,20 @@ class Server extends EventEmitter
/**
* Create a Room instance
* @param {[Object]} options
* @param {[Boolean]} options.forceUniquePayloadTypes
* @return {Room}
*/
Room()
Room(options)
{
logger.debug('Room()');
logger.debug('Room() [options:%o]', options);
if (this._closed)
throw new errors.InvalidStateError('Server closed');
let worker = this._getRandomWorker();
return worker.Room();
return worker.Room(options);
}
_addWorker(worker)
......
......@@ -152,9 +152,9 @@ class Worker extends EventEmitter
});
}
Room()
Room(options)
{
logger.debug('Room()');
logger.debug('Room() [options:%o]', options);
let internal =
{
......@@ -168,7 +168,7 @@ class Worker extends EventEmitter
this._rooms.add(room);
room.on('close', () => this._rooms.delete(room));
this._channel.request('worker.createRoom', internal)
this._channel.request('worker.createRoom', internal, options)
.then(() => logger.debug('"worker.createRoom" request succeeded'))
.catch((error) =>
{
......
......@@ -25,8 +25,14 @@ namespace RTC
virtual void onRoomClosed(RTC::Room* room) = 0;
};
private:
struct Options
{
bool forceUniquePayloadTypes = false;
};
public:
Room(Listener* listener, Channel::Notifier* notifier, uint32_t roomId);
Room(Listener* listener, Channel::Notifier* notifier, uint32_t roomId, Json::Value& data);
virtual ~Room();
void Close();
......@@ -55,6 +61,7 @@ namespace RTC
// Others.
std::unordered_map<uint32_t, RTC::Peer*> peers;
std::unordered_map<RTC::RtpReceiver*, std::unordered_set<RTC::RtpSender*>> mapRtpReceiverRtpSenders;
Options options;
};
}
......
......@@ -198,7 +198,7 @@ void Loop::onChannelRequest(Channel::UnixStreamSocket* channel, Channel::Request
try
{
room = new RTC::Room(this, this->notifier, roomId);
room = new RTC::Room(this, this->notifier, roomId, request->data);
}
catch (const MediaSoupError &error)
{
......
......@@ -10,12 +10,18 @@ namespace RTC
{
/* Instance methods. */
Room::Room(Listener* listener, Channel::Notifier* notifier, uint32_t roomId) :
Room::Room(Listener* listener, Channel::Notifier* notifier, uint32_t roomId, Json::Value& data) :
roomId(roomId),
listener(listener),
notifier(notifier)
{
MS_TRACE();
static const Json::StaticString k_forceUniquePayloadTypes("forceUniquePayloadTypes");
// `forceUniquePayloadTypes` is optional.
if (data[k_forceUniquePayloadTypes].isBool())
this->options.forceUniquePayloadTypes = data[k_forceUniquePayloadTypes].asBool();
}
Room::~Room()
......@@ -58,15 +64,25 @@ namespace RTC
MS_TRACE();
static const Json::StaticString k_roomId("roomId");
static const Json::StaticString k_options("options");
static const Json::StaticString k_forceUniquePayloadTypes("forceUniquePayloadTypes");
static const Json::StaticString k_peers("peers");
static const Json::StaticString k_mapRtpReceiverRtpSenders("mapRtpReceiverRtpSenders");
Json::Value json(Json::objectValue);
Json::Value json_options(Json::objectValue);
Json::Value json_peers(Json::objectValue);
Json::Value json_mapRtpReceiverRtpSenders(Json::objectValue);
// Add `roomId`.
json[k_roomId] = (Json::UInt)this->roomId;
// Add `options`.
json_options[k_forceUniquePayloadTypes] = this->options.forceUniquePayloadTypes;
json[k_options] = json_options;
// Add `peers`.
for (auto& kv : this->peers)
{
RTC::Peer* peer = kv.second;
......@@ -89,6 +105,7 @@ namespace RTC
json_mapRtpReceiverRtpSenders[std::to_string(rtpReceiver->rtpReceiverId)] = json_rtpReceivers;
}
// Add `mapRtpReceiverRtpSenders`.
json[k_mapRtpReceiverRtpSenders] = json_mapRtpReceiverRtpSenders;
return json;
......
Markdown 格式
0% 或
您添加了 0 人 到此讨论。请谨慎行事。
请先完成此评论的编辑!
请 注册 或者 后发表评论