annotate Platforms/Wasm/WasmWebService.js @ 315:aad37d0b6407 am-2

Added LayerWidget::RemoveLayer + DELETE commands in WebService
author am@osimis.io
date Fri, 05 Oct 2018 10:38:16 +0200
parents 14ef1227120f
children aee3d7941c9b
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
221
d7b2590744f8 wip: building applications reusable in SDL and WASM
am@osimis.io
parents:
diff changeset
1 mergeInto(LibraryManager.library, {
309
14ef1227120f web services: better handling of failures
am@osimis.io
parents: 303
diff changeset
2 WasmWebService_GetAsync: function(callableSuccess, callableFailure, url, headersInJsonString, payload, timeoutInSeconds) {
299
3897f9f28cfa backup work in progress: updated messaging framework with ICallable
am@osimis.io
parents: 257
diff changeset
3 // Directly use XMLHttpRequest (no jQuery) to retrieve the raw binary data
3897f9f28cfa backup work in progress: updated messaging framework with ICallable
am@osimis.io
parents: 257
diff changeset
4 // http://www.henryalgus.com/reading-binary-files-using-jquery-ajax/
3897f9f28cfa backup work in progress: updated messaging framework with ICallable
am@osimis.io
parents: 257
diff changeset
5 var xhr = new XMLHttpRequest();
3897f9f28cfa backup work in progress: updated messaging framework with ICallable
am@osimis.io
parents: 257
diff changeset
6 var url_ = UTF8ToString(url);
3897f9f28cfa backup work in progress: updated messaging framework with ICallable
am@osimis.io
parents: 257
diff changeset
7 var headersInJsonString_ = UTF8ToString(headersInJsonString);
3897f9f28cfa backup work in progress: updated messaging framework with ICallable
am@osimis.io
parents: 257
diff changeset
8
3897f9f28cfa backup work in progress: updated messaging framework with ICallable
am@osimis.io
parents: 257
diff changeset
9 xhr.open('GET', url_, true);
3897f9f28cfa backup work in progress: updated messaging framework with ICallable
am@osimis.io
parents: 257
diff changeset
10 xhr.responseType = 'arraybuffer';
309
14ef1227120f web services: better handling of failures
am@osimis.io
parents: 303
diff changeset
11 xhr.timeout = timeoutInSeconds * 1000;
299
3897f9f28cfa backup work in progress: updated messaging framework with ICallable
am@osimis.io
parents: 257
diff changeset
12 var headers = JSON.parse(headersInJsonString_);
3897f9f28cfa backup work in progress: updated messaging framework with ICallable
am@osimis.io
parents: 257
diff changeset
13 for (var key in headers) {
3897f9f28cfa backup work in progress: updated messaging framework with ICallable
am@osimis.io
parents: 257
diff changeset
14 xhr.setRequestHeader(key, headers[key]);
3897f9f28cfa backup work in progress: updated messaging framework with ICallable
am@osimis.io
parents: 257
diff changeset
15 }
3897f9f28cfa backup work in progress: updated messaging framework with ICallable
am@osimis.io
parents: 257
diff changeset
16 //console.log(xhr);
3897f9f28cfa backup work in progress: updated messaging framework with ICallable
am@osimis.io
parents: 257
diff changeset
17 xhr.onreadystatechange = function() {
3897f9f28cfa backup work in progress: updated messaging framework with ICallable
am@osimis.io
parents: 257
diff changeset
18 if (this.readyState == XMLHttpRequest.DONE) {
3897f9f28cfa backup work in progress: updated messaging framework with ICallable
am@osimis.io
parents: 257
diff changeset
19 if (xhr.status === 200) {
3897f9f28cfa backup work in progress: updated messaging framework with ICallable
am@osimis.io
parents: 257
diff changeset
20 // TODO - Is "new Uint8Array()" necessary? This copies the
3897f9f28cfa backup work in progress: updated messaging framework with ICallable
am@osimis.io
parents: 257
diff changeset
21 // answer to the WebAssembly stack, hence necessitating
3897f9f28cfa backup work in progress: updated messaging framework with ICallable
am@osimis.io
parents: 257
diff changeset
22 // increasing the TOTAL_STACK parameter of Emscripten
303
ed1a4302154f new messages in wasm too
am@osimis.io
parents: 299
diff changeset
23 WasmWebService_NotifySuccess(callableSuccess, url_, new Uint8Array(this.response),
299
3897f9f28cfa backup work in progress: updated messaging framework with ICallable
am@osimis.io
parents: 257
diff changeset
24 this.response.byteLength, payload);
3897f9f28cfa backup work in progress: updated messaging framework with ICallable
am@osimis.io
parents: 257
diff changeset
25 } else {
303
ed1a4302154f new messages in wasm too
am@osimis.io
parents: 299
diff changeset
26 WasmWebService_NotifyError(callableFailure, url_, payload);
299
3897f9f28cfa backup work in progress: updated messaging framework with ICallable
am@osimis.io
parents: 257
diff changeset
27 }
3897f9f28cfa backup work in progress: updated messaging framework with ICallable
am@osimis.io
parents: 257
diff changeset
28 }
3897f9f28cfa backup work in progress: updated messaging framework with ICallable
am@osimis.io
parents: 257
diff changeset
29 }
3897f9f28cfa backup work in progress: updated messaging framework with ICallable
am@osimis.io
parents: 257
diff changeset
30
3897f9f28cfa backup work in progress: updated messaging framework with ICallable
am@osimis.io
parents: 257
diff changeset
31 xhr.send();
3897f9f28cfa backup work in progress: updated messaging framework with ICallable
am@osimis.io
parents: 257
diff changeset
32 },
3897f9f28cfa backup work in progress: updated messaging framework with ICallable
am@osimis.io
parents: 257
diff changeset
33
309
14ef1227120f web services: better handling of failures
am@osimis.io
parents: 303
diff changeset
34 WasmWebService_PostAsync: function(callableSuccess, callableFailure, url, headersInJsonString, body, bodySize, payload, timeoutInSeconds) {
221
d7b2590744f8 wip: building applications reusable in SDL and WASM
am@osimis.io
parents:
diff changeset
35 var xhr = new XMLHttpRequest();
257
9afafb192180 using PAM
am@osimis.io
parents: 236
diff changeset
36 var url_ = UTF8ToString(url);
9afafb192180 using PAM
am@osimis.io
parents: 236
diff changeset
37 var headersInJsonString_ = UTF8ToString(headersInJsonString);
9afafb192180 using PAM
am@osimis.io
parents: 236
diff changeset
38 xhr.open('POST', url_, true);
309
14ef1227120f web services: better handling of failures
am@osimis.io
parents: 303
diff changeset
39 xhr.timeout = timeoutInSeconds * 1000;
221
d7b2590744f8 wip: building applications reusable in SDL and WASM
am@osimis.io
parents:
diff changeset
40 xhr.responseType = 'arraybuffer';
d7b2590744f8 wip: building applications reusable in SDL and WASM
am@osimis.io
parents:
diff changeset
41 xhr.setRequestHeader('Content-type', 'application/octet-stream');
257
9afafb192180 using PAM
am@osimis.io
parents: 236
diff changeset
42
9afafb192180 using PAM
am@osimis.io
parents: 236
diff changeset
43 var headers = JSON.parse(headersInJsonString_);
9afafb192180 using PAM
am@osimis.io
parents: 236
diff changeset
44 for (var key in headers) {
9afafb192180 using PAM
am@osimis.io
parents: 236
diff changeset
45 xhr.setRequestHeader(key, headers[key]);
9afafb192180 using PAM
am@osimis.io
parents: 236
diff changeset
46 }
221
d7b2590744f8 wip: building applications reusable in SDL and WASM
am@osimis.io
parents:
diff changeset
47
d7b2590744f8 wip: building applications reusable in SDL and WASM
am@osimis.io
parents:
diff changeset
48 xhr.onreadystatechange = function() {
d7b2590744f8 wip: building applications reusable in SDL and WASM
am@osimis.io
parents:
diff changeset
49 if (this.readyState == XMLHttpRequest.DONE) {
d7b2590744f8 wip: building applications reusable in SDL and WASM
am@osimis.io
parents:
diff changeset
50 if (xhr.status === 200) {
303
ed1a4302154f new messages in wasm too
am@osimis.io
parents: 299
diff changeset
51 WasmWebService_NotifySuccess(callableSuccess, url_, new Uint8Array(this.response),
221
d7b2590744f8 wip: building applications reusable in SDL and WASM
am@osimis.io
parents:
diff changeset
52 this.response.byteLength, payload);
d7b2590744f8 wip: building applications reusable in SDL and WASM
am@osimis.io
parents:
diff changeset
53 } else {
303
ed1a4302154f new messages in wasm too
am@osimis.io
parents: 299
diff changeset
54 WasmWebService_NotifyError(callableFailure, url_, payload);
221
d7b2590744f8 wip: building applications reusable in SDL and WASM
am@osimis.io
parents:
diff changeset
55 }
d7b2590744f8 wip: building applications reusable in SDL and WASM
am@osimis.io
parents:
diff changeset
56 }
d7b2590744f8 wip: building applications reusable in SDL and WASM
am@osimis.io
parents:
diff changeset
57 }
d7b2590744f8 wip: building applications reusable in SDL and WASM
am@osimis.io
parents:
diff changeset
58
d7b2590744f8 wip: building applications reusable in SDL and WASM
am@osimis.io
parents:
diff changeset
59 xhr.send(new Uint8ClampedArray(HEAPU8.buffer, body, bodySize));
315
aad37d0b6407 Added LayerWidget::RemoveLayer + DELETE commands in WebService
am@osimis.io
parents: 309
diff changeset
60 },
aad37d0b6407 Added LayerWidget::RemoveLayer + DELETE commands in WebService
am@osimis.io
parents: 309
diff changeset
61
aad37d0b6407 Added LayerWidget::RemoveLayer + DELETE commands in WebService
am@osimis.io
parents: 309
diff changeset
62 WasmWebService_DeleteAsync: function(callableSuccess, callableFailure, url, headersInJsonString, payload, timeoutInSeconds) {
aad37d0b6407 Added LayerWidget::RemoveLayer + DELETE commands in WebService
am@osimis.io
parents: 309
diff changeset
63 var xhr = new XMLHttpRequest();
aad37d0b6407 Added LayerWidget::RemoveLayer + DELETE commands in WebService
am@osimis.io
parents: 309
diff changeset
64 var url_ = UTF8ToString(url);
aad37d0b6407 Added LayerWidget::RemoveLayer + DELETE commands in WebService
am@osimis.io
parents: 309
diff changeset
65 var headersInJsonString_ = UTF8ToString(headersInJsonString);
aad37d0b6407 Added LayerWidget::RemoveLayer + DELETE commands in WebService
am@osimis.io
parents: 309
diff changeset
66 xhr.open('DELETE', url_, true);
aad37d0b6407 Added LayerWidget::RemoveLayer + DELETE commands in WebService
am@osimis.io
parents: 309
diff changeset
67 xhr.timeout = timeoutInSeconds * 1000;
aad37d0b6407 Added LayerWidget::RemoveLayer + DELETE commands in WebService
am@osimis.io
parents: 309
diff changeset
68 xhr.responseType = 'arraybuffer';
aad37d0b6407 Added LayerWidget::RemoveLayer + DELETE commands in WebService
am@osimis.io
parents: 309
diff changeset
69 xhr.setRequestHeader('Content-type', 'application/octet-stream');
aad37d0b6407 Added LayerWidget::RemoveLayer + DELETE commands in WebService
am@osimis.io
parents: 309
diff changeset
70
aad37d0b6407 Added LayerWidget::RemoveLayer + DELETE commands in WebService
am@osimis.io
parents: 309
diff changeset
71 var headers = JSON.parse(headersInJsonString_);
aad37d0b6407 Added LayerWidget::RemoveLayer + DELETE commands in WebService
am@osimis.io
parents: 309
diff changeset
72 for (var key in headers) {
aad37d0b6407 Added LayerWidget::RemoveLayer + DELETE commands in WebService
am@osimis.io
parents: 309
diff changeset
73 xhr.setRequestHeader(key, headers[key]);
aad37d0b6407 Added LayerWidget::RemoveLayer + DELETE commands in WebService
am@osimis.io
parents: 309
diff changeset
74 }
aad37d0b6407 Added LayerWidget::RemoveLayer + DELETE commands in WebService
am@osimis.io
parents: 309
diff changeset
75
aad37d0b6407 Added LayerWidget::RemoveLayer + DELETE commands in WebService
am@osimis.io
parents: 309
diff changeset
76 xhr.onreadystatechange = function() {
aad37d0b6407 Added LayerWidget::RemoveLayer + DELETE commands in WebService
am@osimis.io
parents: 309
diff changeset
77 if (this.readyState == XMLHttpRequest.DONE) {
aad37d0b6407 Added LayerWidget::RemoveLayer + DELETE commands in WebService
am@osimis.io
parents: 309
diff changeset
78 if (xhr.status === 200) {
aad37d0b6407 Added LayerWidget::RemoveLayer + DELETE commands in WebService
am@osimis.io
parents: 309
diff changeset
79 WasmWebService_NotifySuccess(callableSuccess, url_, new Uint8Array(this.response),
aad37d0b6407 Added LayerWidget::RemoveLayer + DELETE commands in WebService
am@osimis.io
parents: 309
diff changeset
80 this.response.byteLength, payload);
aad37d0b6407 Added LayerWidget::RemoveLayer + DELETE commands in WebService
am@osimis.io
parents: 309
diff changeset
81 } else {
aad37d0b6407 Added LayerWidget::RemoveLayer + DELETE commands in WebService
am@osimis.io
parents: 309
diff changeset
82 WasmWebService_NotifyError(callableFailure, url_, payload);
aad37d0b6407 Added LayerWidget::RemoveLayer + DELETE commands in WebService
am@osimis.io
parents: 309
diff changeset
83 }
aad37d0b6407 Added LayerWidget::RemoveLayer + DELETE commands in WebService
am@osimis.io
parents: 309
diff changeset
84 }
aad37d0b6407 Added LayerWidget::RemoveLayer + DELETE commands in WebService
am@osimis.io
parents: 309
diff changeset
85 }
aad37d0b6407 Added LayerWidget::RemoveLayer + DELETE commands in WebService
am@osimis.io
parents: 309
diff changeset
86
aad37d0b6407 Added LayerWidget::RemoveLayer + DELETE commands in WebService
am@osimis.io
parents: 309
diff changeset
87 xhr.send();
221
d7b2590744f8 wip: building applications reusable in SDL and WASM
am@osimis.io
parents:
diff changeset
88 }
315
aad37d0b6407 Added LayerWidget::RemoveLayer + DELETE commands in WebService
am@osimis.io
parents: 309
diff changeset
89
221
d7b2590744f8 wip: building applications reusable in SDL and WASM
am@osimis.io
parents:
diff changeset
90 });