Mercurial > hg > orthanc-stone
comparison Platforms/WebAssembly/wasm-application.js @ 223:d30a10d574ec am
refactoring continued - not working
author | am@osimis.io |
---|---|
date | Thu, 14 Jun 2018 10:57:02 +0200 |
parents | |
children | 1fa4c65c7e1b |
comparison
equal
deleted
inserted
replaced
222:84844649a8fd | 223:d30a10d574ec |
---|---|
1 | |
2 | |
3 // Global context used by "library.js" | |
4 var viewport = null; | |
5 var WasmWebService_NotifyError = null; | |
6 var WasmWebService_NotifySuccess = null; | |
7 //var NotifyRestApiGet = null; | |
8 var NotifyUpdateContent = null; | |
9 | |
10 function UpdateContentThread() | |
11 { | |
12 if (NotifyUpdateContent != null) { | |
13 NotifyUpdateContent(); | |
14 } | |
15 | |
16 setTimeout(UpdateContentThread, 100); // Update the viewport content every 100ms if need be | |
17 } | |
18 | |
19 | |
20 function GetUriParameters() | |
21 { | |
22 var parameters = window.location.search.substr(1); | |
23 | |
24 if (parameters != null && | |
25 parameters != '') | |
26 { | |
27 var result = {}; | |
28 var tokens = parameters.split('&'); | |
29 | |
30 for (var i = 0; i < tokens.length; i++) { | |
31 var tmp = tokens[i].split('='); | |
32 if (tmp.length == 2) { | |
33 result[tmp[0]] = decodeURIComponent(tmp[1]); | |
34 } | |
35 } | |
36 | |
37 return result; | |
38 } | |
39 else | |
40 { | |
41 return {}; | |
42 } | |
43 } | |
44 | |
45 | |
46 | |
47 function InitializeWasmApplication(canvasId) | |
48 { | |
49 console.log("Initializing wasm-app"); | |
50 viewport = WebAssemblyViewport(StoneFrameworkModule, 'canvas'); | |
51 | |
52 /******************** */ | |
53 SetStartupParameter = StoneFrameworkModule.cwrap('SetStartupParameter', null, [ 'string', 'string' ]); | |
54 CreateWasmApplication = StoneFrameworkModule.cwrap('CreateWasmApplication', null, [ ], [ ]); | |
55 StartWasmApplication = StoneFrameworkModule.cwrap('StartWasmApplication', null, [ ], [ ]); | |
56 | |
57 /******************** */ | |
58 | |
59 // NotifyGlobalParameter = StoneFrameworkModule.cwrap('NotifyGlobalParameter', null, | |
60 // [ 'string', 'string' ]); | |
61 // ViewportUpdate = StoneFrameworkModule.cwrap('ViewportUpdate', null, | |
62 // [ 'string' ]); | |
63 WasmWebService_NotifySuccess = StoneFrameworkModule.cwrap('WasmWebService_NotifySuccess', null, | |
64 [ 'number', 'string', 'array', 'number', 'number' ]); | |
65 WasmWebService_NotifyError = StoneFrameworkModule.cwrap('WasmWebService_NotifyError', null, | |
66 [ 'number', 'string', 'number' ]); | |
67 //NotifyRestApiGet = Module.cwrap('NotifyRestApiGet', null, [ 'number', 'array', 'number' ]); | |
68 NotifyUpdateContent = StoneFrameworkModule.cwrap('NotifyUpdateContent', null, [ ]); | |
69 | |
70 // Prevent scrolling | |
71 document.body.addEventListener('touchmove', function(event) { | |
72 event.preventDefault(); | |
73 }, false); | |
74 | |
75 document.getElementById('canvas').onclick = function() { | |
76 viewport.Redraw(); | |
77 }; | |
78 | |
79 | |
80 /************************************** */ | |
81 CreateWasmApplication(); | |
82 | |
83 // parse uri and transmit the parameters to the app before initializing it | |
84 var parameters = GetUriParameters(); | |
85 | |
86 for (var key in parameters) { | |
87 if (parameters.hasOwnProperty(key)) { | |
88 SetStartupParameter(key, parameters[key]); | |
89 } | |
90 } | |
91 | |
92 StartWasmApplication(); | |
93 /************************************** */ | |
94 | |
95 UpdateContentThread(); | |
96 } | |
97 | |
98 if (!('WebAssembly' in window)) { | |
99 alert('Sorry, your browser does not support WebAssembly :('); | |
100 } else { | |
101 | |
102 } |