diff --git a/Ooui/Client.js b/Ooui/Client.js index 3c8a2d6..83b7203 100644 --- a/Ooui/Client.js +++ b/Ooui/Client.js @@ -414,7 +414,7 @@ var WebAssemblyApp = { this.findMethods (); - var res = this.runApp ("1", "2"); + this.runApp ("1", "2"); this.loading.hidden = true; }, @@ -422,20 +422,24 @@ var WebAssemblyApp = { runApp: function (a, b) { try { var sessionId = "main"; + if (!!this.ooui_DisableServer_method) { + MonoRuntime.call_method (this.ooui_DisableServer_method, null, []); + } MonoRuntime.call_method (this.main_method, null, [MonoRuntime.mono_string (a), MonoRuntime.mono_string (b)]); wasmSession = sessionId; - if (!!ooui_StartWebAssemblySession_method) { + if (!!this.ooui_StartWebAssemblySession_method) { 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))]); + MonoRuntime.call_method (this.ooui_StartWebAssemblySession_method, null, [MonoRuntime.mono_string (sessionId), MonoRuntime.mono_string (""), MonoRuntime.mono_string (Math.round(initialSize.width) + " " + Math.round(initialSize.height))]); } - return "ok"; } catch (e) { - return e.msg; + console.error(e); } }, receiveMessagesJson: function (sessionId, json) { - MonoRuntime.call_method (this.ooui_ReceiveWebAssemblySessionMessageJson_method, null, [MonoRuntime.mono_string (sessionId), MonoRuntime.mono_string (json)]); + if (!!this.ooui_ReceiveWebAssemblySessionMessageJson_method) { + MonoRuntime.call_method (this.ooui_ReceiveWebAssemblySessionMessageJson_method, null, [MonoRuntime.mono_string (sessionId), MonoRuntime.mono_string (json)]); + } }, findMethods: function () { @@ -458,6 +462,10 @@ var WebAssemblyApp = { if (!this.ooui_class) throw "Could not find UI class in Ooui module"; + this.ooui_DisableServer_method = MonoRuntime.find_method (this.ooui_class, "DisableServer", -1); + if (!this.ooui_DisableServer_method) + throw "Could not find DisableServer method"; + this.ooui_StartWebAssemblySession_method = MonoRuntime.find_method (this.ooui_class, "StartWebAssemblySession", -1); if (!this.ooui_StartWebAssemblySession_method) throw "Could not find StartWebAssemblySession method"; diff --git a/Ooui/UI.cs b/Ooui/UI.cs index e1cea9c..fe8b5c9 100644 --- a/Ooui/UI.cs +++ b/Ooui/UI.cs @@ -67,6 +67,12 @@ namespace Ooui } } + [Preserve] + static void DisableServer () + { + ServerEnabled = false; + } + static UI () { var asm = typeof(UI).Assembly; @@ -86,7 +92,7 @@ namespace Ooui static void Publish (string path, RequestHandler handler) { - Console.WriteLine ($"PUBLISH {path} {handler}"); + //Console.WriteLine ($"PUBLISH {path} {handler}"); lock (publishedPaths) publishedPaths[path] = handler; Start (); } @@ -587,24 +593,23 @@ namespace Ooui #endif - static readonly Dictionary globalElements = new Dictionary (); static readonly Dictionary globalElementSessions = new Dictionary (); - public static void SetGlobalElement (string globalElementId, Element element) - { - lock (globalElements) { - globalElements[globalElementId] = element; - } - } - [Preserve] - public static void StartWebAssemblySession (string sessionId, string globalElementId, string initialSize) + public static void StartWebAssemblySession (string sessionId, string elementPath, string initialSize) { Element element; - lock (globalElements) { - if (!globalElements.TryGetValue (globalElementId, out element)) - return; + RequestHandler handler; + lock (publishedPaths) { + publishedPaths.TryGetValue (elementPath, out handler); } + if (handler is ElementHandler eh) { + element = eh.GetElement (); + } + else { + element = new Div (); + } + var ops = initialSize.Split (' '); var initialWidth = double.Parse (ops[0]); var initialHeight = double.Parse (ops[1]);