changeset 715:636eb0e4c9dd twiga-viewer-first-release

Adding SetApplicationParameters
author Benjamin Golinvaux <bgo@osimis.io>
date Mon, 20 May 2019 18:42:39 +0200
parents 90f3a60576a9
children 69370bdaad89 a8149071abaa
files Platforms/Wasm/wasm-application-runner.ts
diffstat 1 files changed, 30 insertions(+), 4 deletions(-) [+]
line wrap: on
line diff
--- a/Platforms/Wasm/wasm-application-runner.ts	Tue Apr 02 14:02:12 2019 +0000
+++ b/Platforms/Wasm/wasm-application-runner.ts	Mon May 20 18:42:39 2019 +0200
@@ -22,14 +22,25 @@
 var StartWasmApplication: Function = null;
 export var SendSerializedMessageToStoneApplication: Function = null;
 
+var auxiliaryParameters : Map<string,string>  = null;
+
+export function SetApplicationParameters(params : Map<string,string>) {
+  if (auxiliaryParameters != null) {
+    console.warn("wasm-application-runner.SetApplicationParameters: about to overwrite the existing application parameters!")
+  }
+  auxiliaryParameters = params;
+}
+
 function DoAnimationThread() {
   if (WasmDoAnimation != null) {
     WasmDoAnimation();
   }
 
-  setTimeout(DoAnimationThread, 100);  // Update the viewport content every 100ms if need be
+  // Update the viewport content every 100ms if need be
+  setTimeout(DoAnimationThread, 100);  
 }
 
+
 function GetUriParameters(): Map<string, string> {
   var parameters = window.location.search.substr(1);
 
@@ -42,10 +53,12 @@
       var tmp = tokens[i].split('=');
       if (tmp.length == 2) {
         result[tmp[0]] = decodeURIComponent(tmp[1]);
+      } else if(tmp.length == 1) {
+        // if there is no '=', we treat ot afterwards as a flag-style param
+        result[tmp[0]] = "";
       }
     }
-
-    return result;
+  return result;
   }
   else {
     return new Map<string, string>();
@@ -60,11 +73,22 @@
 
   CreateWasmApplication();
 
-  // parse uri and transmit the parameters to the app before initializing it
+  // transmit the API-specified parameters to the app before initializing it
+  for (let key in auxiliaryParameters) {
+    if (auxiliaryParameters.hasOwnProperty(key)) {
+      Logger.defaultLogger.debug(
+        `About to call SetStartupParameter("${key}","${auxiliaryParameters[key]}")`);
+      SetStartupParameter(key, auxiliaryParameters[key]);
+    }
+  }
+
+  // parse uri and transmit the URI parameters to the app before initializing it
   let parameters = GetUriParameters();
 
   for (let key in parameters) {
     if (parameters.hasOwnProperty(key)) {
+      Logger.defaultLogger.debug(
+        `About to call SetStartupParameter("${key}","${parameters[key]}")`);
       SetStartupParameter(key, parameters[key]);
     }
   }
@@ -92,6 +116,8 @@
     CreateCppViewport = (<any> window).StoneFrameworkModule.cwrap('CreateCppViewport', 'number', []);
     ReleaseCppViewport = (<any> window).StoneFrameworkModule.cwrap('ReleaseCppViewport', null, ['number']);
     StartWasmApplication = (<any> window).StoneFrameworkModule.cwrap('StartWasmApplication', null, ['string']);
+    (<any> window).IsTraceLevelEnabled = (<any> window).StoneFrameworkModule.cwrap('WasmIsTraceLevelEnabled', 'boolean', null);
+    (<any> window).IsInfoLevelEnabled = (<any> window).StoneFrameworkModule.cwrap('WasmIsInfoLevelEnabled', 'boolean', null);
 
     (<any> window).WasmWebService_NotifyCachedSuccess = (<any> window).StoneFrameworkModule.cwrap('WasmWebService_NotifyCachedSuccess', null, ['number']);
     (<any> window).WasmWebService_NotifySuccess = (<any> window).StoneFrameworkModule.cwrap('WasmWebService_NotifySuccess', null, ['number', 'string', 'array', 'number', 'number']);