Mercurial > hg > orthanc-stone
annotate Platforms/Wasm/wasm-application-runner.ts @ 418:c23df8b3433b
refactoring
author | Sebastien Jodogne <s.jodogne@gmail.com> |
---|---|
date | Thu, 15 Nov 2018 18:32:48 +0100 |
parents | e33659decec5 |
children | 26b90b110719 |
rev | line source |
---|---|
287 | 1 ///<reference path='stone-framework-loader.ts'/> |
2 ///<reference path='wasm-viewport.ts'/> | |
3 | |
4 if (!('WebAssembly' in window)) { | |
5 alert('Sorry, your browser does not support WebAssembly :('); | |
6 } | |
7 | |
8 declare var StoneFrameworkModule : Stone.Framework; | |
9 | |
10 // global functions | |
11 var WasmWebService_NotifyError: Function = null; | |
12 var WasmWebService_NotifySuccess: Function = null; | |
386
e33659decec5
renamed UpdateContent() as DoAnimation()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
314
diff
changeset
|
13 var WasmDoAnimation: Function = null; |
287 | 14 var SetStartupParameter: Function = null; |
15 var CreateWasmApplication: Function = null; | |
16 var CreateCppViewport: Function = null; | |
17 var ReleaseCppViewport: Function = null; | |
18 var StartWasmApplication: Function = null; | |
19 var SendMessageToStoneApplication: Function = null; | |
20 | |
21 | |
386
e33659decec5
renamed UpdateContent() as DoAnimation()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
314
diff
changeset
|
22 function DoAnimationThread() { |
e33659decec5
renamed UpdateContent() as DoAnimation()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
314
diff
changeset
|
23 if (WasmDoAnimation != null) { |
e33659decec5
renamed UpdateContent() as DoAnimation()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
314
diff
changeset
|
24 WasmDoAnimation(); |
287 | 25 } |
26 | |
386
e33659decec5
renamed UpdateContent() as DoAnimation()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
314
diff
changeset
|
27 setTimeout(DoAnimationThread, 100); // Update the viewport content every 100ms if need be |
287 | 28 } |
29 | |
30 | |
313 | 31 function GetUriParameters(): Map<string, string> { |
287 | 32 var parameters = window.location.search.substr(1); |
33 | |
34 if (parameters != null && | |
35 parameters != '') { | |
313 | 36 var result = new Map<string, string>(); |
287 | 37 var tokens = parameters.split('&'); |
38 | |
39 for (var i = 0; i < tokens.length; i++) { | |
40 var tmp = tokens[i].split('='); | |
41 if (tmp.length == 2) { | |
42 result[tmp[0]] = decodeURIComponent(tmp[1]); | |
43 } | |
44 } | |
45 | |
46 return result; | |
47 } | |
48 else { | |
313 | 49 return new Map<string, string>(); |
287 | 50 } |
51 } | |
52 | |
53 // function UpdateWebApplication(statusUpdateMessage: string) { | |
54 // console.log(statusUpdateMessage); | |
55 // } | |
56 | |
314 | 57 function _InitializeWasmApplication(orthancBaseUrl: string): void { |
287 | 58 |
59 CreateWasmApplication(); | |
60 | |
61 // parse uri and transmit the parameters to the app before initializing it | |
313 | 62 let parameters = GetUriParameters(); |
287 | 63 |
313 | 64 for (let key in parameters) { |
287 | 65 if (parameters.hasOwnProperty(key)) { |
66 SetStartupParameter(key, parameters[key]); | |
67 } | |
68 } | |
69 | |
418 | 70 StartWasmApplication(orthancBaseUrl); |
313 | 71 |
418 | 72 // trigger a first resize of the canvas that has just been initialized |
314 | 73 Stone.WasmViewport.ResizeAll(); |
287 | 74 |
386
e33659decec5
renamed UpdateContent() as DoAnimation()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
314
diff
changeset
|
75 DoAnimationThread(); |
287 | 76 } |
77 | |
314 | 78 function InitializeWasmApplication(wasmModuleName: string, orthancBaseUrl: string) { |
287 | 79 |
80 Stone.Framework.Configure(wasmModuleName); | |
81 | |
82 // Wait for the Orthanc Framework to be initialized (this initializes | |
83 // the WebAssembly environment) and then, create and initialize the Wasm application | |
84 Stone.Framework.Initialize(true, function () { | |
85 | |
86 console.log("Connecting C++ methods to JS methods"); | |
87 | |
88 SetStartupParameter = StoneFrameworkModule.cwrap('SetStartupParameter', null, ['string', 'string']); | |
89 CreateWasmApplication = StoneFrameworkModule.cwrap('CreateWasmApplication', null, ['number']); | |
90 CreateCppViewport = StoneFrameworkModule.cwrap('CreateCppViewport', 'number', []); | |
91 ReleaseCppViewport = StoneFrameworkModule.cwrap('ReleaseCppViewport', null, ['number']); | |
418 | 92 StartWasmApplication = StoneFrameworkModule.cwrap('StartWasmApplication', null, ['string']); |
287 | 93 |
94 WasmWebService_NotifySuccess = StoneFrameworkModule.cwrap('WasmWebService_NotifySuccess', null, ['number', 'string', 'array', 'number', 'number']); | |
95 WasmWebService_NotifyError = StoneFrameworkModule.cwrap('WasmWebService_NotifyError', null, ['number', 'string', 'number']); | |
386
e33659decec5
renamed UpdateContent() as DoAnimation()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
314
diff
changeset
|
96 WasmDoAnimation = StoneFrameworkModule.cwrap('WasmDoAnimation', null, []); |
287 | 97 |
98 SendMessageToStoneApplication = StoneFrameworkModule.cwrap('SendMessageToStoneApplication', 'string', ['string']); | |
99 | |
100 console.log("Connecting C++ methods to JS methods - done"); | |
101 | |
102 // Prevent scrolling | |
103 document.body.addEventListener('touchmove', function (event) { | |
104 event.preventDefault(); | |
105 }, false); | |
106 | |
314 | 107 _InitializeWasmApplication(orthancBaseUrl); |
287 | 108 }); |
109 } |