mirror of
https://github.com/ading2210/libcurl.js.git
synced 2025-05-12 22:10:01 -04:00
add version reporting
This commit is contained in:
parent
3c517bbaf5
commit
a4c075b497
10 changed files with 71 additions and 11 deletions
|
@ -75,6 +75,10 @@ cp $JAVSCRIPT_DIR/main.js $OUT_FILE
|
|||
sed -i "/__emscripten_output__/r $MODULE_FILE" $OUT_FILE
|
||||
rm $MODULE_FILE
|
||||
|
||||
#set version number
|
||||
VERSION=$(cat package.json | jq -r '.version')
|
||||
sed -i "s/__library_version__/$VERSION/" $OUT_FILE
|
||||
|
||||
#add extra libraries
|
||||
sed -i "/__extra_libraries__/r $WISP_CLIENT/polyfill.js" $OUT_FILE
|
||||
sed -i "/__extra_libraries__/r $WISP_CLIENT/wisp.js" $OUT_FILE
|
||||
|
|
|
@ -3,6 +3,8 @@ start_request
|
|||
tick_request
|
||||
active_requests
|
||||
|
||||
get_version
|
||||
|
||||
recv_from_websocket
|
||||
send_to_websocket
|
||||
close_websocket
|
||||
|
|
|
@ -33,12 +33,14 @@ var websocket_url = null;
|
|||
var event_loop = null;
|
||||
var active_requests = 0;
|
||||
var wasm_ready = false;
|
||||
var version_dict = null;
|
||||
const libcurl_version = "__library_version__";
|
||||
|
||||
function check_loaded() {
|
||||
function check_loaded(check_websocket) {
|
||||
if (!wasm_ready) {
|
||||
throw new Error("wasm not loaded yet, please call libcurl.load_wasm first");
|
||||
}
|
||||
if (!websocket_url) {
|
||||
if (!websocket_url && check_websocket) {
|
||||
throw new Error("websocket proxy url not set, please call libcurl.set_websocket");
|
||||
}
|
||||
}
|
||||
|
@ -258,7 +260,7 @@ function perform_request_async(url, params, body) {
|
|||
}
|
||||
|
||||
async function libcurl_fetch(url, params={}) {
|
||||
check_loaded();
|
||||
check_loaded(true);
|
||||
let body = await create_options(params);
|
||||
return await perform_request_async(url, params, body);
|
||||
}
|
||||
|
@ -273,6 +275,18 @@ function set_websocket_url(url) {
|
|||
else Module.websocket.url = url;
|
||||
}
|
||||
|
||||
function get_version() {
|
||||
if (!wasm_ready) return null;
|
||||
if (version_dict) return version_dict;
|
||||
|
||||
let version_ptr = _get_version();
|
||||
let version_str = UTF8ToString(version_ptr);
|
||||
_free(version_ptr);
|
||||
version_dict = JSON.parse(version_str);
|
||||
version_dict.lib = libcurl_version;
|
||||
return version_dict;
|
||||
}
|
||||
|
||||
function main() {
|
||||
wasm_ready = true;
|
||||
_init_curl();
|
||||
|
@ -295,10 +309,13 @@ return {
|
|||
load_wasm: load_wasm,
|
||||
wisp: _wisp_connections,
|
||||
WebSocket: CurlWebSocket,
|
||||
|
||||
get version() {return get_version()},
|
||||
get stdout() {return out},
|
||||
set stdout(callback) {out = callback},
|
||||
get stderr() {return err},
|
||||
set stderr(callback) {err = callback}
|
||||
set stderr(callback) {err = callback},
|
||||
get ready() {return wasm_ready}
|
||||
}
|
||||
|
||||
})()
|
|
@ -3,7 +3,7 @@
|
|||
class CurlWebSocket extends EventTarget {
|
||||
constructor(url, protocols=[]) {
|
||||
super();
|
||||
check_loaded();
|
||||
check_loaded(true);
|
||||
if (!url.startsWith("wss://") && !url.startsWith("ws://")) {
|
||||
throw new SyntaxError("invalid url");
|
||||
}
|
||||
|
|
|
@ -1,5 +1,36 @@
|
|||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
#include <string.h>
|
||||
|
||||
#include "curl/curl.h"
|
||||
#include "cjson/cJSON.h"
|
||||
|
||||
int starts_with(const char *a, const char *b) {
|
||||
return strncmp(a, b, strlen(b)) == 0;
|
||||
}
|
||||
|
||||
char* get_version() {
|
||||
struct curl_version_info_data *version_info = curl_version_info(CURLVERSION_NOW);
|
||||
cJSON* version_json = cJSON_CreateObject();
|
||||
|
||||
cJSON* protocols_array = cJSON_CreateArray();
|
||||
const char *const *protocols = version_info->protocols;
|
||||
for (; *protocols != NULL; protocols++) {
|
||||
cJSON* protocol_item = cJSON_CreateString(*protocols);
|
||||
cJSON_AddItemToArray(protocols_array, protocol_item);
|
||||
}
|
||||
|
||||
cJSON* curl_version_item = cJSON_CreateString(version_info->version);
|
||||
cJSON* ssl_version_item = cJSON_CreateString(version_info->ssl_version);
|
||||
cJSON* brotli_version_item = cJSON_CreateString(version_info->brotli_version);
|
||||
cJSON* nghttp2_version_item = cJSON_CreateString(version_info->nghttp2_version);
|
||||
|
||||
cJSON_AddItemToObject(version_json, "curl", curl_version_item);
|
||||
cJSON_AddItemToObject(version_json, "ssl", ssl_version_item);
|
||||
cJSON_AddItemToObject(version_json, "brotli", brotli_version_item);
|
||||
cJSON_AddItemToObject(version_json, "nghttp2", nghttp2_version_item);
|
||||
cJSON_AddItemToObject(version_json, "protocols", protocols_array);
|
||||
|
||||
char* version_json_str = cJSON_Print(version_json);
|
||||
return version_json_str;
|
||||
}
|
|
@ -1,6 +1,6 @@
|
|||
{
|
||||
"name": "libcurl.js",
|
||||
"version": "0.2.0",
|
||||
"version": "0.3.0",
|
||||
"description": "An experimental port of libcurl to WebAssembly for use in the browser.",
|
||||
"main": "libcurl.mjs",
|
||||
"scripts": {
|
||||
|
|
|
@ -3,8 +3,11 @@
|
|||
#publish libcurl.js as an npm package
|
||||
|
||||
./build.sh all
|
||||
tests/run.sh
|
||||
|
||||
cp package.json out
|
||||
cp ../README.md out
|
||||
cp ../LICENSE out
|
||||
|
||||
cd out
|
||||
npm publish
|
Loading…
Add table
Add a link
Reference in a new issue