'use strict'; import { AbortController, AbortSignal } from './AbortController'; import { Blob } from './Blob'; import { DOMException } from './DOMException'; import { FileReader } from './FileReader'; import { FormData } from './FormData'; import { WebSocket } from './WebSocket'; import { XMLHttpRequest } from './XMLHttpRequest'; /** * Installs the networking API (`fetch`, `XMLHttpRequest` and their supporting * globals) on a Worklet Runtime. The native `__workletsNetworking` binding is * installed by C++ only on Worklet Runtimes in Bundle Mode, so this function is * a no-op anywhere else. * * All polyfills must be in place before `whatwg-fetch` is required because it * feature-detects them at module scope. */ let installed = false; export function installNetworking() { if (globalThis.__workletsNetworking === undefined || installed) { return; } installed = true; const global = globalThis as unknown as Record; global.XMLHttpRequest ??= XMLHttpRequest; global.Blob ??= Blob; global.FileReader ??= FileReader; global.FormData ??= FormData; global.DOMException ??= DOMException; global.AbortController ??= AbortController; global.AbortSignal ??= AbortSignal; global.WebSocket ??= WebSocket; require('whatwg-fetch'); }