mirror of
https://github.com/ClassiCube/ClassiCube.git
synced 2025-09-19 12:35:52 -04:00
Webclient: Call Http_OnFinishedAsync/Http_OnUpdateProgress directly instead of using dyncall, addresses #697
This commit is contained in:
parent
b4ec7a31e2
commit
60bf70c13c
21
src/Http.c
21
src/Http.c
@ -319,12 +319,12 @@ cc_bool Http_DescribeError(cc_result res, cc_string* dst) { return false; }
|
|||||||
/* web browsers do caching already, so don't need last modified/etags */
|
/* web browsers do caching already, so don't need last modified/etags */
|
||||||
static void Http_AddHeader(struct HttpRequest* req, const char* key, const cc_string* value) { }
|
static void Http_AddHeader(struct HttpRequest* req, const char* key, const cc_string* value) { }
|
||||||
|
|
||||||
static void OnUpdateProgress(int read, int total) {
|
EMSCRIPTEN_KEEPALIVE void Http_OnUpdateProgress(int read, int total) {
|
||||||
if (!total) return;
|
if (!total) return;
|
||||||
http_curProgress = (int)(100.0f * read / total);
|
http_curProgress = (int)(100.0f * read / total);
|
||||||
}
|
}
|
||||||
|
|
||||||
static void OnFinishedAsync(void* data, int len, int status) {
|
EMSCRIPTEN_KEEPALIVE void Http_OnFinishedAsync(void* data, int len, int status) {
|
||||||
struct HttpRequest* req = &http_curRequest;
|
struct HttpRequest* req = &http_curRequest;
|
||||||
req->data = data;
|
req->data = data;
|
||||||
req->size = len;
|
req->size = len;
|
||||||
@ -347,16 +347,13 @@ static void Http_DownloadAsync(struct HttpRequest* req) {
|
|||||||
Http_BeginRequest(req, &url);
|
Http_BeginRequest(req, &url);
|
||||||
Platform_EncodeUtf8(urlStr, &url);
|
Platform_EncodeUtf8(urlStr, &url);
|
||||||
|
|
||||||
|
/* onFinished = FUNC(data, len, status) */
|
||||||
|
/* onProgress = FUNC(read, total) */
|
||||||
EM_ASM_({
|
EM_ASM_({
|
||||||
var url = UTF8ToString($0);
|
var url = UTF8ToString($0);
|
||||||
var reqMethod = $1 == 1 ? 'HEAD' : 'GET';
|
var reqMethod = $1 == 1 ? 'HEAD' : 'GET';
|
||||||
|
var onFinished = Module["_Http_OnFinishedAsync"];
|
||||||
var onFinished = function(data, len, status) {
|
var onProgress = Module["_Http_OnUpdateProgress"];
|
||||||
Module['dynCall_viii']($2, data, len, status);
|
|
||||||
};
|
|
||||||
var onProgress = function(read, total) {
|
|
||||||
Module['dynCall_vii']($3, read, total);
|
|
||||||
};
|
|
||||||
|
|
||||||
var xhr = new XMLHttpRequest();
|
var xhr = new XMLHttpRequest();
|
||||||
xhr.open(reqMethod, url);
|
xhr.open(reqMethod, url);
|
||||||
@ -383,7 +380,7 @@ static void Http_DownloadAsync(struct HttpRequest* req) {
|
|||||||
xhr.onprogress = function(e) { onProgress(e.loaded, e.total); };
|
xhr.onprogress = function(e) { onProgress(e.loaded, e.total); };
|
||||||
|
|
||||||
try { xhr.send(); } catch (e) { onFinished(0, 0, 0); }
|
try { xhr.send(); } catch (e) { onFinished(0, 0, 0); }
|
||||||
}, urlStr, req->requestType, OnFinishedAsync, OnUpdateProgress);
|
}, urlStr, req->requestType, Http_OnFinishedAsync, Http_OnUpdateProgress);
|
||||||
}
|
}
|
||||||
|
|
||||||
static void Http_WorkerInit(void) {
|
static void Http_WorkerInit(void) {
|
||||||
|
Loading…
x
Reference in New Issue
Block a user