Commit f4cbc4db by 李维杰

为了测试turn 81.70.124.49 及 纯P2P通讯(不走中转)而修改代码

parent f5787584
#include "cmd_processer_server.h"
#include "mqtt_request.h"
#include "json/json.h"
namespace offcn
{
static const std::string kGlobalTopic = "kcp_server_mqtt";
static const std::string kLocalID = "kcp_server_mqtt";
static const std::string kGlobalTopic = "topic_for_turn_test";
static const std::string kLocalID = "mqtt_server_for_turn_test";
CmdProcesserServer::CmdProcesserServer()
:mqtt_wrapper_(NULL)
......@@ -63,67 +64,66 @@ namespace offcn
return;
}
if (method.compare("join") == 0)
if (method.compare("login") == 0)
{
if (MqttRequest::ParseJoinRequest(message, values, error))
{
OnParseJoinSuccess(values["message_id"], values["from_id"]);
OnParseJoinSuccess(values["id"]);
}
else
{
OnParseFailure(values["message_id"], values["from_id"], error);
}
}
else if (method.compare("update") == 0)
{
if (MqttRequest::ParseUpdateRequest(message, values, error))
{
OnParseUpdateSuccess(values["message_id"], values["from_id"], values["pull_type"]);
}
else
{
OnParseFailure(values["message_id"], values["from_id"], error);
OnParseFailure(values["id"], values["id"], error);
}
}
}
void CmdProcesserServer::OnParseJoinSuccess(std::string message_id, std::string from_id)
void CmdProcesserServer::OnParseJoinSuccess(std::string from_id)
{
std::string response;
if (client_lists_.find(from_id) != client_lists_.end())
{
response = MqttRequest::BuildResponse(message_id, "id exist");
response = MqttRequest::BuildResponse(from_id, "id exist");
mqtt_wrapper_->SendRequest(from_id, response);
return;
}
else
{
if (client_lists_.size() == 0)
{
client_lists_.insert(std::pair<std::string, std::string>(from_id, "rtmp"));
}
else
{
client_lists_.insert(std::pair<std::string, std::string>(from_id, "null"));
}
client_lists_.insert(std::pair<std::string, std::string>(from_id, from_id));
//response
response = MqttRequest::BuildResponse(message_id, "ok");
mqtt_wrapper_->SendRequest(from_id, response);
Json::Value root;
Json::Value root1;
Json::Value ids;
Json::StreamWriterBuilder wBuilder;
printf("\n------------------------------------\n");
root["method"] = "publishers";
root1["method"] = "online";
root1["id"] = from_id;
printf("\n----------------online list--------------------\n");
std::map<std::string, std::string>::iterator itor;
for (itor = client_lists_.begin(); itor != client_lists_.end(); itor++)
{
if (itor->first.compare(from_id) != 0 && itor->second.compare("rtmp") == 0)
if (itor->first.compare(from_id) != 0)
{
response = MqttRequest::PublishersRequest("sdf", from_id, itor->first);
mqtt_wrapper_->SendRequest(from_id, response);
//response = MqttRequest::PublishersRequest("sdf", from_id, itor->first);
//mqtt_wrapper_->SendRequest(itor->first, response);
ids.append(itor->first);
}
printf("id = %s, pull type = %s\n", itor->first.c_str(), itor->second.c_str());
}
printf("------------------------------------\n");
printf("\n-----------------------------------------------\n");
root["ids"] = ids;
std::string req = Json::writeString(wBuilder, root);
mqtt_wrapper_->SendRequest(from_id, req);
//req = Json::writeString(wBuilder, root1);
//std::string topic = kGlobalTopic;
//mqtt_wrapper_->SendRequest(topic, req);
}
}
void CmdProcesserServer::OnParseFailure(std::string message_id, std::string from_id, std::string error)
......
......@@ -26,7 +26,7 @@ namespace offcn
virtual void OnServerMessageArrived(std::string topic, std::string message);
private:
void OnParseJoinSuccess(std::string message_id, std::string from_id);
void OnParseJoinSuccess(std::string from_id);
void OnParseFailure(std::string message_id, std::string from_id, std::string error);
void OnParseUpdateSuccess(std::string message_id, std::string from_id, std::string pull_type);
......
......@@ -72,10 +72,8 @@ namespace offcn
Json::Value root;
Json::StreamWriterBuilder wBuilder;
root["message_id"] = message_id;
root["method"] = "publishers";
root["publishers_id"] = publisher_id;
root["to_id"] = to_id;
root["id"] = message_id;
return Json::writeString(wBuilder, root);
}
......@@ -89,7 +87,7 @@ namespace offcn
return false;
}
if (!root["method"] && !root["result_code"])
if (!root["method"])
{
error = "param error";
return false;
......@@ -109,21 +107,20 @@ namespace offcn
goto Error;
}
if (!root["message_id"] || !root["method"] || !root["from_id"])
if (!root["method"] || !root["id"])
{
error = "param error";
goto Error;
}
values["message_id"] = root["message_id"].asString();
values["method"] = root["method"].asString();
values["from_id"] = root["from_id"].asString();
values["id"] = root["id"].asString();
return true;
Error:
values["message_id"] = "";
values["method"] = "";
values["from_id"] = "";
values["id"] = "";
return false;
}
......@@ -205,8 +202,8 @@ namespace offcn
Json::Value root;
Json::StreamWriterBuilder wBuilder;
root["method"] = "response";
root["message_id"] = message_id;
root["method"] = "login";
root["id"] = message_id;
root["result_code"] = result_code;
return Json::writeString(wBuilder, root);
......
......@@ -4,7 +4,7 @@
namespace offcn
{
static const std::string kMqttUrl = "101.200.63.143";//"192.168.43.12";
static const std::string kMqttUrl = "test-mqq.offcncloud.com";//"192.168.43.12";
static const std::string kUserName = "admin";
static const std::string kPassWord = "public";
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment