Mercurial > hg > orthanc-stone
diff Platforms/Wasm/WasmWebService.js @ 236:f73d722d98c8 am
renamed folder
author | am@osimis.io |
---|---|
date | Tue, 19 Jun 2018 16:06:32 +0200 |
parents | Platforms/WebAssembly/WasmWebService.js@b0ba3b38a23c |
children | 9afafb192180 |
line wrap: on
line diff
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/Platforms/Wasm/WasmWebService.js Tue Jun 19 16:06:32 2018 +0200 @@ -0,0 +1,47 @@ +mergeInto(LibraryManager.library, { + WasmWebService_ScheduleGetRequest: function(callback, url, payload) { + // Directly use XMLHttpRequest (no jQuery) to retrieve the raw binary data + // http://www.henryalgus.com/reading-binary-files-using-jquery-ajax/ + var xhr = new XMLHttpRequest(); + var tmp = UTF8ToString(url); + xhr.open('GET', tmp, true); + xhr.responseType = 'arraybuffer'; + + xhr.onreadystatechange = function() { + if (this.readyState == XMLHttpRequest.DONE) { + if (xhr.status === 200) { + // TODO - Is "new Uint8Array()" necessary? This copies the + // answer to the WebAssembly stack, hence necessitating + // increasing the TOTAL_STACK parameter of Emscripten + WasmWebService_NotifySuccess(callback, tmp, new Uint8Array(this.response), + this.response.byteLength, payload); + } else { + WasmWebService_NotifyError(callback, tmp, payload); + } + } + } + + xhr.send(); + }, + + WasmWebService_SchedulePostRequest: function(callback, url, body, bodySize, payload) { + var xhr = new XMLHttpRequest(); + var tmp = UTF8ToString(url); + xhr.open('POST', tmp, true); + xhr.responseType = 'arraybuffer'; + xhr.setRequestHeader('Content-type', 'application/octet-stream'); + + xhr.onreadystatechange = function() { + if (this.readyState == XMLHttpRequest.DONE) { + if (xhr.status === 200) { + WasmWebService_NotifySuccess(callback, tmp, new Uint8Array(this.response), + this.response.byteLength, payload); + } else { + WasmWebService_NotifyError(callback, tmp, payload); + } + } + } + + xhr.send(new Uint8ClampedArray(HEAPU8.buffer, body, bodySize)); + } +});