Mercurial > hg > orthanc-stone
comparison 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 |
comparison
equal
deleted
inserted
replaced
298:f58bfb7bbcc9 | 299:3897f9f28cfa |
---|---|
21 // increasing the TOTAL_STACK parameter of Emscripten | 21 // increasing the TOTAL_STACK parameter of Emscripten |
22 WasmWebService_NotifySuccess(callback, url_, new Uint8Array(this.response), | 22 WasmWebService_NotifySuccess(callback, url_, new Uint8Array(this.response), |
23 this.response.byteLength, payload); | 23 this.response.byteLength, payload); |
24 } else { | 24 } else { |
25 WasmWebService_NotifyError(callback, url_, payload); | 25 WasmWebService_NotifyError(callback, url_, payload); |
26 } | |
27 } | |
28 } | |
29 | |
30 xhr.send(); | |
31 }, | |
32 | |
33 WasmWebService_NewScheduleGetRequest: function(callableSuccess, callableFailure, url, headersInJsonString, payload) { | |
34 // Directly use XMLHttpRequest (no jQuery) to retrieve the raw binary data | |
35 // http://www.henryalgus.com/reading-binary-files-using-jquery-ajax/ | |
36 var xhr = new XMLHttpRequest(); | |
37 var url_ = UTF8ToString(url); | |
38 var headersInJsonString_ = UTF8ToString(headersInJsonString); | |
39 | |
40 xhr.open('GET', url_, true); | |
41 xhr.responseType = 'arraybuffer'; | |
42 var headers = JSON.parse(headersInJsonString_); | |
43 for (var key in headers) { | |
44 xhr.setRequestHeader(key, headers[key]); | |
45 } | |
46 //console.log(xhr); | |
47 xhr.onreadystatechange = function() { | |
48 if (this.readyState == XMLHttpRequest.DONE) { | |
49 if (xhr.status === 200) { | |
50 // TODO - Is "new Uint8Array()" necessary? This copies the | |
51 // answer to the WebAssembly stack, hence necessitating | |
52 // increasing the TOTAL_STACK parameter of Emscripten | |
53 console.log("WasmWebService success", this.response); | |
54 WasmWebService_NewNotifySuccess(callableSuccess, url_, new Uint8Array(this.response), | |
55 this.response.byteLength, payload); | |
56 console.log("WasmWebService success 2", this.response); | |
57 } else { | |
58 console.log("WasmWebService failed"); | |
59 WasmWebService_NewNotifyError(callableFailure, url_, payload); | |
26 } | 60 } |
27 } | 61 } |
28 } | 62 } |
29 | 63 |
30 xhr.send(); | 64 xhr.send(); |