Mercurial > hg > orthanc-stone
annotate Platforms/Wasm/wasm-application-runner.ts @ 533:1c5104a6f7e4 dev
fix warning for preventDefault
author | Alain Mazy <alain@mazy.be> |
---|---|
date | Mon, 18 Mar 2019 16:01:07 +0100 |
parents | 548eed46f535 |
children | f65748b33bd1 |
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 | 4 |
5 if (!('WebAssembly' in window)) { | |
6 alert('Sorry, your browser does not support WebAssembly :('); | |
7 } | |
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 | 11 |
12 // global functions | |
13 var WasmWebService_NotifyError: Function = null; | |
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 | 18 var SetStartupParameter: Function = null; |
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 | 21 var ReleaseCppViewport: Function = null; |
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; |
7105a0bad250
- Added HandleSerializedMessage to IStoneApplication (empty impl)
Benjamin Golinvaux <bgo@osimis.io>
parents:
466
diff
changeset
|
24 export var SendCommandToStoneApplication: Function = null; |
287 | 25 |
386
e33659decec5
renamed UpdateContent() as DoAnimation()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
314
diff
changeset
|
26 function DoAnimationThread() { |
e33659decec5
renamed UpdateContent() as DoAnimation()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
314
diff
changeset
|
27 if (WasmDoAnimation != null) { |
e33659decec5
renamed UpdateContent() as DoAnimation()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
314
diff
changeset
|
28 WasmDoAnimation(); |
287 | 29 } |
30 | |
386
e33659decec5
renamed UpdateContent() as DoAnimation()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
314
diff
changeset
|
31 setTimeout(DoAnimationThread, 100); // Update the viewport content every 100ms if need be |
287 | 32 } |
33 | |
313 | 34 function GetUriParameters(): Map<string, string> { |
287 | 35 var parameters = window.location.search.substr(1); |
36 | |
37 if (parameters != null && | |
38 parameters != '') { | |
313 | 39 var result = new Map<string, string>(); |
287 | 40 var tokens = parameters.split('&'); |
41 | |
42 for (var i = 0; i < tokens.length; i++) { | |
43 var tmp = tokens[i].split('='); | |
44 if (tmp.length == 2) { | |
45 result[tmp[0]] = decodeURIComponent(tmp[1]); | |
46 } | |
47 } | |
48 | |
49 return result; | |
50 } | |
51 else { | |
313 | 52 return new Map<string, string>(); |
287 | 53 } |
54 } | |
55 | |
56 // function UpdateWebApplication(statusUpdateMessage: string) { | |
57 // console.log(statusUpdateMessage); | |
58 // } | |
59 | |
314 | 60 function _InitializeWasmApplication(orthancBaseUrl: string): void { |
287 | 61 |
62 CreateWasmApplication(); | |
63 | |
64 // parse uri and transmit the parameters to the app before initializing it | |
313 | 65 let parameters = GetUriParameters(); |
287 | 66 |
313 | 67 for (let key in parameters) { |
287 | 68 if (parameters.hasOwnProperty(key)) { |
69 SetStartupParameter(key, parameters[key]); | |
70 } | |
71 } | |
72 | |
418 | 73 StartWasmApplication(orthancBaseUrl); |
313 | 74 |
418 | 75 // 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
|
76 StoneViewport.WasmViewport.ResizeAll(); |
287 | 77 |
386
e33659decec5
renamed UpdateContent() as DoAnimation()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
314
diff
changeset
|
78 DoAnimationThread(); |
287 | 79 } |
80 | |
466
5055031f4a06
- Added browserify to build. This allows using require calls for modules that
bgo-osimis
parents:
435
diff
changeset
|
81 export function InitializeWasmApplication(wasmModuleName: string, orthancBaseUrl: string) { |
287 | 82 |
83 Stone.Framework.Configure(wasmModuleName); | |
84 | |
85 // Wait for the Orthanc Framework to be initialized (this initializes | |
86 // the WebAssembly environment) and then, create and initialize the Wasm application | |
87 Stone.Framework.Initialize(true, function () { | |
88 | |
526
548eed46f535
introduced a Logger class that displays timing and source (C++/JS)
Alain Mazy <alain@mazy.be>
parents:
508
diff
changeset
|
89 Logger.defaultLogger.debug("Connecting C++ methods to JS methods"); |
287 | 90 |
466
5055031f4a06
- Added browserify to build. This allows using require calls for modules that
bgo-osimis
parents:
435
diff
changeset
|
91 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
|
92 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
|
93 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
|
94 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
|
95 StartWasmApplication = (<any> window).StoneFrameworkModule.cwrap('StartWasmApplication', null, ['string']); |
287 | 96 |
466
5055031f4a06
- Added browserify to build. This allows using require calls for modules that
bgo-osimis
parents:
435
diff
changeset
|
97 (<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
|
98 (<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
|
99 (<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
|
100 (<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
|
101 // 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
|
102 WasmDoAnimation = (<any> window).StoneFrameworkModule.cwrap('WasmDoAnimation', null, []); |
287 | 103 |
508
7105a0bad250
- Added HandleSerializedMessage to IStoneApplication (empty impl)
Benjamin Golinvaux <bgo@osimis.io>
parents:
466
diff
changeset
|
104 SendSerializedMessageToStoneApplication = (<any> window).StoneFrameworkModule.cwrap('SendSerializedMessageToStoneApplication', 'string', ['string']); |
7105a0bad250
- Added HandleSerializedMessage to IStoneApplication (empty impl)
Benjamin Golinvaux <bgo@osimis.io>
parents:
466
diff
changeset
|
105 SendCommandToStoneApplication = (<any> window).StoneFrameworkModule.cwrap('SendCommandToStoneApplication', 'string', ['string']); |
287 | 106 |
526
548eed46f535
introduced a Logger class that displays timing and source (C++/JS)
Alain Mazy <alain@mazy.be>
parents:
508
diff
changeset
|
107 Logger.defaultLogger.debug("Connecting C++ methods to JS methods - done"); |
287 | 108 |
109 // Prevent scrolling | |
110 document.body.addEventListener('touchmove', function (event) { | |
111 event.preventDefault(); | |
533 | 112 }, { passive: false}); |
287 | 113 |
314 | 114 _InitializeWasmApplication(orthancBaseUrl); |
287 | 115 }); |
466
5055031f4a06
- Added browserify to build. This allows using require calls for modules that
bgo-osimis
parents:
435
diff
changeset
|
116 } |
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 // exports.InitializeWasmApplication = InitializeWasmApplication; |
5055031f4a06
- Added browserify to build. This allows using require calls for modules that
bgo-osimis
parents:
435
diff
changeset
|
120 |
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 |