C++ APISession methods
set_panel_event_callback
Registers the local handler for server-sent panel events.
set_panel_event_callback installs the local handler for server-sent panel
events.
Function variants
void set_panel_event_callback(std::function<void(blaze::panel_event)> callback);Runs on the library I/O thread
Do not call synchronous blaze::session methods from this callback. If you
need to continue work from here, stay on async API or hand control back to
your own thread/executor.
Callback signature
void(blaze::panel_event event)Callback payload
struct panel_event {
blaze::event_type type;
std::unordered_map<std::string, std::string> content;
};Prop
Type
Behavior notes
- This method only installs the local event handler.
- To actually receive panel events from the server, also call
enable_panel_events(true). - If the callback is not set, panel-event subscription can still succeed, but incoming events are ignored by the library.
- The callback is invoked only for successfully parsed panel events.
- Once registered, this callback stays attached to the same
blaze::sessionobject until you replace or clear it. - Protocol/parse failures in the panel-event receive path do not invoke this callback. They surface through
set_exception_callback(...)and then session shutdown. - If panel-event subscription was active before valid session resumption, delivery continues after resumption on the same session.
- Event types and payloads are documented in Panel events overview and Event types.
- Pass
nullptror an emptystd::functionto clear the callback.
Example
Compilation note
This example compiles in the same form from C++14 to C++26.
#include "blazeauth/api/api.hpp"
#include <iostream>
#include <string>
#include <system_error>
void print_error_code(const std::string& context, const std::error_code& ec) {
std::cout << context << ": " << ec.message() << " ("
<< ec.value() << " : " << ec.category().name() << ")\n";
}
std::string read_line(const std::string& label) {
std::string value;
std::cout << label << ": ";
std::getline(std::cin, value);
return value;
}
void print_status(const std::string& context, blaze::status status) {
std::cout << context << ": "
<< static_cast<unsigned int>(status)
<< " (" << blaze::to_string(status) << ")\n";
}
int main() {
const std::string websocket_api_key = read_line("Websocket API key");
const std::string client_id = read_line("Client ID");
blaze::session session;
session.set_panel_event_callback([](blaze::panel_event event) {
std::cout << "Panel event type: "
<< static_cast<unsigned int>(event.type) << '\n';
for (const auto& entry : event.content) {
std::cout << " " << entry.first << " = " << entry.second << '\n';
}
});
try {
const blaze::api_server server = session.connect();
std::cout << "Connected to server location: " << server.location << '\n';
const blaze::application app = session.initialize(websocket_api_key, client_id);
if (!app.good()) {
print_status("Initialize returned status", app.status);
return 1;
}
const blaze::status enable_status = session.enable_panel_events(true);
if (enable_status != blaze::status::ok) {
print_status("Enable-panel-events returned status", enable_status);
return 1;
}
std::cout << "Panel events enabled. Press Enter to stop listening.\n";
std::string line;
std::getline(std::cin, line);
const blaze::status disable_status = session.enable_panel_events(false);
if (disable_status != blaze::status::ok) {
print_status("Disable-panel-events returned status", disable_status);
return 1;
}
session.shutdown();
} catch (const std::system_error& e) {
print_error_code("Panel-event flow failed", e.code());
return 1;
}
return 0;
}