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

General work...

上级 89d793c7
......@@ -29,7 +29,7 @@ class Room extends EventEmitter
reqData = options;
reqData.roomId = this._id;
this._channel.request('createRoom', reqData)
this._channel.request('createRoom_', reqData)
.then((data) =>
{
logger.debug('"createRoom" request succeeded [data:%o]', data);
......
......@@ -3,6 +3,7 @@
#include "Channel/UnixStreamSocket.h"
#include <string>
#include <unordered_map>
#include <json/json.h>
namespace Channel
......@@ -12,11 +13,21 @@ namespace Channel
class Request
{
public:
enum class MethodId
{
createRoom = 1,
createPeer
};
public:
static Channel::Request* Factory(Channel::UnixStreamSocket* channel, Json::Value& json);
private:
static std::unordered_map<std::string, MethodId> string2MethodId;
public:
Request(Channel::UnixStreamSocket* channel, unsigned int id, std::string& method, Json::Value& data);
Request(Channel::UnixStreamSocket* channel, unsigned int id, std::string& method, MethodId methodId, Json::Value& data);
virtual ~Request();
// void Accept(Json::Value data = Json::Value(Json::nullValue));
......@@ -30,6 +41,7 @@ namespace Channel
Channel::UnixStreamSocket* channel = nullptr;
unsigned int id;
std::string method;
MethodId methodId;
Json::Value data;
// Others.
bool replied = false;
......
......@@ -5,9 +5,19 @@
namespace Channel
{
/* Static variables. */
static Json::Value empty_data(Json::objectValue);
/* Static methods. */
/* Class variables. */
std::unordered_map<std::string, Request::MethodId> Request::string2MethodId =
{
{ "createRoom", Request::MethodId::createRoom },
{ "createPeer", Request::MethodId::createPeer }
};
/* Class methods. */
Channel::Request* Request::Factory(Channel::UnixStreamSocket* channel, Json::Value& json)
{
......@@ -15,6 +25,7 @@ namespace Channel
unsigned int id;
std::string method;
MethodId methodId;
Json::Value data;
// TODO: TMP
......@@ -47,20 +58,33 @@ namespace Channel
return nullptr;
}
auto methodIterator = Request::string2MethodId.find(method);
if (methodIterator != Request::string2MethodId.end())
{
methodId = methodIterator->second;
}
else
{
MS_ERROR("unknwon .method '%s'", method.c_str());
return nullptr;
}
if (json["data"].isObject())
data = json["data"];
else
data = Json::Value(Json::objectValue);
return new Request(channel, id, method, data);
return new Request(channel, id, method, methodId, data);
}
/* Instance methods. */
Request::Request(Channel::UnixStreamSocket* channel, unsigned int id, std::string& method, Json::Value& data) :
Request::Request(Channel::UnixStreamSocket* channel, unsigned int id, std::string& method, MethodId methodId, Json::Value& data) :
channel(channel),
id(id),
method(method),
methodId(methodId),
data(data)
{
MS_TRACE();
......
......@@ -13,7 +13,7 @@
namespace Channel
{
/* Static variables. */
/* Class variables. */
MS_BYTE UnixStreamSocket::writeBuffer[MESSAGE_MAX_SIZE];
......@@ -24,8 +24,6 @@ namespace Channel
listener(listener)
{
MS_TRACE();
MS_ERROR("---- MAX NS: %lu", netstring_buffer_size(MESSAGE_MAX_SIZE));
}
UnixStreamSocket::~UnixStreamSocket()
......
......@@ -2,12 +2,12 @@
#include "Logger.h"
/* Static variables. */
/* Class variables. */
std::string Logger::id;
int Logger::fd;
/* Static methods. */
/* Class methods. */
void Logger::Init(const std::string id)
{
......
......@@ -102,6 +102,32 @@ void Loop::onChannelRequest(Channel::UnixStreamSocket* channel, Channel::Request
{
MS_TRACE();
switch (request->methodId)
{
case Channel::Request::MethodId::createRoom:
{
MS_DEBUG("'createRoom' method");
break;
}
case Channel::Request::MethodId::createPeer:
{
MS_DEBUG("'createPeer' method");
break;
}
default:
{
MS_ABORT("unexpected methodId");
}
}
// TODO: TMP jeje
if (request->id < 25000)
{
request->Accept();
......
......@@ -57,7 +57,7 @@ void on_ssl_info(const SSL* ssl, int where, int ret)
namespace RTC
{
/* Static variables. */
/* Class variables. */
X509* DTLSHandler::certificate = nullptr;
EVP_PKEY* DTLSHandler::privateKey = nullptr;
......@@ -77,7 +77,7 @@ namespace RTC
};
MS_BYTE DTLSHandler::sslReadBuffer[MS_SSL_READ_BUFFER_SIZE];
/* Static methods. */
/* Class methods. */
void DTLSHandler::ClassInit()
{
......
......@@ -5,7 +5,7 @@
namespace RTC
{
/* Static methods. */
/* Class methods. */
RTCPPacket* RTCPPacket::Parse(const MS_BYTE* data, size_t len)
{
......
......@@ -7,7 +7,7 @@
namespace RTC
{
/* Static methods. */
/* Class methods. */
RTPPacket* RTPPacket::Parse(const MS_BYTE* data, size_t len)
{
......
......@@ -10,11 +10,11 @@
namespace RTC
{
/* Static variables. */
/* Class variables. */
MS_BYTE SRTPSession::encryptBuffer[MS_ENCRYPT_BUFFER_SIZE];
/* Static methods. */
/* Class methods. */
void SRTPSession::ClassInit()
{
......
......@@ -8,11 +8,11 @@
namespace RTC
{
/* Static variables. */
/* Class variables. */
const MS_BYTE STUNMessage::magicCookie[] = {0x21, 0x12, 0xA4, 0x42};
/* Static methods. */
/* Class methods. */
STUNMessage* STUNMessage::Parse(const MS_BYTE* data, size_t len)
{
......
......@@ -24,7 +24,7 @@ void on_error_close(uv_handle_t* handle)
namespace RTC
{
/* Static variables. */
/* Class variables. */
struct sockaddr_storage TCPServer::sockaddrStorageIPv4;
struct sockaddr_storage TCPServer::sockaddrStorageIPv6;
......@@ -33,7 +33,7 @@ namespace RTC
TCPServer::AvailablePorts TCPServer::availableIPv4Ports;
TCPServer::AvailablePorts TCPServer::availableIPv6Ports;
/* Static methods. */
/* Class methods. */
void TCPServer::ClassInit()
{
......
......@@ -11,11 +11,11 @@
namespace RTC
{
/* Static variables. */
/* Class variables. */
size_t Transport::maxSources = 8;
/* Static methods. */
/* Class methods. */
Transport* Transport::NewWebRTC(Listener* listener)
{
......
......@@ -24,7 +24,7 @@ void on_error_close(uv_handle_t* handle)
namespace RTC
{
/* Static variables. */
/* Class variables. */
struct sockaddr_storage UDPSocket::sockaddrStorageIPv4;
struct sockaddr_storage UDPSocket::sockaddrStorageIPv6;
......@@ -33,7 +33,7 @@ namespace RTC
UDPSocket::AvailablePorts UDPSocket::availableIPv4Ports;
UDPSocket::AvailablePorts UDPSocket::availableIPv6Ports;
/* Static methods. */
/* Class methods. */
void UDPSocket::ClassInit()
{
......
......@@ -21,7 +21,7 @@ extern "C"
static
bool IsBindableIP(const std::string &ip, int family, int* _bind_err);
/* Static variables. */
/* Class variables. */
struct Settings::Configuration Settings::configuration;
std::map<std::string, unsigned int> Settings::string2LogLevel =
......@@ -37,7 +37,7 @@ std::map<unsigned int, std::string> Settings::logLevel2String =
{ MS_LOG_LEVEL_ERROR, "error" }
};
/* Static methods. */
/* Class methods. */
void Settings::SetConfiguration(int argc, char* argv[])
{
......
......@@ -55,7 +55,7 @@ void on_error_close(uv_handle_t* handle)
delete handle;
}
/* Static variables. */
/* Class variables. */
MS_BYTE UDPSocket::readBuffer[MS_READ_BUFFER_SIZE];
......
Markdown 格式
0% 或
您添加了 0 人 到此讨论。请谨慎行事。
请先完成此评论的编辑!
请 注册 或者 后发表评论