enable_panel_events
Enables or disables server-sent panel events for the current initialized session.
enable_panel_events(bool enable) toggles whether the current session receives
server-sent panel events. Event delivery itself happens through
set_panel_event_callback(...).
Function variants
blaze::status enable_panel_events(bool enable);
blaze::status enable_panel_events(bool enable, std::error_code& ec) noexcept;
void async_enable_panel_events(bool enable, std::function<void(std::error_code, blaze::status)> callback);
blaze::coro::awaitable_result<blaze::status> co_enable_panel_events(bool enable);Status vs error
The returned blaze::status is the API result. std::error_code and
std::system_error are used for transport/runtime failures only.
Parameters
Prop
Type
Result
blaze::statusUse direct comparison, for example:
if (status == blaze::status::ok) {
// success
}Recommended flow
Connect the session and complete initialize.
Register set_panel_event_callback(...) before enabling delivery, so the
first event is not missed.
Call enable_panel_events(true).
Handle incoming blaze::panel_event objects in your callback.
Call enable_panel_events(false) when you no longer want server-sent events.
Behavior notes
enable_panel_eventsrequires a connected and initialized session.- Authorization is not required. Panel events can be enabled before or after authorization.
enable = truestarts panel-event delivery for the current session.enable = falsestops panel-event delivery for the current session.- The operation is idempotent. Repeating the same target state is valid.
- If you do not set
set_panel_event_callback(...), subscription can still succeed, but incoming panel events are ignored by the library. - Subscription state is preserved across valid session resumption. A brand-new session still starts with panel events disabled.
- Event payload contracts are documented in Panel events overview and Event types.
- Sync overloads use the session timeout configured in the constructor or via
with_timeout(...). - Coroutine overloads are available only when the library is built with coroutine support.
Example
Compilation note
Synchronous and Asynchronous examples compile 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 << "Received panel event type: "
<< static_cast<unsigned int>(event.type) << '\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\n";
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;
}
std::cout << "Panel events disabled\n";
session.shutdown();
} catch (const std::system_error& e) {
print_error_code("Enable-panel-events failed", e.code());
return 1;
}
return 0;
}#include "blazeauth/api/api.hpp"
#include <future>
#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 << "Received panel event type: "
<< static_cast<unsigned int>(event.type) << '\n';
});
std::promise<int> completion;
std::future<int> result = completion.get_future();
session.async_connect([&session, &completion, websocket_api_key, client_id](std::error_code connect_ec, blaze::api_server server) {
if (connect_ec) {
print_error_code("Connect failed", connect_ec);
completion.set_value(1);
return;
}
std::cout << "Connected to server location: " << server.location << '\n';
session.async_initialize(websocket_api_key, client_id,
[&session, &completion](std::error_code init_ec, blaze::application app) {
if (init_ec) {
print_error_code("Initialize failed", init_ec);
completion.set_value(1);
return;
}
if (!app.good()) {
print_status("Initialize returned status", app.status);
completion.set_value(1);
return;
}
session.async_enable_panel_events(true,
[&session, &completion](std::error_code enable_ec, blaze::status enable_status) {
if (enable_ec) {
print_error_code("Enable-panel-events failed", enable_ec);
completion.set_value(1);
return;
}
if (enable_status != blaze::status::ok) {
print_status("Enable-panel-events returned status", enable_status);
completion.set_value(1);
return;
}
std::cout << "Panel events enabled\n";
session.async_enable_panel_events(false,
[&session, &completion](std::error_code disable_ec, blaze::status disable_status) {
if (disable_ec) {
print_error_code("Disable-panel-events failed", disable_ec);
completion.set_value(1);
return;
}
if (disable_status != blaze::status::ok) {
print_status("Disable-panel-events returned status", disable_status);
completion.set_value(1);
return;
}
std::cout << "Panel events disabled\n";
session.async_shutdown([&completion](std::error_code shutdown_ec) {
if (shutdown_ec) {
print_error_code("Shutdown failed", shutdown_ec);
completion.set_value(1);
return;
}
completion.set_value(0);
});
});
});
});
});
return result.get();
}Project must be built with C++20 support and with coroutine support available both in the language mode and in the standard library implementation for this example to compile correctly.
#include "blazeauth/api/api.hpp"
#include <future>
#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;
}
#if BLAZEAUTH_HAS_COROUTINES
blaze::coro::task<std::error_code> run_example(
blaze::session& session,
const std::string& websocket_api_key,
const std::string& client_id
) {
const auto [connect_ec, server] = co_await session.co_connect();
if (connect_ec) {
co_return connect_ec;
}
std::cout << "Connected to server location: " << server.location << '\n';
const auto [init_ec, app] = co_await session.co_initialize(websocket_api_key, client_id);
if (init_ec) {
co_return init_ec;
}
if (!app.good()) {
co_return blaze::make_error_code(app.status);
}
const auto [enable_ec, enable_status] = co_await session.co_enable_panel_events(true);
if (enable_ec) {
co_return enable_ec;
}
if (enable_status != blaze::status::ok) {
co_return blaze::make_error_code(enable_status);
}
std::cout << "Panel events enabled\n";
const auto [disable_ec, disable_status] = co_await session.co_enable_panel_events(false);
if (disable_ec) {
co_return disable_ec;
}
if (disable_status != blaze::status::ok) {
co_return blaze::make_error_code(disable_status);
}
std::cout << "Panel events disabled\n";
const auto [shutdown_ec] = co_await session.co_shutdown();
co_return shutdown_ec;
}
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 << "Received panel event type: "
<< static_cast<unsigned int>(event.type) << '\n';
});
std::promise<std::error_code> completion;
std::future<std::error_code> result = completion.get_future();
blaze::coro::co_spawn([&session, &completion, websocket_api_key, client_id]() -> blaze::coro::task<void> {
const std::error_code ec = co_await run_example(session, websocket_api_key, client_id);
completion.set_value(ec);
co_return;
}());
const std::error_code ec = result.get();
if (ec) {
print_error_code("Enable-panel-events failed", ec);
return 1;
}
return 0;
}
#else
int main() {
std::cout << "This example requires coroutine support in the Blazeauth library build.\n";
return 0;
}
#endifEnable-panel-events statuses
| Value | Status | Returned when |
|---|---|---|
1 | ok | Subscription state was updated successfully. |
Connection-level shutdowns
Normal enable-panel-events results are returned as blaze::status. The
websocket may still be closed by session-level guards around this operation:
| Close code | Meaning | When it can happen |
|---|---|---|
4200 | not_initialized | enable_panel_events was called before a successful initialize. |
4201 | rate_limited | Session or IP rate limiting closed the websocket around this operation. |