comparison 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
comparison
equal deleted inserted replaced
235:ce4405d98b92 236:f73d722d98c8
1 mergeInto(LibraryManager.library, {
2 WasmWebService_ScheduleGetRequest: function(callback, url, payload) {
3 // Directly use XMLHttpRequest (no jQuery) to retrieve the raw binary data
4 // http://www.henryalgus.com/reading-binary-files-using-jquery-ajax/
5 var xhr = new XMLHttpRequest();
6 var tmp = UTF8ToString(url);
7 xhr.open('GET', tmp, true);
8 xhr.responseType = 'arraybuffer';
9
10 xhr.onreadystatechange = function() {
11 if (this.readyState == XMLHttpRequest.DONE) {
12 if (xhr.status === 200) {
13 // TODO - Is "new Uint8Array()" necessary? This copies the
14 // answer to the WebAssembly stack, hence necessitating
15 // increasing the TOTAL_STACK parameter of Emscripten
16 WasmWebService_NotifySuccess(callback, tmp, new Uint8Array(this.response),
17 this.response.byteLength, payload);
18 } else {
19 WasmWebService_NotifyError(callback, tmp, payload);
20 }
21 }
22 }
23
24 xhr.send();
25 },
26
27 WasmWebService_SchedulePostRequest: function(callback, url, body, bodySize, payload) {
28 var xhr = new XMLHttpRequest();
29 var tmp = UTF8ToString(url);
30 xhr.open('POST', tmp, true);
31 xhr.responseType = 'arraybuffer';
32 xhr.setRequestHeader('Content-type', 'application/octet-stream');
33
34 xhr.onreadystatechange = function() {
35 if (this.readyState == XMLHttpRequest.DONE) {
36 if (xhr.status === 200) {
37 WasmWebService_NotifySuccess(callback, tmp, new Uint8Array(this.response),
38 this.response.byteLength, payload);
39 } else {
40 WasmWebService_NotifyError(callback, tmp, payload);
41 }
42 }
43 }
44
45 xhr.send(new Uint8ClampedArray(HEAPU8.buffer, body, bodySize));
46 }
47 });