예제 #1
0
 void on_message(websocketpp::connection_hdl, client::message_ptr msg) {
     if (msg->get_opcode() == websocketpp::frame::opcode::text) {
         m_messages.push_back("<< " + msg->get_payload());
     } else {
         m_messages.push_back("<< " + websocketpp::utility::to_hex(msg->get_payload()));
     }
 }
예제 #2
0
 void on_message(websocketpp::connection_hdl hdl, Client::message_ptr msg)
 {
     const auto m = fromJSON<Message>(msg->get_payload());
     for(const auto update: m.update) {
         manager_.addOrUpdate(update);
     }
     for(const auto id: m.removal) {
         manager_.remove(id);
     }
 }
예제 #3
0
파일: ddp.cpp 프로젝트: GbalsaC/meteorpp
 void ddp::on_message(client::message_ptr const& msg)
 {
     auto const payload = nlohmann::json::parse(msg->get_payload());
     auto const message = payload["msg"];
     if(message.is_null()) {
         // ignore
     } else if(message == "connected") {
         _session = payload["session"].get<std::string>();
         _connected_sig(_session);
     } else if(message == "failed") {
         // throw error
     } else if(message == "ping") {
         nlohmann::json response;
         response["msg"] = "pong";
         response["id"] = payload["id"];
         _conn->send(response.dump(), websocketpp::frame::opcode::text);
     } else if(message == "error") {
         // throw error
     } else if(message == "nosub") {
         // throw error
     } else if(message == "added") {
         nlohmann::json const& fields = payload["fields"];
         _doc_added_sig(payload["collection"], payload["id"], !fields.is_null() ? fields : nlohmann::json::object());
     } else if(message == "changed") {
         nlohmann::json const& fields = payload["fields"];
         nlohmann::json const& cleared = payload["cleared"];
         _doc_changed_sig(payload["collection"], payload["id"], !fields.is_null() ? fields : nlohmann::json::object(), !cleared.is_null() ? cleared : nlohmann::json::array());
     } else if(message == "removed") {
         _doc_removed_sig(payload["collection"], payload["id"]);
     } else if(message == "ready") {
         for(std::string const& id: payload["subs"]) {
             _ready_sig(id);
         }
     } else if(message == "updated") {
         for(std::string const& id: payload["methods"]) {
             _method_updated_sig(id);
         }
     } else if(message == "result") {
         _method_result_sig(payload["id"], payload["result"], payload["error"]);
     }
 }
    /**
     * This method is used to receive the job translation messages
     * @param hdl the connection handler
     * @param msg the message
     */
    inline void on_message(websocketpp::connection_hdl hdl, client::message_ptr msg) {
        //Create a new incoming message
        incoming_msg * json_msg = new incoming_msg();

        //Try parsing the incoming message
        try {
            //Get the message string
            string msg_str = msg->get_payload();

            LOG_DEBUG << "Got translation server message: " << msg_str << END_LOG;

            //De-serialize the message from string
            json_msg->de_serialize(msg_str);

            //Set the message to the client
            m_notify_new_msg(json_msg);
        } catch (std::exception & ex) {
            LOG_ERROR << ex.what() << END_LOG;
            //Delete the message as it was not set
            delete json_msg;
        }
    }