-
Notifications
You must be signed in to change notification settings - Fork 9
Home
SMJSGaming edited this page Aug 5, 2024
·
3 revisions
Since Alpha.3 GDIntercept comes bundled with an API, this allows you to add event listeners for requests and responses with filter options and some useful tools.
To make a simple request and response event listener just do the following:
#include <smjs.gdintercept/proxy/Proxy.hpp>
using namespace proxy::prelude;
$execute {
new EventListener([=](const RequestEvent* event) {
log::info("Sending request to: {}", event->getRequest().getURL().getRaw());
return ListenerResult::Propagate;
}, RequestFilter());
new EventListener([=](const ResponseEvent* event) {
log::info("Response received with status: {}", event->getResponse().getStatusCode());
return ListenerResult::Propagate;
}, ResponseFilter());
}
You can also link your events to nodes to make use of the context:
#include <smjs.gdintercept/proxy/Proxy.hpp>
using namespace proxy::prelude;
class MyNode : public CCNode {
bool init() override {
// Replace [=] with [=, this] to access the context of the node
this->template addEventListener<RequestFilter>([=](const RequestEvent* event) {
log::info("Sending request to: {}", event->getRequest().getURL().getRaw());
return ListenerResult::Propagate;
});
this->template addEventListener<ResponseFilter>([=](const ResponseEvent* event) {
log::info("Response received with status: {}", event->getResponse().getStatusCode());
return ListenerResult::Propagate;
});
return true;
}
};