Mercurial > hg > orthanc-stone
comparison Platforms/Wasm/wasm-application-runner.ts @ 715:636eb0e4c9dd twiga-viewer-first-release
Adding SetApplicationParameters
author | Benjamin Golinvaux <bgo@osimis.io> |
---|---|
date | Mon, 20 May 2019 18:42:39 +0200 |
parents | e1ba16436d59 |
children | df7286320507 |
comparison
equal
deleted
inserted
replaced
551:90f3a60576a9 | 715:636eb0e4c9dd |
---|---|
20 export var CreateCppViewport: Function = null; | 20 export var CreateCppViewport: Function = null; |
21 var ReleaseCppViewport: Function = null; | 21 var ReleaseCppViewport: Function = null; |
22 var StartWasmApplication: Function = null; | 22 var StartWasmApplication: Function = null; |
23 export var SendSerializedMessageToStoneApplication: Function = null; | 23 export var SendSerializedMessageToStoneApplication: Function = null; |
24 | 24 |
25 var auxiliaryParameters : Map<string,string> = null; | |
26 | |
27 export function SetApplicationParameters(params : Map<string,string>) { | |
28 if (auxiliaryParameters != null) { | |
29 console.warn("wasm-application-runner.SetApplicationParameters: about to overwrite the existing application parameters!") | |
30 } | |
31 auxiliaryParameters = params; | |
32 } | |
33 | |
25 function DoAnimationThread() { | 34 function DoAnimationThread() { |
26 if (WasmDoAnimation != null) { | 35 if (WasmDoAnimation != null) { |
27 WasmDoAnimation(); | 36 WasmDoAnimation(); |
28 } | 37 } |
29 | 38 |
30 setTimeout(DoAnimationThread, 100); // Update the viewport content every 100ms if need be | 39 // Update the viewport content every 100ms if need be |
40 setTimeout(DoAnimationThread, 100); | |
31 } | 41 } |
42 | |
32 | 43 |
33 function GetUriParameters(): Map<string, string> { | 44 function GetUriParameters(): Map<string, string> { |
34 var parameters = window.location.search.substr(1); | 45 var parameters = window.location.search.substr(1); |
35 | 46 |
36 if (parameters != null && | 47 if (parameters != null && |
40 | 51 |
41 for (var i = 0; i < tokens.length; i++) { | 52 for (var i = 0; i < tokens.length; i++) { |
42 var tmp = tokens[i].split('='); | 53 var tmp = tokens[i].split('='); |
43 if (tmp.length == 2) { | 54 if (tmp.length == 2) { |
44 result[tmp[0]] = decodeURIComponent(tmp[1]); | 55 result[tmp[0]] = decodeURIComponent(tmp[1]); |
56 } else if(tmp.length == 1) { | |
57 // if there is no '=', we treat ot afterwards as a flag-style param | |
58 result[tmp[0]] = ""; | |
45 } | 59 } |
46 } | 60 } |
47 | 61 return result; |
48 return result; | |
49 } | 62 } |
50 else { | 63 else { |
51 return new Map<string, string>(); | 64 return new Map<string, string>(); |
52 } | 65 } |
53 } | 66 } |
58 | 71 |
59 function _InitializeWasmApplication(orthancBaseUrl: string): void { | 72 function _InitializeWasmApplication(orthancBaseUrl: string): void { |
60 | 73 |
61 CreateWasmApplication(); | 74 CreateWasmApplication(); |
62 | 75 |
63 // parse uri and transmit the parameters to the app before initializing it | 76 // transmit the API-specified parameters to the app before initializing it |
77 for (let key in auxiliaryParameters) { | |
78 if (auxiliaryParameters.hasOwnProperty(key)) { | |
79 Logger.defaultLogger.debug( | |
80 `About to call SetStartupParameter("${key}","${auxiliaryParameters[key]}")`); | |
81 SetStartupParameter(key, auxiliaryParameters[key]); | |
82 } | |
83 } | |
84 | |
85 // parse uri and transmit the URI parameters to the app before initializing it | |
64 let parameters = GetUriParameters(); | 86 let parameters = GetUriParameters(); |
65 | 87 |
66 for (let key in parameters) { | 88 for (let key in parameters) { |
67 if (parameters.hasOwnProperty(key)) { | 89 if (parameters.hasOwnProperty(key)) { |
90 Logger.defaultLogger.debug( | |
91 `About to call SetStartupParameter("${key}","${parameters[key]}")`); | |
68 SetStartupParameter(key, parameters[key]); | 92 SetStartupParameter(key, parameters[key]); |
69 } | 93 } |
70 } | 94 } |
71 | 95 |
72 StartWasmApplication(orthancBaseUrl); | 96 StartWasmApplication(orthancBaseUrl); |
90 SetStartupParameter = (<any> window).StoneFrameworkModule.cwrap('SetStartupParameter', null, ['string', 'string']); | 114 SetStartupParameter = (<any> window).StoneFrameworkModule.cwrap('SetStartupParameter', null, ['string', 'string']); |
91 CreateWasmApplication = (<any> window).StoneFrameworkModule.cwrap('CreateWasmApplication', null, ['number']); | 115 CreateWasmApplication = (<any> window).StoneFrameworkModule.cwrap('CreateWasmApplication', null, ['number']); |
92 CreateCppViewport = (<any> window).StoneFrameworkModule.cwrap('CreateCppViewport', 'number', []); | 116 CreateCppViewport = (<any> window).StoneFrameworkModule.cwrap('CreateCppViewport', 'number', []); |
93 ReleaseCppViewport = (<any> window).StoneFrameworkModule.cwrap('ReleaseCppViewport', null, ['number']); | 117 ReleaseCppViewport = (<any> window).StoneFrameworkModule.cwrap('ReleaseCppViewport', null, ['number']); |
94 StartWasmApplication = (<any> window).StoneFrameworkModule.cwrap('StartWasmApplication', null, ['string']); | 118 StartWasmApplication = (<any> window).StoneFrameworkModule.cwrap('StartWasmApplication', null, ['string']); |
119 (<any> window).IsTraceLevelEnabled = (<any> window).StoneFrameworkModule.cwrap('WasmIsTraceLevelEnabled', 'boolean', null); | |
120 (<any> window).IsInfoLevelEnabled = (<any> window).StoneFrameworkModule.cwrap('WasmIsInfoLevelEnabled', 'boolean', null); | |
95 | 121 |
96 (<any> window).WasmWebService_NotifyCachedSuccess = (<any> window).StoneFrameworkModule.cwrap('WasmWebService_NotifyCachedSuccess', null, ['number']); | 122 (<any> window).WasmWebService_NotifyCachedSuccess = (<any> window).StoneFrameworkModule.cwrap('WasmWebService_NotifyCachedSuccess', null, ['number']); |
97 (<any> window).WasmWebService_NotifySuccess = (<any> window).StoneFrameworkModule.cwrap('WasmWebService_NotifySuccess', null, ['number', 'string', 'array', 'number', 'number']); | 123 (<any> window).WasmWebService_NotifySuccess = (<any> window).StoneFrameworkModule.cwrap('WasmWebService_NotifySuccess', null, ['number', 'string', 'array', 'number', 'number']); |
98 (<any> window).WasmWebService_NotifyError = (<any> window).StoneFrameworkModule.cwrap('WasmWebService_NotifyError', null, ['number', 'string', 'number']); | 124 (<any> window).WasmWebService_NotifyError = (<any> window).StoneFrameworkModule.cwrap('WasmWebService_NotifyError', null, ['number', 'string', 'number']); |
99 (<any> window).WasmDelayedCallExecutor_ExecuteCallback = (<any> window).StoneFrameworkModule.cwrap('WasmDelayedCallExecutor_ExecuteCallback', null, ['number']); | 125 (<any> window).WasmDelayedCallExecutor_ExecuteCallback = (<any> window).StoneFrameworkModule.cwrap('WasmDelayedCallExecutor_ExecuteCallback', null, ['number']); |