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
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
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
2038d76bf13f interaction with HTML/JS
am@osimis.io
parents:
diff changeset
3
2038d76bf13f interaction with HTML/JS
am@osimis.io
parents:
diff changeset
4 if (!('WebAssembly' in window)) {
2038d76bf13f interaction with HTML/JS
am@osimis.io
parents:
diff changeset
5 alert('Sorry, your browser does not support WebAssembly :(');
2038d76bf13f interaction with HTML/JS
am@osimis.io
parents:
diff changeset
6 }
2038d76bf13f interaction with HTML/JS
am@osimis.io
parents:
diff changeset
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
2038d76bf13f interaction with HTML/JS
am@osimis.io
parents:
diff changeset
10
2038d76bf13f interaction with HTML/JS
am@osimis.io
parents:
diff changeset
11 // global functions
2038d76bf13f interaction with HTML/JS
am@osimis.io
parents:
diff changeset
12 var WasmWebService_NotifyError: Function = null;
2038d76bf13f interaction with HTML/JS
am@osimis.io
parents:
diff changeset
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
2038d76bf13f interaction with HTML/JS
am@osimis.io
parents:
diff changeset
17 var SetStartupParameter: Function = null;
2038d76bf13f interaction with HTML/JS
am@osimis.io
parents:
diff changeset
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
2038d76bf13f interaction with HTML/JS
am@osimis.io
parents:
diff changeset
20 var ReleaseCppViewport: Function = null;
2038d76bf13f interaction with HTML/JS
am@osimis.io
parents:
diff changeset
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
2038d76bf13f interaction with HTML/JS
am@osimis.io
parents:
diff changeset
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
2038d76bf13f interaction with HTML/JS
am@osimis.io
parents:
diff changeset
27 }
2038d76bf13f interaction with HTML/JS
am@osimis.io
parents:
diff changeset
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
2038d76bf13f interaction with HTML/JS
am@osimis.io
parents:
diff changeset
30 }
2038d76bf13f interaction with HTML/JS
am@osimis.io
parents:
diff changeset
31
313
8bdc6112bc2e initial resize of canvas
am@osimis.io
parents: 303
diff changeset
32 function GetUriParameters(): Map<string, string> {
287
2038d76bf13f interaction with HTML/JS
am@osimis.io
parents:
diff changeset
33 var parameters = window.location.search.substr(1);
2038d76bf13f interaction with HTML/JS
am@osimis.io
parents:
diff changeset
34
2038d76bf13f interaction with HTML/JS
am@osimis.io
parents:
diff changeset
35 if (parameters != null &&
2038d76bf13f interaction with HTML/JS
am@osimis.io
parents:
diff changeset
36 parameters != '') {
313
8bdc6112bc2e initial resize of canvas
am@osimis.io
parents: 303
diff changeset
37 var result = new Map<string, string>();
287
2038d76bf13f interaction with HTML/JS
am@osimis.io
parents:
diff changeset
38 var tokens = parameters.split('&');
2038d76bf13f interaction with HTML/JS
am@osimis.io
parents:
diff changeset
39
2038d76bf13f interaction with HTML/JS
am@osimis.io
parents:
diff changeset
40 for (var i = 0; i < tokens.length; i++) {
2038d76bf13f interaction with HTML/JS
am@osimis.io
parents:
diff changeset
41 var tmp = tokens[i].split('=');
2038d76bf13f interaction with HTML/JS
am@osimis.io
parents:
diff changeset
42 if (tmp.length == 2) {
2038d76bf13f interaction with HTML/JS
am@osimis.io
parents:
diff changeset
43 result[tmp[0]] = decodeURIComponent(tmp[1]);
2038d76bf13f interaction with HTML/JS
am@osimis.io
parents:
diff changeset
44 }
2038d76bf13f interaction with HTML/JS
am@osimis.io
parents:
diff changeset
45 }
2038d76bf13f interaction with HTML/JS
am@osimis.io
parents:
diff changeset
46
2038d76bf13f interaction with HTML/JS
am@osimis.io
parents:
diff changeset
47 return result;
2038d76bf13f interaction with HTML/JS
am@osimis.io
parents:
diff changeset
48 }
2038d76bf13f interaction with HTML/JS
am@osimis.io
parents:
diff changeset
49 else {
313
8bdc6112bc2e initial resize of canvas
am@osimis.io
parents: 303
diff changeset
50 return new Map<string, string>();
287
2038d76bf13f interaction with HTML/JS
am@osimis.io
parents:
diff changeset
51 }
2038d76bf13f interaction with HTML/JS
am@osimis.io
parents:
diff changeset
52 }
2038d76bf13f interaction with HTML/JS
am@osimis.io
parents:
diff changeset
53
2038d76bf13f interaction with HTML/JS
am@osimis.io
parents:
diff changeset
54 // function UpdateWebApplication(statusUpdateMessage: string) {
2038d76bf13f interaction with HTML/JS
am@osimis.io
parents:
diff changeset
55 // console.log(statusUpdateMessage);
2038d76bf13f interaction with HTML/JS
am@osimis.io
parents:
diff changeset
56 // }
2038d76bf13f interaction with HTML/JS
am@osimis.io
parents:
diff changeset
57
314
97f16214dc5e cleanup
am@osimis.io
parents: 313
diff changeset
58 function _InitializeWasmApplication(orthancBaseUrl: string): void {
287
2038d76bf13f interaction with HTML/JS
am@osimis.io
parents:
diff changeset
59
2038d76bf13f interaction with HTML/JS
am@osimis.io
parents:
diff changeset
60 CreateWasmApplication();
2038d76bf13f interaction with HTML/JS
am@osimis.io
parents:
diff changeset
61
2038d76bf13f interaction with HTML/JS
am@osimis.io
parents:
diff changeset
62 // parse uri and transmit the parameters to the app before initializing it
313
8bdc6112bc2e initial resize of canvas
am@osimis.io
parents: 303
diff changeset
63 let parameters = GetUriParameters();
287
2038d76bf13f interaction with HTML/JS
am@osimis.io
parents:
diff changeset
64
313
8bdc6112bc2e initial resize of canvas
am@osimis.io
parents: 303
diff changeset
65 for (let key in parameters) {
287
2038d76bf13f interaction with HTML/JS
am@osimis.io
parents:
diff changeset
66 if (parameters.hasOwnProperty(key)) {
2038d76bf13f interaction with HTML/JS
am@osimis.io
parents:
diff changeset
67 SetStartupParameter(key, parameters[key]);
2038d76bf13f interaction with HTML/JS
am@osimis.io
parents:
diff changeset
68 }
2038d76bf13f interaction with HTML/JS
am@osimis.io
parents:
diff changeset
69 }
2038d76bf13f interaction with HTML/JS
am@osimis.io
parents:
diff changeset
70
418
c23df8b3433b refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 386
diff changeset
71 StartWasmApplication(orthancBaseUrl);
313
8bdc6112bc2e initial resize of canvas
am@osimis.io
parents: 303
diff changeset
72
418
c23df8b3433b refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 386
diff changeset
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
2038d76bf13f interaction with HTML/JS
am@osimis.io
parents:
diff changeset
75
386
e33659decec5 renamed UpdateContent() as DoAnimation()
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 314
diff changeset
76 DoAnimationThread();
287
2038d76bf13f interaction with HTML/JS
am@osimis.io
parents:
diff changeset
77 }
2038d76bf13f interaction with HTML/JS
am@osimis.io
parents:
diff changeset
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
2038d76bf13f interaction with HTML/JS
am@osimis.io
parents:
diff changeset
80
2038d76bf13f interaction with HTML/JS
am@osimis.io
parents:
diff changeset
81 Stone.Framework.Configure(wasmModuleName);
2038d76bf13f interaction with HTML/JS
am@osimis.io
parents:
diff changeset
82
2038d76bf13f interaction with HTML/JS
am@osimis.io
parents:
diff changeset
83 // Wait for the Orthanc Framework to be initialized (this initializes
2038d76bf13f interaction with HTML/JS
am@osimis.io
parents:
diff changeset
84 // the WebAssembly environment) and then, create and initialize the Wasm application
2038d76bf13f interaction with HTML/JS
am@osimis.io
parents:
diff changeset
85 Stone.Framework.Initialize(true, function () {
2038d76bf13f interaction with HTML/JS
am@osimis.io
parents:
diff changeset
86
2038d76bf13f interaction with HTML/JS
am@osimis.io
parents:
diff changeset
87 console.log("Connecting C++ methods to JS methods");
2038d76bf13f interaction with HTML/JS
am@osimis.io
parents:
diff changeset
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
2038d76bf13f interaction with HTML/JS
am@osimis.io
parents:
diff changeset
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
2038d76bf13f interaction with HTML/JS
am@osimis.io
parents:
diff changeset
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
2038d76bf13f interaction with HTML/JS
am@osimis.io
parents:
diff changeset
103
2038d76bf13f interaction with HTML/JS
am@osimis.io
parents:
diff changeset
104 console.log("Connecting C++ methods to JS methods - done");
2038d76bf13f interaction with HTML/JS
am@osimis.io
parents:
diff changeset
105
2038d76bf13f interaction with HTML/JS
am@osimis.io
parents:
diff changeset
106 // Prevent scrolling
2038d76bf13f interaction with HTML/JS
am@osimis.io
parents:
diff changeset
107 document.body.addEventListener('touchmove', function (event) {
2038d76bf13f interaction with HTML/JS
am@osimis.io
parents:
diff changeset
108 event.preventDefault();
2038d76bf13f interaction with HTML/JS
am@osimis.io
parents:
diff changeset
109 }, false);
2038d76bf13f interaction with HTML/JS
am@osimis.io
parents:
diff changeset
110
314
97f16214dc5e cleanup
am@osimis.io
parents: 313
diff changeset
111 _InitializeWasmApplication(orthancBaseUrl);
287
2038d76bf13f interaction with HTML/JS
am@osimis.io
parents:
diff changeset
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