Mercurial > hg > orthanc-stone
diff Platforms/Wasm/WasmWebService.js @ 299:3897f9f28cfa am-callable-and-promise
backup work in progress: updated messaging framework with ICallable
author | am@osimis.io |
---|---|
date | Fri, 14 Sep 2018 16:44:01 +0200 |
parents | 9afafb192180 |
children | ed1a4302154f |
line wrap: on
line diff
--- a/Platforms/Wasm/WasmWebService.js Mon Sep 10 12:22:26 2018 +0200 +++ b/Platforms/Wasm/WasmWebService.js Fri Sep 14 16:44:01 2018 +0200 @@ -30,6 +30,40 @@ xhr.send(); }, + WasmWebService_NewScheduleGetRequest: function(callableSuccess, callableFailure, url, headersInJsonString, 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 url_ = UTF8ToString(url); + var headersInJsonString_ = UTF8ToString(headersInJsonString); + + xhr.open('GET', url_, true); + xhr.responseType = 'arraybuffer'; + var headers = JSON.parse(headersInJsonString_); + for (var key in headers) { + xhr.setRequestHeader(key, headers[key]); + } + //console.log(xhr); + 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 + console.log("WasmWebService success", this.response); + WasmWebService_NewNotifySuccess(callableSuccess, url_, new Uint8Array(this.response), + this.response.byteLength, payload); + console.log("WasmWebService success 2", this.response); + } else { + console.log("WasmWebService failed"); + WasmWebService_NewNotifyError(callableFailure, url_, payload); + } + } + } + + xhr.send(); + }, + WasmWebService_SchedulePostRequest: function(callback, url, headersInJsonString, body, bodySize, payload) { var xhr = new XMLHttpRequest(); var url_ = UTF8ToString(url);