Mercurial > hg > orthanc-stone
comparison Platforms/Wasm/wasm-application-runner.ts @ 287:2038d76bf13f am-2
interaction with HTML/JS
author | am@osimis.io |
---|---|
date | Thu, 30 Aug 2018 11:36:36 +0200 |
parents | |
children | 3897f9f28cfa |
comparison
equal
deleted
inserted
replaced
286:6b3d91857b96 | 287:2038d76bf13f |
---|---|
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; | |
13 var WasmWebService_SetBaseUri: Function = null; | |
14 var NotifyUpdateContent: Function = null; | |
15 var SetStartupParameter: Function = null; | |
16 var CreateWasmApplication: Function = null; | |
17 var CreateCppViewport: Function = null; | |
18 var ReleaseCppViewport: Function = null; | |
19 var StartWasmApplication: Function = null; | |
20 var SendMessageToStoneApplication: Function = null; | |
21 | |
22 | |
23 function UpdateContentThread() { | |
24 if (NotifyUpdateContent != null) { | |
25 NotifyUpdateContent(); | |
26 } | |
27 | |
28 setTimeout(UpdateContentThread, 100); // Update the viewport content every 100ms if need be | |
29 } | |
30 | |
31 | |
32 function GetUriParameters() { | |
33 var parameters = window.location.search.substr(1); | |
34 | |
35 if (parameters != null && | |
36 parameters != '') { | |
37 var result = {}; | |
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 { | |
50 return {}; | |
51 } | |
52 } | |
53 | |
54 // function UpdateWebApplication(statusUpdateMessage: string) { | |
55 // console.log(statusUpdateMessage); | |
56 // } | |
57 | |
58 function _InitializeWasmApplication(canvasId: string, orthancBaseUrl: string): void { | |
59 | |
60 /************************************** */ | |
61 CreateWasmApplication(); | |
62 WasmWebService_SetBaseUri(orthancBaseUrl); | |
63 | |
64 | |
65 // parse uri and transmit the parameters to the app before initializing it | |
66 var parameters = GetUriParameters(); | |
67 | |
68 for (var key in parameters) { | |
69 if (parameters.hasOwnProperty(key)) { | |
70 SetStartupParameter(key, parameters[key]); | |
71 } | |
72 } | |
73 | |
74 StartWasmApplication(); | |
75 /************************************** */ | |
76 | |
77 UpdateContentThread(); | |
78 } | |
79 | |
80 function InitializeWasmApplication(wasmModuleName: string, orthancBaseUrl: string) { | |
81 | |
82 Stone.Framework.Configure(wasmModuleName); | |
83 | |
84 // Wait for the Orthanc Framework to be initialized (this initializes | |
85 // the WebAssembly environment) and then, create and initialize the Wasm application | |
86 Stone.Framework.Initialize(true, function () { | |
87 | |
88 console.log("Connecting C++ methods to JS methods"); | |
89 | |
90 SetStartupParameter = StoneFrameworkModule.cwrap('SetStartupParameter', null, ['string', 'string']); | |
91 CreateWasmApplication = StoneFrameworkModule.cwrap('CreateWasmApplication', null, ['number']); | |
92 CreateCppViewport = StoneFrameworkModule.cwrap('CreateCppViewport', 'number', []); | |
93 ReleaseCppViewport = StoneFrameworkModule.cwrap('ReleaseCppViewport', null, ['number']); | |
94 StartWasmApplication = StoneFrameworkModule.cwrap('StartWasmApplication', null, ['number']); | |
95 | |
96 WasmWebService_NotifySuccess = StoneFrameworkModule.cwrap('WasmWebService_NotifySuccess', null, ['number', 'string', 'array', 'number', 'number']); | |
97 WasmWebService_NotifyError = StoneFrameworkModule.cwrap('WasmWebService_NotifyError', null, ['number', 'string', 'number']); | |
98 WasmWebService_SetBaseUri = StoneFrameworkModule.cwrap('WasmWebService_SetBaseUri', null, ['string']); | |
99 NotifyUpdateContent = StoneFrameworkModule.cwrap('NotifyUpdateContent', null, []); | |
100 | |
101 SendMessageToStoneApplication = StoneFrameworkModule.cwrap('SendMessageToStoneApplication', 'string', ['string']); | |
102 | |
103 console.log("Connecting C++ methods to JS methods - done"); | |
104 | |
105 // Prevent scrolling | |
106 document.body.addEventListener('touchmove', function (event) { | |
107 event.preventDefault(); | |
108 }, false); | |
109 | |
110 _InitializeWasmApplication("canvas", orthancBaseUrl); | |
111 }); | |
112 } |