Mercurial > hg > orthanc-stone
comparison Resources/Graveyard/Deprecated/Platforms/Wasm/WasmWebService.js @ 1503:553084468225
moving /Deprecated/ to /Resources/Graveyard/Deprecated/
author | Sebastien Jodogne <s.jodogne@gmail.com> |
---|---|
date | Tue, 30 Jun 2020 11:38:13 +0200 |
parents | Deprecated/Platforms/Wasm/WasmWebService.js@419d0320c344 |
children |
comparison
equal
deleted
inserted
replaced
1502:e5729dab3f67 | 1503:553084468225 |
---|---|
1 mergeInto(LibraryManager.library, { | |
2 WasmWebService_GetAsync: function(callableSuccess, callableFailure, url, headersInJsonString, payload, timeoutInSeconds) { | |
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 url_ = UTF8ToString(url); | |
7 var headersInJsonString_ = UTF8ToString(headersInJsonString); | |
8 | |
9 xhr.open('GET', url_, true); | |
10 xhr.responseType = 'arraybuffer'; | |
11 xhr.timeout = timeoutInSeconds * 1000; | |
12 var headers = JSON.parse(headersInJsonString_); | |
13 for (var key in headers) { | |
14 xhr.setRequestHeader(key, headers[key]); | |
15 } | |
16 //console.log(xhr); | |
17 xhr.onreadystatechange = function() { | |
18 if (this.readyState == XMLHttpRequest.DONE) { | |
19 if (xhr.status === 200) { | |
20 var s = xhr.getAllResponseHeaders(); | |
21 var headers = _malloc(s.length + 1); | |
22 stringToUTF8(s, headers, s.length + 1); | |
23 | |
24 // TODO - Is "new Uint8Array()" necessary? This copies the | |
25 // answer to the WebAssembly stack, hence necessitating | |
26 // increasing the TOTAL_STACK parameter of Emscripten | |
27 window.WasmWebService_NotifySuccess(callableSuccess, url_, new Uint8Array(this.response), | |
28 this.response.byteLength, headers, payload); | |
29 } else { | |
30 window.WasmWebService_NotifyError(callableFailure, url_, xhr.status, payload); | |
31 } | |
32 } | |
33 } | |
34 | |
35 xhr.send(); | |
36 }, | |
37 | |
38 WasmWebService_ScheduleLaterCachedSuccessNotification: function (brol) { | |
39 setTimeout(function() { | |
40 window.WasmWebService_NotifyCachedSuccess(brol); | |
41 }, 0); | |
42 }, | |
43 | |
44 WasmWebService_PostAsync: function(callableSuccess, callableFailure, url, headersInJsonString, body, bodySize, payload, timeoutInSeconds) { | |
45 var xhr = new XMLHttpRequest(); | |
46 var url_ = UTF8ToString(url); | |
47 var headersInJsonString_ = UTF8ToString(headersInJsonString); | |
48 xhr.open('POST', url_, true); | |
49 xhr.timeout = timeoutInSeconds * 1000; | |
50 xhr.responseType = 'arraybuffer'; | |
51 xhr.setRequestHeader('Content-type', 'application/octet-stream'); | |
52 | |
53 var headers = JSON.parse(headersInJsonString_); | |
54 for (var key in headers) { | |
55 xhr.setRequestHeader(key, headers[key]); | |
56 } | |
57 | |
58 xhr.onreadystatechange = function() { | |
59 if (this.readyState == XMLHttpRequest.DONE) { | |
60 if (xhr.status === 200) { | |
61 var s = xhr.getAllResponseHeaders(); | |
62 var headers = _malloc(s.length + 1); | |
63 stringToUTF8(s, headers, s.length + 1); | |
64 | |
65 window.WasmWebService_NotifySuccess(callableSuccess, url_, new Uint8Array(this.response), | |
66 this.response.byteLength, headers, payload); | |
67 } else { | |
68 window.WasmWebService_NotifyError(callableFailure, url_, xhr.status, payload); | |
69 } | |
70 } | |
71 } | |
72 | |
73 xhr.send(new Uint8ClampedArray(HEAPU8.buffer, body, bodySize)); | |
74 }, | |
75 | |
76 WasmWebService_DeleteAsync: function(callableSuccess, callableFailure, url, headersInJsonString, payload, timeoutInSeconds) { | |
77 var xhr = new XMLHttpRequest(); | |
78 var url_ = UTF8ToString(url); | |
79 var headersInJsonString_ = UTF8ToString(headersInJsonString); | |
80 xhr.open('DELETE', url_, true); | |
81 xhr.timeout = timeoutInSeconds * 1000; | |
82 xhr.responseType = 'arraybuffer'; | |
83 xhr.setRequestHeader('Content-type', 'application/octet-stream'); | |
84 | |
85 var headers = JSON.parse(headersInJsonString_); | |
86 for (var key in headers) { | |
87 xhr.setRequestHeader(key, headers[key]); | |
88 } | |
89 | |
90 xhr.onreadystatechange = function() { | |
91 if (this.readyState == XMLHttpRequest.DONE) { | |
92 if (xhr.status === 200) { | |
93 var s = xhr.getAllResponseHeaders(); | |
94 var headers = _malloc(s.length + 1); | |
95 stringToUTF8(s, headers, s.length + 1); | |
96 | |
97 window.WasmWebService_NotifySuccess(callableSuccess, url_, new Uint8Array(this.response), | |
98 this.response.byteLength, headers, payload); | |
99 } else { | |
100 window.WasmWebService_NotifyError(callableFailure, url_, xhr.status, payload); | |
101 } | |
102 } | |
103 } | |
104 | |
105 xhr.send(); | |
106 } | |
107 | |
108 }); |