diff --git a/.gitmodules b/.gitmodules new file mode 100644 index 0000000..ae9314b --- /dev/null +++ b/.gitmodules @@ -0,0 +1,3 @@ +[submodule "client/wisp_client"] + path = client/wisp_client + url = https://github.com/mercuryWorkshop/wisp-client-js diff --git a/client/build.sh b/client/build.sh index 6c1d4c6..1523b70 100755 --- a/client/build.sh +++ b/client/build.sh @@ -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 \ No newline at end of file diff --git a/client/main.c b/client/main.c index a78a93d..b43b265 100644 --- a/client/main.c +++ b/client/main.c @@ -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); } diff --git a/client/main.js b/client/main.js index dd09398..2a5d10b 100644 --- a/client/main.js +++ b/client/main.js @@ -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 = { diff --git a/client/wisp_client b/client/wisp_client new file mode 160000 index 0000000..0a80885 --- /dev/null +++ b/client/wisp_client @@ -0,0 +1 @@ +Subproject commit 0a80885090b6247f42bc07cc85b441d8d719f551