add wisp support

This commit is contained in:
ading2210 2024-01-15 20:57:50 -05:00
parent 248d5b0161
commit 95121068bc
5 changed files with 17 additions and 5 deletions

3
.gitmodules vendored Normal file
View file

@ -0,0 +1,3 @@
[submodule "client/wisp_client"]
path = client/wisp_client
url = https://github.com/mercuryWorkshop/wisp-client-js

View file

@ -8,11 +8,12 @@ OUT_FILE="out/libcurl.js"
ES6_FILE="out/libcurl_module.mjs"
MODULE_FILE="out/emscripten_compiled.js"
WRAPPER_SOURCE="main.js"
WISP_CLIENT="wisp_client"
EXPORTED_FUNCS="_init_curl,_start_request,_request_loop"
RUNTIME_METHODS="addFunction,removeFunction,allocate,ALLOC_NORMAL"
COMPILER_OPTIONS="-o $MODULE_FILE -lcurl -lssl -lcrypto -lcjson -lz -lbrotlidec -lbrotlicommon -I $INCLUDE_DIR -L $LIB_DIR"
EMSCRIPTEN_OPTIONS="-lwebsocket.js -sASYNCIFY -sASYNCIFY_ONLY=start_request,request_loop -sALLOW_TABLE_GROWTH -sEXPORTED_FUNCTIONS=$EXPORTED_FUNCS -sEXPORTED_RUNTIME_METHODS=$RUNTIME_METHODS"
EMSCRIPTEN_OPTIONS="-lwebsocket.js -sASYNCIFY -sASYNCIFY_ONLY=start_request,request_loop -sASSERTIONS=1 -sALLOW_TABLE_GROWTH -sEXPORTED_FUNCTIONS=$EXPORTED_FUNCS -sEXPORTED_RUNTIME_METHODS=$RUNTIME_METHODS"
if [ "$1" = "release" ]; then
COMPILER_OPTIONS="-O3 -flto $COMPILER_OPTIONS"
@ -44,6 +45,11 @@ cp $WRAPPER_SOURCE $OUT_FILE
sed -i "/__emscripten_output__/r $MODULE_FILE" $OUT_FILE
rm $MODULE_FILE
#add wisp libraries
sed -i "s/new WebSocketConstructor/new WispWebSocket/" $OUT_FILE
sed -i "/__wisp_libraries__/r $WISP_CLIENT/polyfill.js" $OUT_FILE
sed -i "/__wisp_libraries__/r $WISP_CLIENT/wisp.js" $OUT_FILE
#generate es6 module
cp $OUT_FILE $ES6_FILE
sed -i 's/window.libcurl/export const libcurl/' $ES6_FILE

View file

@ -50,15 +50,14 @@ void request_loop() {
break;
}
//ensure we dont block the main thread
emscripten_sleep(0);
int msgq = 0;
curl_msg = curl_multi_info_read(multi_handle, &msgq);
if (curl_msg && curl_msg->msg == CURLMSG_DONE) {
finish_request(curl_msg);
}
//ensure we dont block the main thread
emscripten_sleep(0);
} while(request_active);
}

View file

@ -4,6 +4,9 @@ window.libcurl = (function() {
//emscripten compiled code is inserted here
/* __emscripten_output__ */
//wisp client code goes here
/* __wisp_libraries__ */
const websocket_url = `wss://${location.hostname}/ws/`;
const status_messages = {

1
client/wisp_client Submodule

@ -0,0 +1 @@
Subproject commit 0a80885090b6247f42bc07cc85b441d8d719f551