annotate Platforms/Wasm/WasmWebService.js @ 981:c20dbaab360c

Ability to cope with empty "Referenced SOP Instance UID" (dicom path (3006,0039)[i] / (0x3006, 0x0040)[0] / (0x3006, 0x0016)[0] / (0x0008, 0x1155)) + better logs + code formating
author Benjamin Golinvaux <bgo@osimis.io>
date Fri, 06 Sep 2019 09:38:18 +0200
parents 861c080ef47b
children
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) {
417
aee3d7941c9b preparing to load images using DICOMweb
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 315
diff changeset
20 var s = xhr.getAllResponseHeaders();
aee3d7941c9b preparing to load images using DICOMweb
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 315
diff changeset
21 var headers = _malloc(s.length + 1);
419
d638d5721f1c replace deprecated writeStringToMemory by stringToUTF8
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 417
diff changeset
22 stringToUTF8(s, headers, s.length + 1);
417
aee3d7941c9b preparing to load images using DICOMweb
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 315
diff changeset
23
299
3897f9f28cfa backup work in progress: updated messaging framework with ICallable
am@osimis.io
parents: 257
diff changeset
24 // 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
25 // answer to the WebAssembly stack, hence necessitating
3897f9f28cfa backup work in progress: updated messaging framework with ICallable
am@osimis.io
parents: 257
diff changeset
26 // increasing the TOTAL_STACK parameter of Emscripten
466
5055031f4a06 - Added browserify to build. This allows using require calls for modules that
bgo-osimis
parents: 435
diff changeset
27 window.WasmWebService_NotifySuccess(callableSuccess, url_, new Uint8Array(this.response),
417
aee3d7941c9b preparing to load images using DICOMweb
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 315
diff changeset
28 this.response.byteLength, headers, payload);
299
3897f9f28cfa backup work in progress: updated messaging framework with ICallable
am@osimis.io
parents: 257
diff changeset
29 } else {
940
861c080ef47b handling httpStatus in WebService error messages
Alain Mazy <alain@mazy.be>
parents: 509
diff changeset
30 window.WasmWebService_NotifyError(callableFailure, url_, xhr.status, payload);
299
3897f9f28cfa backup work in progress: updated messaging framework with ICallable
am@osimis.io
parents: 257
diff changeset
31 }
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 }
3897f9f28cfa backup work in progress: updated messaging framework with ICallable
am@osimis.io
parents: 257
diff changeset
34
3897f9f28cfa backup work in progress: updated messaging framework with ICallable
am@osimis.io
parents: 257
diff changeset
35 xhr.send();
3897f9f28cfa backup work in progress: updated messaging framework with ICallable
am@osimis.io
parents: 257
diff changeset
36 },
3897f9f28cfa backup work in progress: updated messaging framework with ICallable
am@osimis.io
parents: 257
diff changeset
37
435
e641d3978856 WasmWebService now using BaseWebService and supporting cache
am@osimis.io
parents: 419
diff changeset
38 WasmWebService_ScheduleLaterCachedSuccessNotification: function (brol) {
e641d3978856 WasmWebService now using BaseWebService and supporting cache
am@osimis.io
parents: 419
diff changeset
39 setTimeout(function() {
509
1b9973905e15 Fix to use js callbacks attached to 'window' + dummy changes in cmake files
Benjamin Golinvaux <bgo@osimis.io>
parents: 466
diff changeset
40 window.WasmWebService_NotifyCachedSuccess(brol);
435
e641d3978856 WasmWebService now using BaseWebService and supporting cache
am@osimis.io
parents: 419
diff changeset
41 }, 0);
e641d3978856 WasmWebService now using BaseWebService and supporting cache
am@osimis.io
parents: 419
diff changeset
42 },
e641d3978856 WasmWebService now using BaseWebService and supporting cache
am@osimis.io
parents: 419
diff changeset
43
309
14ef1227120f web services: better handling of failures
am@osimis.io
parents: 303
diff changeset
44 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
45 var xhr = new XMLHttpRequest();
257
9afafb192180 using PAM
am@osimis.io
parents: 236
diff changeset
46 var url_ = UTF8ToString(url);
9afafb192180 using PAM
am@osimis.io
parents: 236
diff changeset
47 var headersInJsonString_ = UTF8ToString(headersInJsonString);
9afafb192180 using PAM
am@osimis.io
parents: 236
diff changeset
48 xhr.open('POST', url_, true);
309
14ef1227120f web services: better handling of failures
am@osimis.io
parents: 303
diff changeset
49 xhr.timeout = timeoutInSeconds * 1000;
221
d7b2590744f8 wip: building applications reusable in SDL and WASM
am@osimis.io
parents:
diff changeset
50 xhr.responseType = 'arraybuffer';
d7b2590744f8 wip: building applications reusable in SDL and WASM
am@osimis.io
parents:
diff changeset
51 xhr.setRequestHeader('Content-type', 'application/octet-stream');
257
9afafb192180 using PAM
am@osimis.io
parents: 236
diff changeset
52
9afafb192180 using PAM
am@osimis.io
parents: 236
diff changeset
53 var headers = JSON.parse(headersInJsonString_);
9afafb192180 using PAM
am@osimis.io
parents: 236
diff changeset
54 for (var key in headers) {
9afafb192180 using PAM
am@osimis.io
parents: 236
diff changeset
55 xhr.setRequestHeader(key, headers[key]);
9afafb192180 using PAM
am@osimis.io
parents: 236
diff changeset
56 }
221
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 xhr.onreadystatechange = function() {
d7b2590744f8 wip: building applications reusable in SDL and WASM
am@osimis.io
parents:
diff changeset
59 if (this.readyState == XMLHttpRequest.DONE) {
d7b2590744f8 wip: building applications reusable in SDL and WASM
am@osimis.io
parents:
diff changeset
60 if (xhr.status === 200) {
417
aee3d7941c9b preparing to load images using DICOMweb
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 315
diff changeset
61 var s = xhr.getAllResponseHeaders();
aee3d7941c9b preparing to load images using DICOMweb
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 315
diff changeset
62 var headers = _malloc(s.length + 1);
419
d638d5721f1c replace deprecated writeStringToMemory by stringToUTF8
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 417
diff changeset
63 stringToUTF8(s, headers, s.length + 1);
417
aee3d7941c9b preparing to load images using DICOMweb
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 315
diff changeset
64
509
1b9973905e15 Fix to use js callbacks attached to 'window' + dummy changes in cmake files
Benjamin Golinvaux <bgo@osimis.io>
parents: 466
diff changeset
65 window.WasmWebService_NotifySuccess(callableSuccess, url_, new Uint8Array(this.response),
417
aee3d7941c9b preparing to load images using DICOMweb
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 315
diff changeset
66 this.response.byteLength, headers, payload);
221
d7b2590744f8 wip: building applications reusable in SDL and WASM
am@osimis.io
parents:
diff changeset
67 } else {
940
861c080ef47b handling httpStatus in WebService error messages
Alain Mazy <alain@mazy.be>
parents: 509
diff changeset
68 window.WasmWebService_NotifyError(callableFailure, url_, xhr.status, payload);
221
d7b2590744f8 wip: building applications reusable in SDL and WASM
am@osimis.io
parents:
diff changeset
69 }
d7b2590744f8 wip: building applications reusable in SDL and WASM
am@osimis.io
parents:
diff changeset
70 }
d7b2590744f8 wip: building applications reusable in SDL and WASM
am@osimis.io
parents:
diff changeset
71 }
d7b2590744f8 wip: building applications reusable in SDL and WASM
am@osimis.io
parents:
diff changeset
72
d7b2590744f8 wip: building applications reusable in SDL and WASM
am@osimis.io
parents:
diff changeset
73 xhr.send(new Uint8ClampedArray(HEAPU8.buffer, body, bodySize));
315
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 WasmWebService_DeleteAsync: function(callableSuccess, callableFailure, url, headersInJsonString, payload, timeoutInSeconds) {
aad37d0b6407 Added LayerWidget::RemoveLayer + DELETE commands in WebService
am@osimis.io
parents: 309
diff changeset
77 var xhr = new XMLHttpRequest();
aad37d0b6407 Added LayerWidget::RemoveLayer + DELETE commands in WebService
am@osimis.io
parents: 309
diff changeset
78 var url_ = UTF8ToString(url);
aad37d0b6407 Added LayerWidget::RemoveLayer + DELETE commands in WebService
am@osimis.io
parents: 309
diff changeset
79 var headersInJsonString_ = UTF8ToString(headersInJsonString);
aad37d0b6407 Added LayerWidget::RemoveLayer + DELETE commands in WebService
am@osimis.io
parents: 309
diff changeset
80 xhr.open('DELETE', url_, true);
aad37d0b6407 Added LayerWidget::RemoveLayer + DELETE commands in WebService
am@osimis.io
parents: 309
diff changeset
81 xhr.timeout = timeoutInSeconds * 1000;
aad37d0b6407 Added LayerWidget::RemoveLayer + DELETE commands in WebService
am@osimis.io
parents: 309
diff changeset
82 xhr.responseType = 'arraybuffer';
aad37d0b6407 Added LayerWidget::RemoveLayer + DELETE commands in WebService
am@osimis.io
parents: 309
diff changeset
83 xhr.setRequestHeader('Content-type', 'application/octet-stream');
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 var headers = JSON.parse(headersInJsonString_);
aad37d0b6407 Added LayerWidget::RemoveLayer + DELETE commands in WebService
am@osimis.io
parents: 309
diff changeset
86 for (var key in headers) {
aad37d0b6407 Added LayerWidget::RemoveLayer + DELETE commands in WebService
am@osimis.io
parents: 309
diff changeset
87 xhr.setRequestHeader(key, headers[key]);
aad37d0b6407 Added LayerWidget::RemoveLayer + DELETE commands in WebService
am@osimis.io
parents: 309
diff changeset
88 }
aad37d0b6407 Added LayerWidget::RemoveLayer + DELETE commands in WebService
am@osimis.io
parents: 309
diff changeset
89
aad37d0b6407 Added LayerWidget::RemoveLayer + DELETE commands in WebService
am@osimis.io
parents: 309
diff changeset
90 xhr.onreadystatechange = function() {
aad37d0b6407 Added LayerWidget::RemoveLayer + DELETE commands in WebService
am@osimis.io
parents: 309
diff changeset
91 if (this.readyState == XMLHttpRequest.DONE) {
aad37d0b6407 Added LayerWidget::RemoveLayer + DELETE commands in WebService
am@osimis.io
parents: 309
diff changeset
92 if (xhr.status === 200) {
417
aee3d7941c9b preparing to load images using DICOMweb
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 315
diff changeset
93 var s = xhr.getAllResponseHeaders();
aee3d7941c9b preparing to load images using DICOMweb
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 315
diff changeset
94 var headers = _malloc(s.length + 1);
419
d638d5721f1c replace deprecated writeStringToMemory by stringToUTF8
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 417
diff changeset
95 stringToUTF8(s, headers, s.length + 1);
417
aee3d7941c9b preparing to load images using DICOMweb
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 315
diff changeset
96
509
1b9973905e15 Fix to use js callbacks attached to 'window' + dummy changes in cmake files
Benjamin Golinvaux <bgo@osimis.io>
parents: 466
diff changeset
97 window.WasmWebService_NotifySuccess(callableSuccess, url_, new Uint8Array(this.response),
417
aee3d7941c9b preparing to load images using DICOMweb
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 315
diff changeset
98 this.response.byteLength, headers, payload);
315
aad37d0b6407 Added LayerWidget::RemoveLayer + DELETE commands in WebService
am@osimis.io
parents: 309
diff changeset
99 } else {
940
861c080ef47b handling httpStatus in WebService error messages
Alain Mazy <alain@mazy.be>
parents: 509
diff changeset
100 window.WasmWebService_NotifyError(callableFailure, url_, xhr.status, payload);
315
aad37d0b6407 Added LayerWidget::RemoveLayer + DELETE commands in WebService
am@osimis.io
parents: 309
diff changeset
101 }
aad37d0b6407 Added LayerWidget::RemoveLayer + DELETE commands in WebService
am@osimis.io
parents: 309
diff changeset
102 }
aad37d0b6407 Added LayerWidget::RemoveLayer + DELETE commands in WebService
am@osimis.io
parents: 309
diff changeset
103 }
aad37d0b6407 Added LayerWidget::RemoveLayer + DELETE commands in WebService
am@osimis.io
parents: 309
diff changeset
104
aad37d0b6407 Added LayerWidget::RemoveLayer + DELETE commands in WebService
am@osimis.io
parents: 309
diff changeset
105 xhr.send();
221
d7b2590744f8 wip: building applications reusable in SDL and WASM
am@osimis.io
parents:
diff changeset
106 }
315
aad37d0b6407 Added LayerWidget::RemoveLayer + DELETE commands in WebService
am@osimis.io
parents: 309
diff changeset
107
221
d7b2590744f8 wip: building applications reusable in SDL and WASM
am@osimis.io
parents:
diff changeset
108 });