don't hardcode websocket url

This commit is contained in:
ading2210 2024-01-07 19:57:44 -05:00
parent 663f31cd6e
commit 57d1245c40
2 changed files with 7 additions and 5 deletions

View file

@ -10,7 +10,7 @@ OUT_FILE="out/libcurl.js"
EXPORTED_FUNCS="_load_certs,_perform_request"
RUNTIME_METHODS="addFunction,removeFunction,allocate,ALLOC_NORMAL"
COMPILER_OPTIONS="-o $OUT_FILE -lcurl -lssl -lcrypto -lcjson -I $INCLUDE_DIR -L $LIB_DIR"
EMSCRIPTEN_OPTIONS="-lwebsocket.js -sWEBSOCKET_URL=wss://debug.ading.dev/ws -sSINGLE_FILE -sASYNCIFY -sALLOW_TABLE_GROWTH -sEXPORTED_FUNCTIONS=$EXPORTED_FUNCS -sEXPORTED_RUNTIME_METHODS=$RUNTIME_METHODS"
EMSCRIPTEN_OPTIONS="-lwebsocket.js -sSINGLE_FILE -sASYNCIFY -sALLOW_TABLE_GROWTH -sEXPORTED_FUNCTIONS=$EXPORTED_FUNCS -sEXPORTED_RUNTIME_METHODS=$RUNTIME_METHODS"
tools/all_deps.sh
tools/generate_cert.sh
@ -25,4 +25,3 @@ $COMPILE_CMD
#patch the output to work around some emscripten bugs
sed -i 's/err("__syscall_getsockname " \?+ \?fd);//' $OUT_FILE
sed -i 's/function _emscripten_console_error(str) {/& if(UTF8ToString(str).endsWith("__syscall_setsockopt\\n")) return;/' $OUT_FILE
mv out/libcurl.data ./

View file

@ -1,4 +1,3 @@
const cacert_path = "./out/cacert.pem";
const websocket_url = `wss://${location.hostname}/ws`;
const status_messages = {
@ -218,14 +217,18 @@ function libcurl_fetch(url, params={}) {
})
}
function set_websocket_url(url) {
Module.websocket.url = url;
}
async function main() {
console.log("emscripten module loaded");
_load_certs();
set_websocket_url(websocket_url);
console.log(await libcurl_fetch("https://httpbin.org/anything"));
}
window.onload = () => {
console.log("page loaded, waiting for emscripten module load");
//Module.websocket.url = websocket_url;
Module.onRuntimeInitialized = main;
};