287
|
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
|
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 WasmWebService_SetBaseUri(orthancBaseUrl);
|
|
62
|
|
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
|
|
73 StartWasmApplication();
|
313
|
74
|
|
75 // trigger a first resize of the canvas that have just been initialized
|
314
|
76 Stone.WasmViewport.ResizeAll();
|
287
|
77
|
|
78 UpdateContentThread();
|
|
79 }
|
|
80
|
314
|
81 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
|
|
89 console.log("Connecting C++ methods to JS methods");
|
|
90
|
|
91 SetStartupParameter = StoneFrameworkModule.cwrap('SetStartupParameter', null, ['string', 'string']);
|
|
92 CreateWasmApplication = StoneFrameworkModule.cwrap('CreateWasmApplication', null, ['number']);
|
|
93 CreateCppViewport = StoneFrameworkModule.cwrap('CreateCppViewport', 'number', []);
|
|
94 ReleaseCppViewport = StoneFrameworkModule.cwrap('ReleaseCppViewport', null, ['number']);
|
|
95 StartWasmApplication = StoneFrameworkModule.cwrap('StartWasmApplication', null, ['number']);
|
|
96
|
|
97 WasmWebService_NotifySuccess = StoneFrameworkModule.cwrap('WasmWebService_NotifySuccess', null, ['number', 'string', 'array', 'number', 'number']);
|
|
98 WasmWebService_NotifyError = StoneFrameworkModule.cwrap('WasmWebService_NotifyError', null, ['number', 'string', 'number']);
|
|
99 WasmWebService_SetBaseUri = StoneFrameworkModule.cwrap('WasmWebService_SetBaseUri', null, ['string']);
|
|
100 NotifyUpdateContent = StoneFrameworkModule.cwrap('NotifyUpdateContent', null, []);
|
|
101
|
|
102 SendMessageToStoneApplication = StoneFrameworkModule.cwrap('SendMessageToStoneApplication', 'string', ['string']);
|
|
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 });
|
|
113 } |