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

Channel: Split previous Request's .data into .data and .internal.

上级 6d8802c5
......@@ -156,12 +156,12 @@ class Channel extends EventEmitter
}, 250);
}
request(method, data)
request(method, internal, data)
{
logger.debug('request() [method:%s]', method);
let id = utils.randomNumber();
let request = { id, method, data };
let request = { id, method, internal, data };
let ns = netstring.nsWrite(JSON.stringify(request));
let promise;
......
......@@ -9,17 +9,17 @@ const Transport = require('./Transport');
class Peer extends EventEmitter
{
constructor(options, channel)
constructor(internal, channel)
{
logger.debug('constructor() [options:%o]', options);
logger.debug('constructor() [internal:%o]', internal);
super();
// Room identificator
this._roomId = options.roomId;
this._roomId = internal.roomId;
// Peer identificator
this._peerId = options.peerId;
this._peerId = internal.peerId;
// Channel instance
this._channel = channel;
......@@ -58,14 +58,14 @@ class Peer extends EventEmitter
if (!dontSendChannel)
{
let data =
let internal =
{
roomId : this._roomId,
peerId : this._peerId
};
// Send Channel request
this._channel.request('peer.close', data)
this._channel.request('peer.close', internal)
.then(() =>
{
logger.debug('"peer.close" request succeeded');
......@@ -86,13 +86,13 @@ class Peer extends EventEmitter
if (this._closed)
return Promise.reject(errors.Closed('peer closed'));
let data =
let internal =
{
roomId : this._roomId,
peerId : this._peerId
};
return this._channel.request('peer.dump', data)
return this._channel.request('peer.dump', internal)
.then((data) =>
{
logger.debug('"peer.dump" request succeeded');
......@@ -121,21 +121,20 @@ class Peer extends EventEmitter
if (this._closed)
return Promise.reject(errors.Closed('peer closed'));
options = utils.cloneObject(options);
let transportId = utils.randomNumber();
options.roomId = this._roomId;
options.peerId = this._peerId;
options.transportId = transportId;
let internal =
{
roomId : this._roomId,
peerId : this._peerId,
transportId : utils.randomNumber()
};
return this._channel.request('peer.createTransport', options)
return this._channel.request('peer.createTransport', internal, options)
.then((data) =>
{
logger.debug('"peer.createTransport" request succeeded');
// Create a Transport instance
let transport = new Transport(options, data, this._channel);
let transport = new Transport(internal, data, this._channel);
// Store the Transport instance and remove it when closed
this._transports.add(transport);
......
......@@ -8,14 +8,14 @@ const Peer = require('./Peer');
class Room extends EventEmitter
{
constructor(options, channel)
constructor(internal, channel)
{
logger.debug('constructor() [options:%o]', options);
logger.debug('constructor() [internal:%o]', internal);
super();
// Room identificator
this._roomId = options.roomId;
this._roomId = internal.roomId;
// Channel instance
this._channel = channel;
......@@ -57,13 +57,13 @@ class Room extends EventEmitter
if (!dontSendChannel)
{
let data =
let internal =
{
roomId : this._roomId
};
// Send Channel request
this._channel.request('room.close', data)
this._channel.request('room.close', internal)
.then(() =>
{
logger.debug('"room.close" request succeeded');
......@@ -84,12 +84,12 @@ class Room extends EventEmitter
if (this._closed)
return Promise.reject(errors.Closed('room closed'));
let data =
let internal =
{
roomId : this._roomId
};
return this._channel.request('room.dump', data)
return this._channel.request('room.dump', internal)
.then((data) =>
{
logger.debug('"room.dump" request succeeded');
......@@ -122,20 +122,20 @@ class Room extends EventEmitter
if (this._peers.has(peerId))
throw new Error(`peer already exists [peerId:${peerId}]`);
let options =
let internal =
{
roomId : this._roomId,
peerId : peerId
};
// Create a Peer instance
let peer = new Peer(options, this._channel);
let peer = new Peer(internal, this._channel);
// Store the Peer instance and remove it when closed
this._peers.set(peerId, peer);
peer.on('close', () => this._peers.delete(peerId));
this._channel.request('room.createPeer', options)
this._channel.request('room.createPeer', internal)
.then(() => logger.debug('"room.createPeer" request succeeded'))
.catch((error) =>
{
......
......@@ -8,20 +8,20 @@ const errors = require('./errors');
class Transport extends EventEmitter
{
constructor(options, data, channel)
constructor(internal, data, channel)
{
logger.debug('constructor() [options:%o, data:%o]', options, data);
logger.debug('constructor() [internal:%o, data:%o]', internal, data);
super();
// Room identificator
this._roomId = options.roomId;
this._roomId = internal.roomId;
// Peer identificator
this._peerId = options.peerId;
this._peerId = internal.peerId;
// Transport identificator
this._transportId = options.transportId;
this._transportId = internal.transportId;
// Transport data provided by the worker
this._data = data;
......@@ -77,7 +77,7 @@ class Transport extends EventEmitter
if (!dontSendChannel)
{
let data =
let internal =
{
roomId : this._roomId,
peerId : this._peerId,
......@@ -85,7 +85,7 @@ class Transport extends EventEmitter
};
// Send Channel request
this._channel.request('transport.close', data)
this._channel.request('transport.close', internal)
.then(() =>
{
logger.debug('"transport.close" request succeeded');
......@@ -106,14 +106,14 @@ class Transport extends EventEmitter
if (this._closed)
return Promise.reject(errors.Closed('transport closed'));
let data =
let internal =
{
roomId : this._roomId,
peerId : this._peerId,
transportId : this._transportId
};
return this._channel.request('transport.dump', data)
return this._channel.request('transport.dump', internal)
.then((data) =>
{
logger.debug('"transport.dump" request succeeded');
......@@ -129,37 +129,37 @@ class Transport extends EventEmitter
}
/**
* Start the DTLS stack
* @param {Object} remoteDtlsParameters Remote DTLS parameters
* Provide the remote DTLS parameters
* @param {Object} options Remote DTLS parameters
* @return {Promise}
*/
start(remoteDtlsParameters)
setRemoteDtlsParameters(options)
{
logger.debug('start() [remoteDtlsParameters:%o]', remoteDtlsParameters);
logger.debug('setRemoteDtlsParameters() [options:%o]', options);
if (this._closed)
return Promise.reject(errors.Closed('transport closed'));
let data =
let internal =
{
roomId : this._roomId,
peerId : this._peerId,
transportId : this._transportId,
role : remoteDtlsParameters.role,
fingerprint : remoteDtlsParameters.fingerprint
transportId : this._transportId
};
// Send Channel request
return this._channel.request('transport.start', data)
return this._channel.request('transport.setRemoteDtlsParameters', internal, options)
.then((data) =>
{
logger.debug('"transport.start" request succeeded');
logger.debug('"transport.setRemoteDtlsParameters" request succeeded');
// TODO: Handle content of data and append it to this._data.
return data;
})
.catch((error) =>
{
logger.error('"transport.start" request failed [status:%s, error:"%s"]', error.status, error.message);
logger.error('"transport.setRemoteDtlsParameters" request failed [status:%s, error:"%s"]', error.status, error.message);
throw error;
});
......@@ -176,7 +176,7 @@ class Transport extends EventEmitter
if (this._closed)
return Promise.reject(errors.Closed('transport closed'));
let options =
let internal =
{
roomId : this._roomId,
peerId : this._peerId,
......@@ -184,13 +184,13 @@ class Transport extends EventEmitter
rtpTransportId : this._transportId
};
return this._channel.request('peer.createAssociatedTransport', options)
return this._channel.request('peer.createAssociatedTransport', internal)
.then((data) =>
{
logger.debug('"peer.createAssociatedTransport" request succeeded');
// Create a Transport instance
let transport = new Transport(options, data, this._channel);
let transport = new Transport(internal, data, this._channel);
// Emit 'associatedtransport' so the owner Peer can handle this new
// transport
......
......@@ -140,7 +140,7 @@ class Worker extends EventEmitter
{
logger.debug('updateSettings() [options:%o]', options);
return this._channel.request('worker.updateSettings', options)
return this._channel.request('worker.updateSettings', null, options)
.then(() =>
{
logger.debug('"worker.updateSettings" request succeeded');
......@@ -157,19 +157,19 @@ class Worker extends EventEmitter
{
logger.debug('Room()');
let options =
let internal =
{
roomId : utils.randomNumber()
};
// Create a Room instance
let room = new Room(options, this._channel);
let room = new Room(internal, this._channel);
// Store the Room instance and remove it when closed
this._rooms.add(room);
room.on('close', () => this._rooms.delete(room));
this._channel.request('worker.createRoom', options)
this._channel.request('worker.createRoom', internal)
.then(() => logger.debug('"worker.createRoom" request succeeded'))
.catch((error) =>
{
......
......@@ -28,7 +28,7 @@ namespace Channel
peer_createAssociatedTransport,
transport_close,
transport_dump,
transport_start
transport_setRemoteDtlsParameters
};
private:
......@@ -49,6 +49,7 @@ namespace Channel
unsigned int id;
std::string method;
MethodId methodId;
Json::Value internal;
Json::Value data;
// Others.
bool replied = false;
......
......@@ -124,7 +124,7 @@ namespace RTC
bool icePaired = false;
bool icePairedWithUseCandidate = false;
// Others (DTLS).
bool started = false;
bool remoteDtlsParametersGiven = false;
RTC::DTLSTransport::Role dtlsLocalRole = RTC::DTLSTransport::Role::AUTO;
};
......
......@@ -28,7 +28,7 @@ public:
public:
static void SetConfiguration(int argc, char* argv[]);
static void PrintConfiguration();
static void HandleUpdateRequest(Channel::Request* request);
static void HandleRequest(Channel::Request* request);
private:
static void SetDefaultRtcListenIP(int requested_family);
......
......@@ -26,7 +26,7 @@ namespace Channel
{ "peer.createAssociatedTransport", Request::MethodId::peer_createAssociatedTransport },
{ "transport.close", Request::MethodId::transport_close },
{ "transport.dump", Request::MethodId::transport_dump },
{ "transport.start", Request::MethodId::transport_start }
{ "transport.setRemoteDtlsParameters", Request::MethodId::transport_setRemoteDtlsParameters }
};
/* Instance methods. */
......@@ -38,6 +38,7 @@ namespace Channel
static const Json::StaticString k_id("id");
static const Json::StaticString k_method("method");
static const Json::StaticString k_internal("internal");
static const Json::StaticString k_data("data");
if (json[k_id].isUInt())
......@@ -63,6 +64,11 @@ namespace Channel
MS_THROW_ERROR("unknown .method '%s'", this->method.c_str());
}
if (json[k_internal].isObject())
this->internal = json[k_internal];
else
this->internal = Json::Value(Json::objectValue);
if (json[k_data].isObject())
this->data = json[k_data];
else
......
......@@ -87,7 +87,7 @@ RTC::Room* Loop::GetRoomFromRequest(Channel::Request* request, unsigned int* roo
static const Json::StaticString k_roomId("roomId");
auto jsonRoomId = request->data[k_roomId];
auto jsonRoomId = request->internal[k_roomId];
if (!jsonRoomId.isUInt())
MS_THROW_ERROR("Request has not numeric .roomId field");
......@@ -163,7 +163,8 @@ void Loop::onChannelRequest(Channel::UnixStreamSocket* channel, Channel::Request
case Channel::Request::MethodId::worker_updateSettings:
{
Settings::HandleUpdateRequest(request);
Settings::HandleRequest(request);
break;
}
......@@ -217,7 +218,7 @@ void Loop::onChannelRequest(Channel::UnixStreamSocket* channel, Channel::Request
case Channel::Request::MethodId::peer_createAssociatedTransport:
case Channel::Request::MethodId::transport_close:
case Channel::Request::MethodId::transport_dump:
case Channel::Request::MethodId::transport_start:
case Channel::Request::MethodId::transport_setRemoteDtlsParameters:
{
RTC::Room* room;
......
......@@ -954,6 +954,8 @@ namespace RTC
}
else
{
// TODO: this is not an error?
MS_DEBUG("SRTP profile not negotiated");
}
}
......
......@@ -158,7 +158,7 @@ namespace RTC
static const Json::StaticString k_rtpTransportId("rtpTransportId");
auto jsonRtpTransportId = request->data[k_rtpTransportId];
auto jsonRtpTransportId = request->internal[k_rtpTransportId];
if (!jsonRtpTransportId.isUInt())
{
......@@ -203,7 +203,7 @@ namespace RTC
case Channel::Request::MethodId::transport_close:
case Channel::Request::MethodId::transport_dump:
case Channel::Request::MethodId::transport_start:
case Channel::Request::MethodId::transport_setRemoteDtlsParameters:
{
RTC::Transport* transport;
......@@ -243,7 +243,7 @@ namespace RTC
static const Json::StaticString k_transportId("transportId");
auto jsonTransportId = request->data[k_transportId];
auto jsonTransportId = request->internal[k_transportId];
if (!jsonTransportId.isUInt())
MS_THROW_ERROR("Request has not numeric .transportId field");
......
......@@ -136,7 +136,7 @@ namespace RTC
case Channel::Request::MethodId::peer_createAssociatedTransport:
case Channel::Request::MethodId::transport_close:
case Channel::Request::MethodId::transport_dump:
case Channel::Request::MethodId::transport_start:
case Channel::Request::MethodId::transport_setRemoteDtlsParameters:
{
RTC::Peer* peer;
......@@ -176,7 +176,7 @@ namespace RTC
static const Json::StaticString k_peerId("peerId");
auto jsonPeerId = request->data[k_peerId];
auto jsonPeerId = request->internal[k_peerId];
if (!jsonPeerId.isString())
MS_THROW_ERROR("Request has not string .peerId field");
......
......@@ -294,7 +294,7 @@ namespace RTC
break;
}
case Channel::Request::MethodId::transport_start:
case Channel::Request::MethodId::transport_setRemoteDtlsParameters:
{
static const Json::StaticString k_role("role");
static const Json::StaticString v_auto("auto");
......@@ -308,14 +308,14 @@ namespace RTC
RTC::DTLSTransport::Role remoteRole = RTC::DTLSTransport::Role::AUTO; // Default value if missing.
// Ensure this method is not called twice.
if (this->started)
if (this->remoteDtlsParametersGiven)
{
MS_ERROR("method already called");
request->Reject(500, "method already called");
return;
}
this->started = true;
this->remoteDtlsParametersGiven = true;
// Validate request data.
......
......@@ -167,11 +167,17 @@ void Settings::PrintConfiguration()
MS_DEBUG("</configuration>");
}
void Settings::HandleUpdateRequest(Channel::Request* request)
void Settings::HandleRequest(Channel::Request* request)
{
MS_TRACE();
auto jsonLogLevel = request->data["logLevel"];
switch (request->methodId)
{
case Channel::Request::MethodId::worker_updateSettings:
{
static const Json::StaticString k_logLevel("logLevel");
Json::Value jsonLogLevel = request->data[k_logLevel];
try
{
......@@ -195,6 +201,15 @@ void Settings::HandleUpdateRequest(Channel::Request* request)
Settings::PrintConfiguration();
request->Accept();
break;
}
default:
{
MS_ABORT("unknown method");
}
}
}
void Settings::SetDefaultRtcListenIP(int requested_family)
......
Markdown 格式
0% 或
您添加了 0 人 到此讨论。请谨慎行事。
请先完成此评论的编辑!
请 注册 或者 后发表评论