mirror of
https://github.com/ading2210/libcurl.js.git
synced 2025-05-13 22:40:01 -04:00
improve download speeds by listening directly for ws messages
This commit is contained in:
parent
e598ed3be6
commit
4004409650
3 changed files with 13 additions and 2 deletions
5
client/fragments/notify_ws_events.js
Normal file
5
client/fragments/notify_ws_events.js
Normal file
|
@ -0,0 +1,5 @@
|
||||||
|
/* INSERT
|
||||||
|
Module\[['"]websocket['"]\]\.emit\(['"]message['"], ?sock\.stream\.fd\)
|
||||||
|
*/
|
||||||
|
; ws_events.dispatchEvent(new Event("message"));
|
||||||
|
|
|
@ -30,6 +30,8 @@ var wasm_ready = false;
|
||||||
var version_dict = null;
|
var version_dict = null;
|
||||||
var api = null;
|
var api = null;
|
||||||
var main_session = null;
|
var main_session = null;
|
||||||
|
const ws_events = new EventTarget();
|
||||||
|
|
||||||
const libcurl_version = "__library_version__";
|
const libcurl_version = "__library_version__";
|
||||||
const wisp_version = "__wisp_version__";
|
const wisp_version = "__wisp_version__";
|
||||||
|
|
||||||
|
|
|
@ -20,6 +20,9 @@ class CurlSession {
|
||||||
}, "viii");
|
}, "viii");
|
||||||
this.request_callbacks = {};
|
this.request_callbacks = {};
|
||||||
this.last_request_id = 0;
|
this.last_request_id = 0;
|
||||||
|
|
||||||
|
this.ws_event_listener = () => {this.event_loop_func()};
|
||||||
|
ws_events.addEventListener("message", this.ws_event_listener);
|
||||||
}
|
}
|
||||||
|
|
||||||
assert_ready() {
|
assert_ready() {
|
||||||
|
@ -97,7 +100,7 @@ class CurlSession {
|
||||||
if (this.event_loop) {
|
if (this.event_loop) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
this.event_loop = setInterval(() => {
|
this.event_loop = setInterval(() => {
|
||||||
this.event_loop_func();
|
this.event_loop_func();
|
||||||
}, 0);
|
}, 0);
|
||||||
|
@ -108,7 +111,7 @@ class CurlSession {
|
||||||
if (libcurl_active || this.active_requests) {
|
if (libcurl_active || this.active_requests) {
|
||||||
_session_perform(this.session_ptr);
|
_session_perform(this.session_ptr);
|
||||||
}
|
}
|
||||||
else {
|
else if (this.event_loop) {
|
||||||
clearInterval(this.event_loop);
|
clearInterval(this.event_loop);
|
||||||
this.event_loop = null;
|
this.event_loop = null;
|
||||||
}
|
}
|
||||||
|
@ -120,6 +123,7 @@ class CurlSession {
|
||||||
}
|
}
|
||||||
_session_cleanup(this.session_ptr);
|
_session_cleanup(this.session_ptr);
|
||||||
this.session_ptr = null;
|
this.session_ptr = null;
|
||||||
|
ws_events.removeEventListener(this.ws_event_listener);
|
||||||
Module.removeFunction(this.end_callback_ptr);
|
Module.removeFunction(this.end_callback_ptr);
|
||||||
Module.removeFunction(this.headers_callback_ptr);
|
Module.removeFunction(this.headers_callback_ptr);
|
||||||
Module.removeFunction(this.data_callback_ptr);
|
Module.removeFunction(this.data_callback_ptr);
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue