Mercurial > hg > orthanc-stone
comparison Platforms/Wasm/WasmWebService.js @ 257:9afafb192180 am-2
using PAM
author | am@osimis.io |
---|---|
date | Tue, 10 Jul 2018 12:39:01 +0200 |
parents | f73d722d98c8 |
children | 3897f9f28cfa |
comparison
equal
deleted
inserted
replaced
255:65562a28fe05 | 257:9afafb192180 |
---|---|
1 mergeInto(LibraryManager.library, { | 1 mergeInto(LibraryManager.library, { |
2 WasmWebService_ScheduleGetRequest: function(callback, url, payload) { | 2 WasmWebService_ScheduleGetRequest: function(callback, url, headersInJsonString, payload) { |
3 // Directly use XMLHttpRequest (no jQuery) to retrieve the raw binary data | 3 // Directly use XMLHttpRequest (no jQuery) to retrieve the raw binary data |
4 // http://www.henryalgus.com/reading-binary-files-using-jquery-ajax/ | 4 // http://www.henryalgus.com/reading-binary-files-using-jquery-ajax/ |
5 var xhr = new XMLHttpRequest(); | 5 var xhr = new XMLHttpRequest(); |
6 var tmp = UTF8ToString(url); | 6 var url_ = UTF8ToString(url); |
7 xhr.open('GET', tmp, true); | 7 var headersInJsonString_ = UTF8ToString(headersInJsonString); |
8 | |
9 xhr.open('GET', url_, true); | |
8 xhr.responseType = 'arraybuffer'; | 10 xhr.responseType = 'arraybuffer'; |
9 | 11 var headers = JSON.parse(headersInJsonString_); |
12 for (var key in headers) { | |
13 xhr.setRequestHeader(key, headers[key]); | |
14 } | |
15 // console.log(xhr); | |
10 xhr.onreadystatechange = function() { | 16 xhr.onreadystatechange = function() { |
11 if (this.readyState == XMLHttpRequest.DONE) { | 17 if (this.readyState == XMLHttpRequest.DONE) { |
12 if (xhr.status === 200) { | 18 if (xhr.status === 200) { |
13 // TODO - Is "new Uint8Array()" necessary? This copies the | 19 // TODO - Is "new Uint8Array()" necessary? This copies the |
14 // answer to the WebAssembly stack, hence necessitating | 20 // answer to the WebAssembly stack, hence necessitating |
15 // increasing the TOTAL_STACK parameter of Emscripten | 21 // increasing the TOTAL_STACK parameter of Emscripten |
16 WasmWebService_NotifySuccess(callback, tmp, new Uint8Array(this.response), | 22 WasmWebService_NotifySuccess(callback, url_, new Uint8Array(this.response), |
17 this.response.byteLength, payload); | 23 this.response.byteLength, payload); |
18 } else { | 24 } else { |
19 WasmWebService_NotifyError(callback, tmp, payload); | 25 WasmWebService_NotifyError(callback, url_, payload); |
20 } | 26 } |
21 } | 27 } |
22 } | 28 } |
23 | 29 |
24 xhr.send(); | 30 xhr.send(); |
25 }, | 31 }, |
26 | 32 |
27 WasmWebService_SchedulePostRequest: function(callback, url, body, bodySize, payload) { | 33 WasmWebService_SchedulePostRequest: function(callback, url, headersInJsonString, body, bodySize, payload) { |
28 var xhr = new XMLHttpRequest(); | 34 var xhr = new XMLHttpRequest(); |
29 var tmp = UTF8ToString(url); | 35 var url_ = UTF8ToString(url); |
30 xhr.open('POST', tmp, true); | 36 var headersInJsonString_ = UTF8ToString(headersInJsonString); |
37 xhr.open('POST', url_, true); | |
31 xhr.responseType = 'arraybuffer'; | 38 xhr.responseType = 'arraybuffer'; |
32 xhr.setRequestHeader('Content-type', 'application/octet-stream'); | 39 xhr.setRequestHeader('Content-type', 'application/octet-stream'); |
40 | |
41 var headers = JSON.parse(headersInJsonString_); | |
42 for (var key in headers) { | |
43 xhr.setRequestHeader(key, headers[key]); | |
44 } | |
33 | 45 |
34 xhr.onreadystatechange = function() { | 46 xhr.onreadystatechange = function() { |
35 if (this.readyState == XMLHttpRequest.DONE) { | 47 if (this.readyState == XMLHttpRequest.DONE) { |
36 if (xhr.status === 200) { | 48 if (xhr.status === 200) { |
37 WasmWebService_NotifySuccess(callback, tmp, new Uint8Array(this.response), | 49 WasmWebService_NotifySuccess(callback, url_, new Uint8Array(this.response), |
38 this.response.byteLength, payload); | 50 this.response.byteLength, payload); |
39 } else { | 51 } else { |
40 WasmWebService_NotifyError(callback, tmp, payload); | 52 WasmWebService_NotifyError(callback, url_, payload); |
41 } | 53 } |
42 } | 54 } |
43 } | 55 } |
44 | 56 |
45 xhr.send(new Uint8ClampedArray(HEAPU8.buffer, body, bodySize)); | 57 xhr.send(new Uint8ClampedArray(HEAPU8.buffer, body, bodySize)); |