|
|
@ -13,17 +13,24 @@ void IflytopFrontEndService::initialize(string ip) { |
|
|
|
logger->info("IflytopFrontEndService initialize {}:{}", ip, 19001); |
|
|
|
logger->info("IflytopFrontEndService initialize {}:{}", ip, 19002); |
|
|
|
|
|
|
|
m_work_queue.reset(new WorkQueue("IflytopFrontEndService-WQ")); |
|
|
|
m_work_queue->startWork(); |
|
|
|
|
|
|
|
m_server.reset(new WebSocketServer(19001, ip)); |
|
|
|
m_server->setOnConnectionCallback([this](weak_ptr<WebSocket> webSocket, shared_ptr<ConnectionState> connectionState) { |
|
|
|
logger->info("Remote ip: {}", connectionState->getRemoteIp()); |
|
|
|
auto ws = webSocket.lock(); |
|
|
|
if (!ws) return; |
|
|
|
ws->setOnMessageCallback([this, webSocket, connectionState](const ix::WebSocketMessagePtr& msg) { |
|
|
|
try { |
|
|
|
onMessageCallback(webSocket, connectionState, msg); |
|
|
|
} catch (const std::exception& e) { |
|
|
|
logger->error("catch exception,onMessageCallback error: {}", e.what()); |
|
|
|
} |
|
|
|
shared_ptr<ix::WebSocketMessage> messageSPtr = make_shared<ix::WebSocketMessage>(*msg); |
|
|
|
|
|
|
|
m_work_queue->enQueue([this, webSocket, connectionState, messageSPtr]() { |
|
|
|
try { |
|
|
|
onMessageCallback(webSocket, connectionState, messageSPtr); |
|
|
|
} catch (const std::exception& e) { |
|
|
|
logger->error("catch exception,onMessageCallback error: {}", e.what()); |
|
|
|
} |
|
|
|
}); |
|
|
|
}); |
|
|
|
}); |
|
|
|
|
|
|
@ -102,7 +109,8 @@ void IflytopFrontEndService::sendReport(json& report) { |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
void IflytopFrontEndService::onMessageCallback(weak_ptr<WebSocket> webSocket, shared_ptr<ConnectionState> connectionState, const ix::WebSocketMessagePtr& msg) { |
|
|
|
void IflytopFrontEndService::onMessageCallback(weak_ptr<WebSocket> webSocket, shared_ptr<ConnectionState> connectionState, |
|
|
|
shared_ptr<ix::WebSocketMessage> msg) { |
|
|
|
if (msg->type == ix::WebSocketMessageType::Open) { |
|
|
|
logger->info("New connection"); |
|
|
|
logger->info("id : {}", connectionState->getId()); |
|
|
@ -125,7 +133,7 @@ void IflytopFrontEndService::onMessageCallback(weak_ptr<WebSocket> webSocket, sh |
|
|
|
onDisconnect(webSocket, msg); |
|
|
|
} |
|
|
|
} |
|
|
|
void IflytopFrontEndService::processRxMessage(weak_ptr<WebSocket> webSocket, const ix::WebSocketMessagePtr& msg) { |
|
|
|
void IflytopFrontEndService::processRxMessage(weak_ptr<WebSocket> webSocket, shared_ptr<ix::WebSocketMessage> msg) { |
|
|
|
if (msg->binary) { |
|
|
|
logger->warn("receive binary message,ignore"); |
|
|
|
return; |
|
|
|