Mercurial > hg > orthanc-stone
comparison Samples/WebAssembly/SingleFrameViewer/SingleFrameViewerApp.js @ 1354:c0e4eb14c912 broker
SingleFrameViewer WASM working OK
author | Benjamin Golinvaux <bgo@osimis.io> |
---|---|
date | Wed, 15 Apr 2020 12:59:15 +0200 |
parents | |
children | 240531afdd2d |
comparison
equal
deleted
inserted
replaced
1353:af65bce18951 | 1354:c0e4eb14c912 |
---|---|
1 | |
2 // This object wraps the functions exposed by the wasm module | |
3 | |
4 const WasmModuleWrapper = function() { | |
5 this._InitializeViewport = undefined; | |
6 this._LoadOrthanc = undefined; | |
7 this._LoadDicomWeb = undefined; | |
8 }; | |
9 | |
10 WasmModuleWrapper.prototype.Setup = function(Module) { | |
11 this._InitializeViewport = Module.cwrap('InitializeViewport', null, [ 'string' ]); | |
12 this._LoadOrthanc = Module.cwrap('LoadOrthanc', null, [ 'string', 'int' ]); | |
13 this._LoadDicomWeb = Module.cwrap('LoadDicomWeb', null, [ 'string', 'string', 'string', 'string', 'int' ]); | |
14 }; | |
15 | |
16 WasmModuleWrapper.prototype.InitializeViewport = function(canvasId) { | |
17 this._InitializeViewport(canvasId); | |
18 }; | |
19 | |
20 WasmModuleWrapper.prototype.LoadOrthanc = function(instance, frame) { | |
21 this._LoadOrthanc(instance, frame); | |
22 }; | |
23 | |
24 WasmModuleWrapper.prototype.LoadDicomWeb = function(server, studyInstanceUid, seriesInstanceUid, sopInstanceUid, frame) { | |
25 this._LoadDicomWeb(server, studyInstanceUid, seriesInstanceUid, sopInstanceUid, frame); | |
26 }; | |
27 | |
28 var moduleWrapper = new WasmModuleWrapper(); | |
29 | |
30 $(document).ready(function() { | |
31 | |
32 window.addEventListener('StoneInitialized', function() { | |
33 stone.Setup(Module); | |
34 console.warn('Native Stone properly intialized'); | |
35 | |
36 stone.InitializeViewport('viewport'); | |
37 }); | |
38 | |
39 window.addEventListener('StoneException', function() { | |
40 alert('Exception caught in Stone'); | |
41 }); | |
42 | |
43 var scriptSource; | |
44 | |
45 if ('WebAssembly' in window) { | |
46 console.warn('Loading WebAssembly'); | |
47 scriptSource = 'SingleFrameViewerWasm.js'; | |
48 } else { | |
49 console.error('Your browser does not support WebAssembly!'); | |
50 } | |
51 | |
52 // Option 1: Loading script using plain HTML | |
53 | |
54 /* | |
55 var script = document.createElement('script'); | |
56 script.src = scriptSource; | |
57 script.type = 'text/javascript'; | |
58 document.body.appendChild(script); | |
59 */ | |
60 | |
61 // Option 2: Loading script using AJAX (gives the opportunity to | |
62 // report explicit errors) | |
63 | |
64 axios.get(scriptSource) | |
65 .then(function (response) { | |
66 var script = document.createElement('script'); | |
67 script.innerHTML = response.data; | |
68 script.type = 'text/javascript'; | |
69 document.body.appendChild(script); | |
70 }) | |
71 .catch(function (error) { | |
72 alert('Cannot load the WebAssembly framework'); | |
73 }); | |
74 }); | |
75 | |
76 | |
77 $('#orthancLoad').click(function() { | |
78 stone.LoadOrthanc($('#orthancInstance').val(), | |
79 $('#orthancFrame').val()); | |
80 }); | |
81 | |
82 | |
83 $('#dicomWebLoad').click(function() { | |
84 stone.LoadDicomWeb($('#dicomWebServer').val(), | |
85 $('#dicomWebStudy').val(), | |
86 $('#dicomWebSeries').val(), | |
87 $('#dicomWebInstance').val(), | |
88 $('#dicomWebFrame').val()); | |
89 }); |