void Client::onAnnounceState(void* sender, TransactionState& state, const TransactionState&) { TraceL << "On announce response: " << state << endl; auto transaction = reinterpret_cast<sockio::Transaction*>(sender); switch (state.id()) { case TransactionState::Success: try { json::Value data = transaction->response().json(); //[(unsigned)0]; _announceStatus = data["status"].asInt(); if (_announceStatus != 200) throw std::runtime_error(data["message"].asString()); _ourID = data["data"]["id"].asString(); // Address(); if (_ourID.empty()) throw std::runtime_error("Invalid announce response."); // Set our local peer data from the response or fail. onPresenceData(data["data"], true); // Notify the outside application of the response // status before we transition the client state. Announce.emit(_announceStatus); // Transition to Online state. onOnline(); // setState(this, sockio::ClientState::Online); // Broadcast a presence probe to our network. sendPresence(true); } catch (std::exception& exc) { // Set the error message and close the connection. setError("Announce failed: " + std::string(exc.what())); } break; case TransactionState::Failed: Announce.emit(_announceStatus); setError("Announce failed"); break; } }
void onTransactionStateChanged(void* sender, TransactionState& state, const TransactionState&) { Log("debug", this) << "Transaction State Changed: " << state.toString() << endl; SocketIO::Transaction* transaction = reinterpret_cast<SocketIO::Transaction*>(sender); switch (state.id()) { case TransactionState::Running: break; case TransactionState::Success: break; case TransactionState::Cancelled: break; case TransactionState::Failed: break; } };