Mercurial > hg > orthanc-stone
annotate Platforms/Wasm/wasm-application-runner.ts @ 466:5055031f4a06 bgo-commands-codegen
- Added browserify to build. This allows using require calls for modules that
work with tsc compiler.
- removed older stuff related to Protocol Buffers and Flatbuffers
- changed triple-slash references to import statements
- module prefixes are now added at call sites
- added cmake module for filename handling
- switched to Ninja for sample build
- Added virtual dtor in ICommand
author | bgo-osimis |
---|---|
date | Mon, 11 Feb 2019 16:00:04 +0100 |
parents | e641d3978856 |
children | 7105a0bad250 |
rev | line source |
---|---|
466
5055031f4a06
- Added browserify to build. This allows using require calls for modules that
bgo-osimis
parents:
435
diff
changeset
|
1 import Stone = require('./stone-framework-loader'); |
5055031f4a06
- Added browserify to build. This allows using require calls for modules that
bgo-osimis
parents:
435
diff
changeset
|
2 import StoneViewport = require('./wasm-viewport'); |
287 | 3 |
4 if (!('WebAssembly' in window)) { | |
5 alert('Sorry, your browser does not support WebAssembly :('); | |
6 } | |
7 | |
466
5055031f4a06
- Added browserify to build. This allows using require calls for modules that
bgo-osimis
parents:
435
diff
changeset
|
8 //var StoneFrameworkModule : Stone.Framework = (<any>window).StoneFrameworkModule; |
5055031f4a06
- Added browserify to build. This allows using require calls for modules that
bgo-osimis
parents:
435
diff
changeset
|
9 //export declare var StoneFrameworkModule : Stone.Framework; |
287 | 10 |
11 // global functions | |
12 var WasmWebService_NotifyError: Function = null; | |
13 var WasmWebService_NotifySuccess: Function = null; | |
435
e641d3978856
WasmWebService now using BaseWebService and supporting cache
am@osimis.io
parents:
431
diff
changeset
|
14 var WasmWebService_NotifyCachedSuccess: Function = null; |
431
26b90b110719
added DelayedCallExecutor to avoid using sleep() in C++ that consumes 100% CPU once executed in WASM
am@osimis.io
parents:
418
diff
changeset
|
15 var WasmDelayedCallExecutor_ExecuteCallback: Function = null; |
386
e33659decec5
renamed UpdateContent() as DoAnimation()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
314
diff
changeset
|
16 var WasmDoAnimation: Function = null; |
287 | 17 var SetStartupParameter: Function = null; |
18 var CreateWasmApplication: Function = null; | |
466
5055031f4a06
- Added browserify to build. This allows using require calls for modules that
bgo-osimis
parents:
435
diff
changeset
|
19 export var CreateCppViewport: Function = null; |
287 | 20 var ReleaseCppViewport: Function = null; |
21 var StartWasmApplication: Function = null; | |
466
5055031f4a06
- Added browserify to build. This allows using require calls for modules that
bgo-osimis
parents:
435
diff
changeset
|
22 export var SendMessageToStoneApplication: Function = null; |
287 | 23 |
386
e33659decec5
renamed UpdateContent() as DoAnimation()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
314
diff
changeset
|
24 function DoAnimationThread() { |
e33659decec5
renamed UpdateContent() as DoAnimation()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
314
diff
changeset
|
25 if (WasmDoAnimation != null) { |
e33659decec5
renamed UpdateContent() as DoAnimation()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
314
diff
changeset
|
26 WasmDoAnimation(); |
287 | 27 } |
28 | |
386
e33659decec5
renamed UpdateContent() as DoAnimation()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
314
diff
changeset
|
29 setTimeout(DoAnimationThread, 100); // Update the viewport content every 100ms if need be |
287 | 30 } |
31 | |
313 | 32 function GetUriParameters(): Map<string, string> { |
287 | 33 var parameters = window.location.search.substr(1); |
34 | |
35 if (parameters != null && | |
36 parameters != '') { | |
313 | 37 var result = new Map<string, string>(); |
287 | 38 var tokens = parameters.split('&'); |
39 | |
40 for (var i = 0; i < tokens.length; i++) { | |
41 var tmp = tokens[i].split('='); | |
42 if (tmp.length == 2) { | |
43 result[tmp[0]] = decodeURIComponent(tmp[1]); | |
44 } | |
45 } | |
46 | |
47 return result; | |
48 } | |
49 else { | |
313 | 50 return new Map<string, string>(); |
287 | 51 } |
52 } | |
53 | |
54 // function UpdateWebApplication(statusUpdateMessage: string) { | |
55 // console.log(statusUpdateMessage); | |
56 // } | |
57 | |
314 | 58 function _InitializeWasmApplication(orthancBaseUrl: string): void { |
287 | 59 |
60 CreateWasmApplication(); | |
61 | |
62 // parse uri and transmit the parameters to the app before initializing it | |
313 | 63 let parameters = GetUriParameters(); |
287 | 64 |
313 | 65 for (let key in parameters) { |
287 | 66 if (parameters.hasOwnProperty(key)) { |
67 SetStartupParameter(key, parameters[key]); | |
68 } | |
69 } | |
70 | |
418 | 71 StartWasmApplication(orthancBaseUrl); |
313 | 72 |
418 | 73 // trigger a first resize of the canvas that has just been initialized |
466
5055031f4a06
- Added browserify to build. This allows using require calls for modules that
bgo-osimis
parents:
435
diff
changeset
|
74 StoneViewport.WasmViewport.ResizeAll(); |
287 | 75 |
386
e33659decec5
renamed UpdateContent() as DoAnimation()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
314
diff
changeset
|
76 DoAnimationThread(); |
287 | 77 } |
78 | |
466
5055031f4a06
- Added browserify to build. This allows using require calls for modules that
bgo-osimis
parents:
435
diff
changeset
|
79 export function InitializeWasmApplication(wasmModuleName: string, orthancBaseUrl: string) { |
287 | 80 |
81 Stone.Framework.Configure(wasmModuleName); | |
82 | |
83 // Wait for the Orthanc Framework to be initialized (this initializes | |
84 // the WebAssembly environment) and then, create and initialize the Wasm application | |
85 Stone.Framework.Initialize(true, function () { | |
86 | |
87 console.log("Connecting C++ methods to JS methods"); | |
88 | |
466
5055031f4a06
- Added browserify to build. This allows using require calls for modules that
bgo-osimis
parents:
435
diff
changeset
|
89 SetStartupParameter = (<any> window).StoneFrameworkModule.cwrap('SetStartupParameter', null, ['string', 'string']); |
5055031f4a06
- Added browserify to build. This allows using require calls for modules that
bgo-osimis
parents:
435
diff
changeset
|
90 CreateWasmApplication = (<any> window).StoneFrameworkModule.cwrap('CreateWasmApplication', null, ['number']); |
5055031f4a06
- Added browserify to build. This allows using require calls for modules that
bgo-osimis
parents:
435
diff
changeset
|
91 CreateCppViewport = (<any> window).StoneFrameworkModule.cwrap('CreateCppViewport', 'number', []); |
5055031f4a06
- Added browserify to build. This allows using require calls for modules that
bgo-osimis
parents:
435
diff
changeset
|
92 ReleaseCppViewport = (<any> window).StoneFrameworkModule.cwrap('ReleaseCppViewport', null, ['number']); |
5055031f4a06
- Added browserify to build. This allows using require calls for modules that
bgo-osimis
parents:
435
diff
changeset
|
93 StartWasmApplication = (<any> window).StoneFrameworkModule.cwrap('StartWasmApplication', null, ['string']); |
287 | 94 |
466
5055031f4a06
- Added browserify to build. This allows using require calls for modules that
bgo-osimis
parents:
435
diff
changeset
|
95 (<any> window).WasmWebService_NotifyCachedSuccess = (<any> window).StoneFrameworkModule.cwrap('WasmWebService_NotifyCachedSuccess', null, ['number']); |
5055031f4a06
- Added browserify to build. This allows using require calls for modules that
bgo-osimis
parents:
435
diff
changeset
|
96 (<any> window).WasmWebService_NotifySuccess = (<any> window).StoneFrameworkModule.cwrap('WasmWebService_NotifySuccess', null, ['number', 'string', 'array', 'number', 'number']); |
5055031f4a06
- Added browserify to build. This allows using require calls for modules that
bgo-osimis
parents:
435
diff
changeset
|
97 (<any> window).WasmWebService_NotifyError = (<any> window).StoneFrameworkModule.cwrap('WasmWebService_NotifyError', null, ['number', 'string', 'number']); |
5055031f4a06
- Added browserify to build. This allows using require calls for modules that
bgo-osimis
parents:
435
diff
changeset
|
98 (<any> window).WasmDelayedCallExecutor_ExecuteCallback = (<any> window).StoneFrameworkModule.cwrap('WasmDelayedCallExecutor_ExecuteCallback', null, ['number']); |
5055031f4a06
- Added browserify to build. This allows using require calls for modules that
bgo-osimis
parents:
435
diff
changeset
|
99 // no need to put this into the globals for it's only used in this very module |
5055031f4a06
- Added browserify to build. This allows using require calls for modules that
bgo-osimis
parents:
435
diff
changeset
|
100 WasmDoAnimation = (<any> window).StoneFrameworkModule.cwrap('WasmDoAnimation', null, []); |
287 | 101 |
466
5055031f4a06
- Added browserify to build. This allows using require calls for modules that
bgo-osimis
parents:
435
diff
changeset
|
102 SendMessageToStoneApplication = (<any> window).StoneFrameworkModule.cwrap('SendMessageToStoneApplication', 'string', ['string']); |
287 | 103 |
104 console.log("Connecting C++ methods to JS methods - done"); | |
105 | |
106 // Prevent scrolling | |
107 document.body.addEventListener('touchmove', function (event) { | |
108 event.preventDefault(); | |
109 }, false); | |
110 | |
314 | 111 _InitializeWasmApplication(orthancBaseUrl); |
287 | 112 }); |
466
5055031f4a06
- Added browserify to build. This allows using require calls for modules that
bgo-osimis
parents:
435
diff
changeset
|
113 } |
5055031f4a06
- Added browserify to build. This allows using require calls for modules that
bgo-osimis
parents:
435
diff
changeset
|
114 |
5055031f4a06
- Added browserify to build. This allows using require calls for modules that
bgo-osimis
parents:
435
diff
changeset
|
115 |
5055031f4a06
- Added browserify to build. This allows using require calls for modules that
bgo-osimis
parents:
435
diff
changeset
|
116 // exports.InitializeWasmApplication = InitializeWasmApplication; |
5055031f4a06
- Added browserify to build. This allows using require calls for modules that
bgo-osimis
parents:
435
diff
changeset
|
117 |
5055031f4a06
- Added browserify to build. This allows using require calls for modules that
bgo-osimis
parents:
435
diff
changeset
|
118 |
5055031f4a06
- Added browserify to build. This allows using require calls for modules that
bgo-osimis
parents:
435
diff
changeset
|
119 |