Mercurial > hg > orthanc-stone
comparison OrthancStone/Samples/WebAssembly/SingleFrameViewer/SingleFrameViewerApp.js @ 1512:244ad1e4e76a
reorganization of folders
author | Sebastien Jodogne <s.jodogne@gmail.com> |
---|---|
date | Tue, 07 Jul 2020 16:21:02 +0200 |
parents | Samples/WebAssembly/SingleFrameViewer/SingleFrameViewerApp.js@27e0a00bd3e8 |
children |
comparison
equal
deleted
inserted
replaced
1511:9dfeee74c1e6 | 1512:244ad1e4e76a |
---|---|
1 | |
2 // This object wraps the functions exposed by the wasm module | |
3 | |
4 const WasmModuleWrapper = function() { | |
5 this._InitializeViewport = undefined; | |
6 this._LoadFromOrthanc = undefined; | |
7 }; | |
8 | |
9 WasmModuleWrapper.prototype.Setup = function(Module) { | |
10 this._InitializeViewport = Module.cwrap('InitializeViewport', null, [ 'string' ]); | |
11 this._LoadFromOrthanc = Module.cwrap('LoadFromOrthanc', null, [ 'string', 'int' ]); | |
12 }; | |
13 | |
14 WasmModuleWrapper.prototype.InitializeViewport = function(canvasId) { | |
15 this._InitializeViewport(canvasId); | |
16 }; | |
17 | |
18 WasmModuleWrapper.prototype.LoadFromOrthanc = function(instance, frame) { | |
19 this._LoadFromOrthanc(instance, frame); | |
20 }; | |
21 | |
22 var wasmModuleWrapper = new WasmModuleWrapper(); | |
23 | |
24 $(document).ready(function() { | |
25 | |
26 window.addEventListener('WasmModuleInitialized', function() { | |
27 wasmModuleWrapper.Setup(Module); | |
28 console.warn('Native C++ module initialized'); | |
29 | |
30 wasmModuleWrapper.InitializeViewport('viewport'); | |
31 }); | |
32 | |
33 window.addEventListener('StoneException', function() { | |
34 alert('Exception caught in C++ code'); | |
35 }); | |
36 | |
37 var scriptSource; | |
38 | |
39 if ('WebAssembly' in window) { | |
40 console.warn('Loading WebAssembly'); | |
41 scriptSource = 'SingleFrameViewerWasm.js'; | |
42 } else { | |
43 console.error('Your browser does not support WebAssembly!'); | |
44 } | |
45 | |
46 // Option 1: Loading script using plain HTML | |
47 | |
48 /* | |
49 var script = document.createElement('script'); | |
50 script.src = scriptSource; | |
51 script.type = 'text/javascript'; | |
52 document.body.appendChild(script); | |
53 */ | |
54 | |
55 // Option 2: Loading script using AJAX (gives the opportunity to | |
56 // report explicit errors) | |
57 | |
58 axios.get(scriptSource) | |
59 .then(function (response) { | |
60 var script = document.createElement('script'); | |
61 script.innerHTML = response.data; | |
62 script.type = 'text/javascript'; | |
63 document.body.appendChild(script); | |
64 }) | |
65 .catch(function (error) { | |
66 alert('Cannot load the WebAssembly framework'); | |
67 }); | |
68 }); | |
69 | |
70 | |
71 $('#orthancLoad').click(function() { | |
72 wasmModuleWrapper.LoadFromOrthanc($('#orthancInstance').val(), | |
73 $('#orthancFrame').val()); | |
74 }); |