Fix initial size js

This commit is contained in:
Frank A. Krueger 2018-03-12 22:14:37 -07:00
parent 8ef0a12ab4
commit 980b2880d7
No known key found for this signature in database
GPG Key ID: 0471C67474FFE664
1 changed files with 26 additions and 35 deletions

View File

@ -105,17 +105,25 @@ function ooui (rootElementPath) {
console.log("Web socket created");
// Throttled window resize event
(function() {
window.addEventListener("resize", resizeThrottler, false);
monitorSizeChanges (1000/10);
}
function oouiWasm (mainAsmName, mainNamspace, mainClassName, mainMethodNmae, assemblies)
{
Module.assemblies = assemblies;
monitorSizeChanges (1000/30);
}
function monitorSizeChanges (millis)
{
var resizeTimeout;
function resizeThrottler() {
if (!resizeTimeout) {
resizeTimeout = setTimeout(function() {
resizeTimeout = null;
resizeHandler();
}, 100);
}, millis);
}
}
@ -131,28 +139,8 @@ function ooui (rootElementPath) {
send (ems);
if (debug) console.log ("Event", em);
}
}());
}
function oouiWasm (mainAsmName, mainNamspace, mainClassName, mainMethodNmae, assemblies)
{
Module.assemblies = assemblies;
var initialSize = getSize ();
function resizeHandler() {
const em = {
m: "event",
id: "window",
k: "resize",
v: getSize (),
};
const ems = JSON.stringify (em);
send (ems);
if (debug) console.log ("Event", em);
}
window.addEventListener ("resize", resizeHandler, false);
window.addEventListener("resize", resizeThrottler, false);
}
function getNode (id) {
@ -330,11 +318,13 @@ function fixupValue (v) {
window["__oouiReceiveMessages"] = function (sessionId, messages)
{
if (debug) console.log ("WebAssembly Receive", messages);
if (wasmSession != null) {
messages.forEach (function (m) {
// console.log ('Raw value from server', m.v);
m.v = fixupValue (m.v);
processMessage (m);
});
}
};
var Module = {
@ -433,8 +423,9 @@ var WebAssemblyApp = {
var sessionId = "main";
var rres = MonoRuntime.call_method (this.main_method, null, [MonoRuntime.mono_string (a), MonoRuntime.mono_string (b)]);
var res = MonoRuntime.conv_string (rres);
MonoRuntime.call_method (this.ooui_StartWebAssemblySession_method, null, [MonoRuntime.mono_string (sessionId), MonoRuntime.mono_string ("main")]);
wasmSession = sessionId;
var initialSize = getSize ();
MonoRuntime.call_method (this.ooui_StartWebAssemblySession_method, null, [MonoRuntime.mono_string (sessionId), MonoRuntime.mono_string ("main"), MonoRuntime.mono_string (Math.round(initialSize.width) + " " + Math.round(initialSize.height))]);
return res;
} catch (e) {
return e.msg;