12#include <emscripten.h>
13#include <emscripten/val.h>
19#include "platforms/wasm/js_fetch.h"
24#if defined(FASTLED_HAS_NETWORKING) && !defined(FL_IS_WASM)
29 #include "platforms/win/socket_win.h"
31 #include "platforms/posix/socket_posix.h"
51 ::fl::wasm_fetch.get(url).response(callback);
63 fl::string fetch_url = request.url().empty() ? url : request.url();
66 auto wasm_request = ::fl::WasmFetchRequest(fetch_url);
70 wasm_request.response([promise](
const Response& resp)
mutable {
72 if (promise.valid()) {
73 promise.complete_with_value(resp);
82#elif defined(FASTLED_HAS_NETWORKING)
86 #define SOCKET_ERROR_WOULD_BLOCK WSAEWOULDBLOCK
87 #define SOCKET_ERROR_IN_PROGRESS WSAEINPROGRESS
89 #define SOCKET_ERROR_WOULD_BLOCK EWOULDBLOCK
90 #define SOCKET_ERROR_IN_PROGRESS EINPROGRESS
353 .then([callback](
const Response& resp) {
356 .catch_([callback](
const fl::task::Error& err) {
358 Response resp(500,
"Internal Server Error");
379 .
then([fetch_req, task_ptr]() {
384 if (fetch_req->is_done()) {
388 .catch_([promise](
const fl::task::Error& e)
mutable {
390 if (promise.valid() && !promise.is_completed()) {
391 promise.complete_with_error(e);
406 Response resp(501,
"Not Implemented");
407 resp.
set_text(
"HTTP fetch not supported on this platform");
414 FL_WARN(
"HTTP fetch is not supported on this platform. URL: " <<
url);
415 Response error_response(501,
"Not Implemented");
416 error_response.
set_body(
"HTTP fetch is not available on this platform.");
465 if (promise.valid()) {
500 if (promise.valid() && !promise.is_completed()) {
517 const auto& opts = request.options();
518 get_request.
timeout(opts.timeout_ms);
519 for (
const auto& header : opts.headers) {
520 get_request.
header(header.first, header.second);
522 if (!opts.body.empty()) {
523 get_request.
body(opts.body);
534 const auto& opts = request.options();
535 post_request.
timeout(opts.timeout_ms);
536 for (
const auto& header : opts.headers) {
537 post_request.
header(header.first, header.second);
539 if (!opts.body.empty()) {
540 post_request.
body(opts.body);
551 const auto& opts = request.options();
552 put_request.
timeout(opts.timeout_ms);
553 for (
const auto& header : opts.headers) {
554 put_request.
header(header.first, header.second);
556 if (!opts.body.empty()) {
557 put_request.
body(opts.body);
568 const auto& opts = request.options();
569 delete_request.
timeout(opts.timeout_ms);
570 for (
const auto& header : opts.headers) {
571 delete_request.
header(header.first, header.second);
573 if (!opts.body.empty()) {
574 delete_request.
body(opts.body);
585 const auto& opts = request.options();
586 head_request.
timeout(opts.timeout_ms);
587 for (
const auto& header : opts.headers) {
588 head_request.
header(header.first, header.second);
590 if (!opts.body.empty()) {
591 head_request.
body(opts.body);
602 const auto& opts = request.options();
603 options_request.
timeout(opts.timeout_ms);
604 for (
const auto& header : opts.headers) {
605 options_request.
header(header.first, header.second);
607 if (!opts.body.empty()) {
608 options_request.
body(opts.body);
619 const auto& opts = request.options();
620 patch_request.
timeout(opts.timeout_ms);
621 for (
const auto& header : opts.headers) {
622 patch_request.
header(header.first, header.second);
624 if (!opts.body.empty()) {
625 patch_request.
body(opts.body);
static void removeListener(Listener *listener) FL_NO_EXCEPT
static void addListener(Listener *listener, int priority=0) FL_NO_EXCEPT
static T & instance() FL_NO_EXCEPT
FetchEngineListener() FL_NO_EXCEPT
~FetchEngineListener() FL_NO_EXCEPT override
void onEndFrame() FL_NO_EXCEPT override
void cleanup_completed_promises() FL_NO_EXCEPT
size_t active_task_count() const FL_NO_EXCEPT override
Get number of active tasks (for debugging/monitoring)
fl::size active_requests() const FL_NO_EXCEPT
fl::unique_ptr< FetchEngineListener > mEngineListener
void register_promise(const fl::task::Promise< Response > &promise) FL_NO_EXCEPT
fl::vector< fl::task::Promise< Response > > mActivePromises
bool has_active_tasks() const FL_NO_EXCEPT override
Check if this runner has active tasks.
static FetchManager & instance() FL_NO_EXCEPT
void update() FL_NO_EXCEPT override
Update this runner (called during task pumping)
Internal fetch manager for promise tracking.
FetchOptions & timeout(int timeout_ms) FL_NO_EXCEPT
Set timeout in milliseconds.
FetchOptions & header(const fl::string &name, const fl::string &value) FL_NO_EXCEPT
Add header.
FetchOptions & body(const fl::string &data) FL_NO_EXCEPT
Set request body.
Fetch options builder (fluent interface)
void set_body(const fl::string &body) FL_NO_EXCEPT
fl::json parse_json_body() const FL_NO_EXCEPT
Parse JSON from response body with error handling.
void set_text(const fl::string &body) FL_NO_EXCEPT
bool is_json() const FL_NO_EXCEPT
Check if response appears to contain JSON content.
fl::json json() const FL_NO_EXCEPT
Response body parsed as JSON (JavaScript-like API)
fl::optional< fl::json > mCachedJson
HTTP response class (unified interface)
static constexpr fl::size npos
void register_runner(Runner *r) FL_NO_EXCEPT
Register a runner.
void unregister_runner(Runner *r) FL_NO_EXCEPT
Unregister a runner.
static Executor & instance() FL_NO_EXCEPT
Handle & then(function< void()> on_then) FL_NO_EXCEPT
Sets the callback invoked when the task runs successfully.
static Promise< T > resolve(const T &value) FL_NO_EXCEPT
Create a resolved Promise with value.
static Promise< T > create() FL_NO_EXCEPT
Create a pending Promise.
Promise class that provides fluent .then() and .catch_() semantics This is a lightweight wrapper arou...
static Scheduler & instance() FL_NO_EXCEPT
int add_task(Handle t) FL_NO_EXCEPT
void push_back(const T &value) FL_NO_EXCEPT
Task executor — runs registered task runners and manages the run loop.
Unified HTTP fetch API for FastLED (cross-platform)
fl::enable_if<!fl::is_array< T >::value, unique_ptr< T > >::type make_unique(Args &&... args) FL_NO_EXCEPT
shared_ptr< T > make_shared(Args &&... args) FL_NO_EXCEPT
constexpr remove_reference< T >::type && move(T &&t) FL_NO_EXCEPT
void fetch_update() FL_NO_EXCEPT
Legacy manual update for fetch promises (use fl::task::run() for new code)
fl::task::Promise< Response > fetch_put(const fl::string &url, const FetchOptions &request) FL_NO_EXCEPT
HTTP PUT request.
fl::task::Promise< Response > fetch_patch(const fl::string &url, const FetchOptions &request) FL_NO_EXCEPT
HTTP PATCH request.
void fetch(const fl::string &url, const FetchCallback &callback) FL_NO_EXCEPT
Make an HTTP GET request (cross-platform, backward compatible)
fl::size fetch_active_requests() FL_NO_EXCEPT
Get number of active requests.
fl::function< void(const Response &)> FetchCallback
Callback type for simple fetch responses (backward compatible)
fl::task::Promise< Response > fetch_head(const fl::string &url, const FetchOptions &request) FL_NO_EXCEPT
HTTP HEAD request.
fl::task::Promise< Response > execute_fetch_request(const fl::string &url, const FetchOptions &request) FL_NO_EXCEPT
Internal helper to execute a fetch request and return a promise.
fl::task::Promise< Response > fetch_http_options(const fl::string &url, const FetchOptions &request) FL_NO_EXCEPT
HTTP OPTIONS request.
fl::task::Promise< Response > fetch_post(const fl::string &url, const FetchOptions &request) FL_NO_EXCEPT
HTTP POST request.
fl::task::Promise< Response > fetch_request(const fl::string &url, const RequestOptions &options) FL_NO_EXCEPT
Generic request with options (like fetch(url, options))
fl::task::Promise< Response > fetch_get(const fl::string &url, const FetchOptions &request) FL_NO_EXCEPT
HTTP GET request.
fl::task::Promise< Response > fetch_delete(const fl::string &url, const FetchOptions &request) FL_NO_EXCEPT
HTTP DELETE request.
void run(fl::u32 microseconds, ExecFlags flags) FL_NO_EXCEPT
Run selected task subsystems.
Handle every_ms(int interval_ms) FL_NO_EXCEPT
Creates a task that runs at a fixed millisecond interval.
u8 u8 fract8 blur_amount FL_NO_EXCEPT
Base definition for an LED controller.
Request options (matches JavaScript fetch RequestInit)