Use EMSCRIPTEN_FETCH_SYNCHRONOUS in PocketPy custom module to send HTTP(s) requests from inside WASM
Tested with PocketPy v2.0.0, Emscripten v3.1.64.
- Open this repo in devcontainer, e.g. using Github Codespaces. Type or copy/paste following commands to devcontainer's terminal.
cd
into the folder of this example:
cd browser-sync-xhr
- Download
pocketpy.c
andpocketpy.h
from release intopocketpy
subfolder. These two files are enough to embed PocketPy into example program:
curl -L --compressed --output-dir pocketpy --create-dirs -O "https://github.com/pocketpy/pocketpy/releases/download/v2.0.0/pocketpy.{c,h}"
- Compile the example using Emscripten:
emcc -I pocketpy pocketpy/pocketpy.c -s -Os -s ALLOW_MEMORY_GROWTH=1 -s FETCH=1 --proxy-to-worker -o main.js main.c
This command will output main.wasm
, main.js
, and main.worker.js
.
- Run simple HTTP server to temporarily publish project to Web:
python3 -m http.server
Codespace will show you "Open in Browser" button. Just click that button or obtain web address from "Forwarded Ports" tab.
- As
index.html
, JS files, and a 332k-sizedmain.wasm
are loaded into browser, refer to browser developer console to see the results.
Perform your own experiments if desired.