aboutsummaryrefslogtreecommitdiff
path: root/src/library_browser.js
diff options
context:
space:
mode:
authorAnthony Liot <anthony.liot@gmail.com>2012-12-13 15:27:37 +0100
committerAnthony Liot <anthony.liot@gmail.com>2012-12-13 15:27:37 +0100
commitaf4716bb662651c26fdbe5ca1fb1e6a4e8384301 (patch)
tree37efd69c71dca911e6526405ab58988d7d376e90 /src/library_browser.js
parent125256db5c00421c00ef2afbb0e909a81ab3d1d1 (diff)
Add emscripten_async_wget2 with progress callback
Send request Post & Get with progress callback Add sample HTTP using emscripten_async_wget2
Diffstat (limited to 'src/library_browser.js')
-rw-r--r--src/library_browser.js50
1 files changed, 50 insertions, 0 deletions
diff --git a/src/library_browser.js b/src/library_browser.js
index 00ee158c..c18edf4a 100644
--- a/src/library_browser.js
+++ b/src/library_browser.js
@@ -385,6 +385,56 @@ mergeInto(LibraryManager.library, {
);
},
+ emscripten_async_wget2: function(url, file, request, param, arg, onload, onerror, onprogress) {
+ var _url = Pointer_stringify(url);
+ var _file = Pointer_stringify(file);
+ var _request = Pointer_stringify(request);
+ var _param = Pointer_stringify(param);
+ var index = _file.lastIndexOf('/');
+
+ var http = new XMLHttpRequest();
+ http.open(_request, _url, true);
+ http.responseType = 'arraybuffer';
+
+ // LOAD
+ http.onload = function(e) {
+ if (http.status == 200) {
+ FS.createDataFile( _file.substr(0, index), _file.substr(index +1), new Uint8Array(http.response), true, true);
+ if (onload) FUNCTION_TABLE[onload](arg,file);
+ } else {
+ if (onerror) FUNCTION_TABLE[onerror](arg,http.status);
+ }
+ };
+
+ // ERROR
+ http.onerror = function(e) {
+ if (onerror) FUNCTION_TABLE[onerror](arg,http.status);
+ };
+
+ // PROGRESS
+ http.onprogress = function(e) {
+ var percentComplete = (e.position / e.totalSize)*100;
+ if (onprogress) FUNCTION_TABLE[onprogress](arg,percentComplete);
+ };
+
+ try {
+ if (http.channel instanceof Ci.nsIHttpChannel)
+ http.channel.redirectionLimit = 0;
+ } catch (ex) { /* whatever */ }
+
+ if (_request == "POST") {
+ //Send the proper header information along with the request
+ http.setRequestHeader("Content-type", "application/x-www-form-urlencoded");
+ http.setRequestHeader("Content-length", _param.length);
+ http.setRequestHeader("Connection", "close");
+
+ http.send(_param);
+ } else {
+ http.send(null);
+ }
+
+ },
+
emscripten_async_prepare: function(file, onload, onerror) {
var _file = Pointer_stringify(file);
var data = FS.analyzePath(_file);