annotate Platforms/Wasm/wasm-application-runner.ts @ 603:70992b38aa8a

new routable logging system in STDIO mode + flag support (with no value) in StartupParametersBuilder + 80 col indent
author Benjamin Golinvaux <bgo@osimis.io>
date Mon, 29 Apr 2019 15:09:48 +0200
parents e1ba16436d59
children 28b9e3a54200
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');
526
548eed46f535 introduced a Logger class that displays timing and source (C++/JS)
Alain Mazy <alain@mazy.be>
parents: 508
diff changeset
3 import * as Logger from './logger'
287
2038d76bf13f interaction with HTML/JS
am@osimis.io
parents:
diff changeset
4
2038d76bf13f interaction with HTML/JS
am@osimis.io
parents:
diff changeset
5 if (!('WebAssembly' in window)) {
2038d76bf13f interaction with HTML/JS
am@osimis.io
parents:
diff changeset
6 alert('Sorry, your browser does not support WebAssembly :(');
2038d76bf13f interaction with HTML/JS
am@osimis.io
parents:
diff changeset
7 }
2038d76bf13f interaction with HTML/JS
am@osimis.io
parents:
diff changeset
8
466
5055031f4a06 - Added browserify to build. This allows using require calls for modules that
bgo-osimis
parents: 435
diff changeset
9 //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
10 //export declare var StoneFrameworkModule : Stone.Framework;
287
2038d76bf13f interaction with HTML/JS
am@osimis.io
parents:
diff changeset
11
2038d76bf13f interaction with HTML/JS
am@osimis.io
parents:
diff changeset
12 // global functions
2038d76bf13f interaction with HTML/JS
am@osimis.io
parents:
diff changeset
13 var WasmWebService_NotifyError: Function = null;
2038d76bf13f interaction with HTML/JS
am@osimis.io
parents:
diff changeset
14 var WasmWebService_NotifySuccess: Function = null;
435
e641d3978856 WasmWebService now using BaseWebService and supporting cache
am@osimis.io
parents: 431
diff changeset
15 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
16 var WasmDelayedCallExecutor_ExecuteCallback: Function = null;
386
e33659decec5 renamed UpdateContent() as DoAnimation()
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 314
diff changeset
17 var WasmDoAnimation: Function = null;
287
2038d76bf13f interaction with HTML/JS
am@osimis.io
parents:
diff changeset
18 var SetStartupParameter: Function = null;
2038d76bf13f interaction with HTML/JS
am@osimis.io
parents:
diff changeset
19 var CreateWasmApplication: Function = null;
466
5055031f4a06 - Added browserify to build. This allows using require calls for modules that
bgo-osimis
parents: 435
diff changeset
20 export var CreateCppViewport: Function = null;
287
2038d76bf13f interaction with HTML/JS
am@osimis.io
parents:
diff changeset
21 var ReleaseCppViewport: Function = null;
2038d76bf13f interaction with HTML/JS
am@osimis.io
parents:
diff changeset
22 var StartWasmApplication: Function = null;
508
7105a0bad250 - Added HandleSerializedMessage to IStoneApplication (empty impl)
Benjamin Golinvaux <bgo@osimis.io>
parents: 466
diff changeset
23 export var SendSerializedMessageToStoneApplication: Function = null;
287
2038d76bf13f interaction with HTML/JS
am@osimis.io
parents:
diff changeset
24
386
e33659decec5 renamed UpdateContent() as DoAnimation()
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 314
diff changeset
25 function DoAnimationThread() {
e33659decec5 renamed UpdateContent() as DoAnimation()
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 314
diff changeset
26 if (WasmDoAnimation != null) {
e33659decec5 renamed UpdateContent() as DoAnimation()
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 314
diff changeset
27 WasmDoAnimation();
287
2038d76bf13f interaction with HTML/JS
am@osimis.io
parents:
diff changeset
28 }
2038d76bf13f interaction with HTML/JS
am@osimis.io
parents:
diff changeset
29
603
70992b38aa8a new routable logging system in STDIO mode + flag support (with no value) in StartupParametersBuilder + 80 col indent
Benjamin Golinvaux <bgo@osimis.io>
parents: 545
diff changeset
30 // Update the viewport content every 100ms if need be
70992b38aa8a new routable logging system in STDIO mode + flag support (with no value) in StartupParametersBuilder + 80 col indent
Benjamin Golinvaux <bgo@osimis.io>
parents: 545
diff changeset
31 setTimeout(DoAnimationThread, 100);
287
2038d76bf13f interaction with HTML/JS
am@osimis.io
parents:
diff changeset
32 }
2038d76bf13f interaction with HTML/JS
am@osimis.io
parents:
diff changeset
33
313
8bdc6112bc2e initial resize of canvas
am@osimis.io
parents: 303
diff changeset
34 function GetUriParameters(): Map<string, string> {
287
2038d76bf13f interaction with HTML/JS
am@osimis.io
parents:
diff changeset
35 var parameters = window.location.search.substr(1);
2038d76bf13f interaction with HTML/JS
am@osimis.io
parents:
diff changeset
36
2038d76bf13f interaction with HTML/JS
am@osimis.io
parents:
diff changeset
37 if (parameters != null &&
2038d76bf13f interaction with HTML/JS
am@osimis.io
parents:
diff changeset
38 parameters != '') {
313
8bdc6112bc2e initial resize of canvas
am@osimis.io
parents: 303
diff changeset
39 var result = new Map<string, string>();
287
2038d76bf13f interaction with HTML/JS
am@osimis.io
parents:
diff changeset
40 var tokens = parameters.split('&');
2038d76bf13f interaction with HTML/JS
am@osimis.io
parents:
diff changeset
41
2038d76bf13f interaction with HTML/JS
am@osimis.io
parents:
diff changeset
42 for (var i = 0; i < tokens.length; i++) {
2038d76bf13f interaction with HTML/JS
am@osimis.io
parents:
diff changeset
43 var tmp = tokens[i].split('=');
2038d76bf13f interaction with HTML/JS
am@osimis.io
parents:
diff changeset
44 if (tmp.length == 2) {
2038d76bf13f interaction with HTML/JS
am@osimis.io
parents:
diff changeset
45 result[tmp[0]] = decodeURIComponent(tmp[1]);
603
70992b38aa8a new routable logging system in STDIO mode + flag support (with no value) in StartupParametersBuilder + 80 col indent
Benjamin Golinvaux <bgo@osimis.io>
parents: 545
diff changeset
46 } else if(tmp.length == 1) {
70992b38aa8a new routable logging system in STDIO mode + flag support (with no value) in StartupParametersBuilder + 80 col indent
Benjamin Golinvaux <bgo@osimis.io>
parents: 545
diff changeset
47 // if there is no '=', we treat ot afterwards as a flag-style param
70992b38aa8a new routable logging system in STDIO mode + flag support (with no value) in StartupParametersBuilder + 80 col indent
Benjamin Golinvaux <bgo@osimis.io>
parents: 545
diff changeset
48 result[tmp[0]] = "";
287
2038d76bf13f interaction with HTML/JS
am@osimis.io
parents:
diff changeset
49 }
2038d76bf13f interaction with HTML/JS
am@osimis.io
parents:
diff changeset
50 }
603
70992b38aa8a new routable logging system in STDIO mode + flag support (with no value) in StartupParametersBuilder + 80 col indent
Benjamin Golinvaux <bgo@osimis.io>
parents: 545
diff changeset
51 return result;
287
2038d76bf13f interaction with HTML/JS
am@osimis.io
parents:
diff changeset
52 }
2038d76bf13f interaction with HTML/JS
am@osimis.io
parents:
diff changeset
53 else {
313
8bdc6112bc2e initial resize of canvas
am@osimis.io
parents: 303
diff changeset
54 return new Map<string, string>();
287
2038d76bf13f interaction with HTML/JS
am@osimis.io
parents:
diff changeset
55 }
2038d76bf13f interaction with HTML/JS
am@osimis.io
parents:
diff changeset
56 }
2038d76bf13f interaction with HTML/JS
am@osimis.io
parents:
diff changeset
57
2038d76bf13f interaction with HTML/JS
am@osimis.io
parents:
diff changeset
58 // function UpdateWebApplication(statusUpdateMessage: string) {
2038d76bf13f interaction with HTML/JS
am@osimis.io
parents:
diff changeset
59 // console.log(statusUpdateMessage);
2038d76bf13f interaction with HTML/JS
am@osimis.io
parents:
diff changeset
60 // }
2038d76bf13f interaction with HTML/JS
am@osimis.io
parents:
diff changeset
61
314
97f16214dc5e cleanup
am@osimis.io
parents: 313
diff changeset
62 function _InitializeWasmApplication(orthancBaseUrl: string): void {
287
2038d76bf13f interaction with HTML/JS
am@osimis.io
parents:
diff changeset
63
2038d76bf13f interaction with HTML/JS
am@osimis.io
parents:
diff changeset
64 CreateWasmApplication();
2038d76bf13f interaction with HTML/JS
am@osimis.io
parents:
diff changeset
65
2038d76bf13f interaction with HTML/JS
am@osimis.io
parents:
diff changeset
66 // 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
67 let parameters = GetUriParameters();
287
2038d76bf13f interaction with HTML/JS
am@osimis.io
parents:
diff changeset
68
313
8bdc6112bc2e initial resize of canvas
am@osimis.io
parents: 303
diff changeset
69 for (let key in parameters) {
287
2038d76bf13f interaction with HTML/JS
am@osimis.io
parents:
diff changeset
70 if (parameters.hasOwnProperty(key)) {
603
70992b38aa8a new routable logging system in STDIO mode + flag support (with no value) in StartupParametersBuilder + 80 col indent
Benjamin Golinvaux <bgo@osimis.io>
parents: 545
diff changeset
71 Logger.defaultLogger.debug(
70992b38aa8a new routable logging system in STDIO mode + flag support (with no value) in StartupParametersBuilder + 80 col indent
Benjamin Golinvaux <bgo@osimis.io>
parents: 545
diff changeset
72 `About to call SetStartupParameter("${key}","${parameters[key]}")`);
287
2038d76bf13f interaction with HTML/JS
am@osimis.io
parents:
diff changeset
73 SetStartupParameter(key, parameters[key]);
2038d76bf13f interaction with HTML/JS
am@osimis.io
parents:
diff changeset
74 }
2038d76bf13f interaction with HTML/JS
am@osimis.io
parents:
diff changeset
75 }
2038d76bf13f interaction with HTML/JS
am@osimis.io
parents:
diff changeset
76
418
c23df8b3433b refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 386
diff changeset
77 StartWasmApplication(orthancBaseUrl);
313
8bdc6112bc2e initial resize of canvas
am@osimis.io
parents: 303
diff changeset
78
418
c23df8b3433b refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 386
diff changeset
79 // 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
80 StoneViewport.WasmViewport.ResizeAll();
287
2038d76bf13f interaction with HTML/JS
am@osimis.io
parents:
diff changeset
81
386
e33659decec5 renamed UpdateContent() as DoAnimation()
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 314
diff changeset
82 DoAnimationThread();
287
2038d76bf13f interaction with HTML/JS
am@osimis.io
parents:
diff changeset
83 }
2038d76bf13f interaction with HTML/JS
am@osimis.io
parents:
diff changeset
84
466
5055031f4a06 - Added browserify to build. This allows using require calls for modules that
bgo-osimis
parents: 435
diff changeset
85 export function InitializeWasmApplication(wasmModuleName: string, orthancBaseUrl: string) {
287
2038d76bf13f interaction with HTML/JS
am@osimis.io
parents:
diff changeset
86
2038d76bf13f interaction with HTML/JS
am@osimis.io
parents:
diff changeset
87 Stone.Framework.Configure(wasmModuleName);
2038d76bf13f interaction with HTML/JS
am@osimis.io
parents:
diff changeset
88
2038d76bf13f interaction with HTML/JS
am@osimis.io
parents:
diff changeset
89 // Wait for the Orthanc Framework to be initialized (this initializes
2038d76bf13f interaction with HTML/JS
am@osimis.io
parents:
diff changeset
90 // the WebAssembly environment) and then, create and initialize the Wasm application
2038d76bf13f interaction with HTML/JS
am@osimis.io
parents:
diff changeset
91 Stone.Framework.Initialize(true, function () {
2038d76bf13f interaction with HTML/JS
am@osimis.io
parents:
diff changeset
92
526
548eed46f535 introduced a Logger class that displays timing and source (C++/JS)
Alain Mazy <alain@mazy.be>
parents: 508
diff changeset
93 Logger.defaultLogger.debug("Connecting C++ methods to JS methods");
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 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
96 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
97 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
98 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
99 StartWasmApplication = (<any> window).StoneFrameworkModule.cwrap('StartWasmApplication', null, ['string']);
603
70992b38aa8a new routable logging system in STDIO mode + flag support (with no value) in StartupParametersBuilder + 80 col indent
Benjamin Golinvaux <bgo@osimis.io>
parents: 545
diff changeset
100 (<any> window).IsTraceLevelEnabled = (<any> window).StoneFrameworkModule.cwrap('WasmIsTraceLevelEnabled', 'boolean', null);
70992b38aa8a new routable logging system in STDIO mode + flag support (with no value) in StartupParametersBuilder + 80 col indent
Benjamin Golinvaux <bgo@osimis.io>
parents: 545
diff changeset
101 (<any> window).IsInfoLevelEnabled = (<any> window).StoneFrameworkModule.cwrap('WasmIsInfoLevelEnabled', 'boolean', null);
287
2038d76bf13f interaction with HTML/JS
am@osimis.io
parents:
diff changeset
102
466
5055031f4a06 - Added browserify to build. This allows using require calls for modules that
bgo-osimis
parents: 435
diff changeset
103 (<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
104 (<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
105 (<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
106 (<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
107 // 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
108 WasmDoAnimation = (<any> window).StoneFrameworkModule.cwrap('WasmDoAnimation', null, []);
287
2038d76bf13f interaction with HTML/JS
am@osimis.io
parents:
diff changeset
109
508
7105a0bad250 - Added HandleSerializedMessage to IStoneApplication (empty impl)
Benjamin Golinvaux <bgo@osimis.io>
parents: 466
diff changeset
110 SendSerializedMessageToStoneApplication = (<any> window).StoneFrameworkModule.cwrap('SendSerializedMessageToStoneApplication', 'string', ['string']);
287
2038d76bf13f interaction with HTML/JS
am@osimis.io
parents:
diff changeset
111
526
548eed46f535 introduced a Logger class that displays timing and source (C++/JS)
Alain Mazy <alain@mazy.be>
parents: 508
diff changeset
112 Logger.defaultLogger.debug("Connecting C++ methods to JS methods - done");
287
2038d76bf13f interaction with HTML/JS
am@osimis.io
parents:
diff changeset
113
2038d76bf13f interaction with HTML/JS
am@osimis.io
parents:
diff changeset
114 // Prevent scrolling
2038d76bf13f interaction with HTML/JS
am@osimis.io
parents:
diff changeset
115 document.body.addEventListener('touchmove', function (event) {
2038d76bf13f interaction with HTML/JS
am@osimis.io
parents:
diff changeset
116 event.preventDefault();
545
e1ba16436d59 set events passive again
Alain Mazy <alain@mazy.be>
parents: 536
diff changeset
117 }, { passive: false}); // must not be passive if calling event.preventDefault, ie to cancel scroll or zoom of the whole interface
287
2038d76bf13f interaction with HTML/JS
am@osimis.io
parents:
diff changeset
118
314
97f16214dc5e cleanup
am@osimis.io
parents: 313
diff changeset
119 _InitializeWasmApplication(orthancBaseUrl);
287
2038d76bf13f interaction with HTML/JS
am@osimis.io
parents:
diff changeset
120 });
466
5055031f4a06 - Added browserify to build. This allows using require calls for modules that
bgo-osimis
parents: 435
diff changeset
121 }
5055031f4a06 - Added browserify to build. This allows using require calls for modules that
bgo-osimis
parents: 435
diff changeset
122
5055031f4a06 - Added browserify to build. This allows using require calls for modules that
bgo-osimis
parents: 435
diff changeset
123
5055031f4a06 - Added browserify to build. This allows using require calls for modules that
bgo-osimis
parents: 435
diff changeset
124 // exports.InitializeWasmApplication = InitializeWasmApplication;
5055031f4a06 - Added browserify to build. This allows using require calls for modules that
bgo-osimis
parents: 435
diff changeset
125
5055031f4a06 - Added browserify to build. This allows using require calls for modules that
bgo-osimis
parents: 435
diff changeset
126
5055031f4a06 - Added browserify to build. This allows using require calls for modules that
bgo-osimis
parents: 435
diff changeset
127