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

jsoncpp vs picojson

上级 6d71f5f5
/node_modules/
/worker/submodules/
/worker/**/*.o
/worker/submodules/
/worker/bin/
/worker/cldoc/
/worker/mediasoup-tester.sh
......
......@@ -4,3 +4,6 @@
[submodule "worker/submodules/jsoncpp"]
path = worker/submodules/jsoncpp
url = https://github.com/open-source-parsers/jsoncpp.git
[submodule "worker/submodules/picojson"]
path = worker/submodules/picojson
url = https://github.com/eluck/picojson.git
......@@ -7,6 +7,7 @@ debugerror.log = console.error.bind(console);
const process = require('process');
const os = require('os');
const path = require('path');
const check = require('check-types');
const randomString = require('random-string');
......@@ -22,6 +23,7 @@ const VALID_PARAMETERS =
// Set of Server instances
var servers = new Set();
// On process exit close all the Servers
process.on('exit', () =>
{
for (let server of servers)
......@@ -42,15 +44,25 @@ class Server
options = options || {};
// Map of Worker instances
this._workers = new Map();
if (check.integer(options.numWorkers) && check.positive(options.numWorkers))
{
numWorkers = options.numWorkers;
}
// Map of Worker instances
this._workers = new Map();
if (check.nonEmptyString(options.dtlsCertificateFile))
{
options.dtlsCertificateFile = path.resolve(options.dtlsCertificateFile);
}
// Add the server to the set
if (check.nonEmptyString(options.dtlsPrivateKeyFile))
{
options.dtlsPrivateKeyFile = path.resolve(options.dtlsPrivateKeyFile);
}
// Add this Server to the Set
servers.add(this);
for (let key of Object.keys(options))
......@@ -63,13 +75,12 @@ class Server
debug('constructor() [worker parameters:"%s"]', parameters.join(' '));
// Create mediasoup-worker child processes
// Create Worker instances
for (let i = 1; i <= numWorkers; i++)
{
let worker;
let workerId = serverId + '#' + i;
// Create a Worker instance
worker = new Worker(workerId, parameters);
worker.on('exit', () =>
......@@ -82,7 +93,7 @@ class Server
this._workers.delete(workerId);
});
// Add the worker to the map
// Add the Worker to the Map
this._workers.set(workerId, worker);
}
}
......@@ -91,16 +102,14 @@ class Server
{
debug('close()');
// Remove this server from the set
// Remove this Server from the Set
servers.delete(this);
// Close every worker
// Close every Worker
for (let worker of this._workers.values())
{
worker.close();
}
// Clear the workers map
this._workers.clear();
}
}
......
......@@ -12,7 +12,7 @@ const EventEmitter = require('events').EventEmitter;
const WORKER_BIN_PATH = path.join(__dirname, '..', 'worker', 'bin', 'mediasoup-worker');
// Set an env variable to tell workers which the Control FD is
// Set an env variable to tell childs which the Control FD is
process.env.MEDIASOUP_CONTROL_FD = '3';
class Worker extends EventEmitter
......@@ -30,7 +30,7 @@ class Worker extends EventEmitter
stdio : [ 'pipe', 'pipe', 'pipe', 'pipe' ]
};
// Create the worker child process
// Create the mediasoup-worker child process
this._child = spawn(WORKER_BIN_PATH, spawnArgs, spawnOptions);
// TODO: TMP
......@@ -60,14 +60,14 @@ class Worker extends EventEmitter
this._child.on('exit', (code, signal) =>
{
debug('worker process closed [id:%s, code:%s, signal:%s]', id, code, signal);
debug('child process closed [id:%s, code:%s, signal:%s]', id, code, signal);
this.emit('exit', code, signal);
});
this._child.on('error', (error) =>
{
debugerror('worker process error [id:%s]: %s', id, error);
debugerror('child process error [id:%s]: %s', id, error);
this.emit('error', error);
});
......@@ -77,7 +77,7 @@ class Worker extends EventEmitter
{
debug('close()');
// Kill worker child
// Kill child
this._child.kill('SIGTERM');
}
}
......
......@@ -57,6 +57,7 @@ DEP_SOURCES += ./submodules/jsoncpp/dist/jsoncpp.cpp
DEP_HEADERS_DIRS :=
DEP_HEADERS_DIRS += ./submodules/jsoncpp/dist
DEP_HEADERS_DIRS += ./submodules/usrsctp/usrsctplib
DEP_HEADERS_DIRS += ./submodules/picojson
# Dependencies static libraries to link with.
DEP_LIBS :=
......
......@@ -2,6 +2,8 @@
#include "Control/UnixStreamSocket.h"
#include "Logger.h"
#include <json/json.h>
#include <picojson.h>
#define MESSAGE_MAX_SIZE 65536 // TODO: set proper buffer size
......@@ -27,9 +29,60 @@ namespace Control
std::string kk((const char*)data, len);
MS_WARN("---------- readed kk: %s", kk.c_str());
MS_WARN("---------- readed data: %s", kk.c_str());
this->bufferDataLen = 0;
Json::Value json;
Json::Reader reader;
if (reader.parse((const char*)data, (const char*)data + len, json))
{
MS_DEBUG("jsoncpp: IT IS VALID JSON:\n%s", json.toStyledString().c_str());
MS_DEBUG("jsoncpp: method : %s", json["method"].asCString());
MS_DEBUG("jsoncpp: room.id : %d", json["room"]["id"].asInt());
MS_DEBUG("jsoncpp: room.closed : %s", json["room"]["closed"].asBool() ? "true" : "false");
if (json["method"].isString())
MS_DEBUG("jsoncpp: method is a string");
if (!json.isMember("kk"))
MS_DEBUG("jsoncpp: kk is not member");
if (json["parent"]["foo"]["bar"].isNull())
MS_DEBUG("jsoncpp: parent.foo.bar is null");
}
else
{
MS_ERROR("jsoncpp: INVALID JSON !!!!");
}
picojson::value v;
std::string err;
picojson::parse(v, (const char*)data, (const char*)data + len, &err);
if (!err.empty()) {
MS_ERROR("picojson: INVALID JSON: %s", err.c_str());
}
MS_DEBUG("picojson: IT IS VALID JSON:\n%s", v.serialize().c_str());
MS_DEBUG("picojson: method : %s", v.get("method").get<std::string>().c_str());
MS_DEBUG("picojson: room.id : %d", (int)v.get("room").get("id").get<double>());
MS_DEBUG("picojson: room.closed : %s", v.get("room").get("closed").get<bool>() ? "true" : "false");
if (v.get("method").is<std::string>())
MS_DEBUG("picojson: method is a string");
if (v.get("kk").is<picojson::null>())
MS_DEBUG("picojson: kk is null");
// ESTO CASCA: ganador: jsoncpp
if (v.get("parent").get("foo").get("bar").is<picojson::null>())
MS_DEBUG("picojson: parent.foo.bar is null");
}
void UnixStreamSocket::userOnUnixStreamSocketClosed(bool is_closed_by_peer)
......
Markdown 格式
0% 或
您添加了 0 人 到此讨论。请谨慎行事。
请先完成此评论的编辑!
请 注册 或者 后发表评论