comparison Platforms/WebAssembly/WasmWebService.js @ 221:d7b2590744f8 am

wip: building applications reusable in SDL and WASM
author am@osimis.io
date Mon, 11 Jun 2018 14:01:02 +0200
parents
children b0ba3b38a23c
comparison
equal deleted inserted replaced
219:26e3bfe30e66 221:d7b2590744f8
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
48 ScheduleRedraw: function() {
49 ScheduleRedraw();
50 }
51 });