Use Publish in wasm
This commit is contained in:
parent
794e27dd79
commit
9733254d68
|
@ -414,7 +414,7 @@ var WebAssemblyApp = {
|
||||||
|
|
||||||
this.findMethods ();
|
this.findMethods ();
|
||||||
|
|
||||||
var res = this.runApp ("1", "2");
|
this.runApp ("1", "2");
|
||||||
|
|
||||||
this.loading.hidden = true;
|
this.loading.hidden = true;
|
||||||
},
|
},
|
||||||
|
@ -422,20 +422,24 @@ var WebAssemblyApp = {
|
||||||
runApp: function (a, b) {
|
runApp: function (a, b) {
|
||||||
try {
|
try {
|
||||||
var sessionId = "main";
|
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)]);
|
MonoRuntime.call_method (this.main_method, null, [MonoRuntime.mono_string (a), MonoRuntime.mono_string (b)]);
|
||||||
wasmSession = sessionId;
|
wasmSession = sessionId;
|
||||||
if (!!ooui_StartWebAssemblySession_method) {
|
if (!!this.ooui_StartWebAssemblySession_method) {
|
||||||
var initialSize = getSize ();
|
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) {
|
} catch (e) {
|
||||||
return e.msg;
|
console.error(e);
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
|
|
||||||
receiveMessagesJson: function (sessionId, json) {
|
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 () {
|
findMethods: function () {
|
||||||
|
@ -458,6 +462,10 @@ var WebAssemblyApp = {
|
||||||
if (!this.ooui_class)
|
if (!this.ooui_class)
|
||||||
throw "Could not find UI class in Ooui module";
|
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);
|
this.ooui_StartWebAssemblySession_method = MonoRuntime.find_method (this.ooui_class, "StartWebAssemblySession", -1);
|
||||||
if (!this.ooui_StartWebAssemblySession_method)
|
if (!this.ooui_StartWebAssemblySession_method)
|
||||||
throw "Could not find StartWebAssemblySession method";
|
throw "Could not find StartWebAssemblySession method";
|
||||||
|
|
31
Ooui/UI.cs
31
Ooui/UI.cs
|
@ -67,6 +67,12 @@ namespace Ooui
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
[Preserve]
|
||||||
|
static void DisableServer ()
|
||||||
|
{
|
||||||
|
ServerEnabled = false;
|
||||||
|
}
|
||||||
|
|
||||||
static UI ()
|
static UI ()
|
||||||
{
|
{
|
||||||
var asm = typeof(UI).Assembly;
|
var asm = typeof(UI).Assembly;
|
||||||
|
@ -86,7 +92,7 @@ namespace Ooui
|
||||||
|
|
||||||
static void Publish (string path, RequestHandler handler)
|
static void Publish (string path, RequestHandler handler)
|
||||||
{
|
{
|
||||||
Console.WriteLine ($"PUBLISH {path} {handler}");
|
//Console.WriteLine ($"PUBLISH {path} {handler}");
|
||||||
lock (publishedPaths) publishedPaths[path] = handler;
|
lock (publishedPaths) publishedPaths[path] = handler;
|
||||||
Start ();
|
Start ();
|
||||||
}
|
}
|
||||||
|
@ -587,24 +593,23 @@ namespace Ooui
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
static readonly Dictionary<string, Element> globalElements = new Dictionary<string, Element> ();
|
|
||||||
static readonly Dictionary<string, WebAssemblySession> globalElementSessions = new Dictionary<string, WebAssemblySession> ();
|
static readonly Dictionary<string, WebAssemblySession> globalElementSessions = new Dictionary<string, WebAssemblySession> ();
|
||||||
|
|
||||||
public static void SetGlobalElement (string globalElementId, Element element)
|
|
||||||
{
|
|
||||||
lock (globalElements) {
|
|
||||||
globalElements[globalElementId] = element;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
[Preserve]
|
[Preserve]
|
||||||
public static void StartWebAssemblySession (string sessionId, string globalElementId, string initialSize)
|
public static void StartWebAssemblySession (string sessionId, string elementPath, string initialSize)
|
||||||
{
|
{
|
||||||
Element element;
|
Element element;
|
||||||
lock (globalElements) {
|
RequestHandler handler;
|
||||||
if (!globalElements.TryGetValue (globalElementId, out element))
|
lock (publishedPaths) {
|
||||||
return;
|
publishedPaths.TryGetValue (elementPath, out handler);
|
||||||
}
|
}
|
||||||
|
if (handler is ElementHandler eh) {
|
||||||
|
element = eh.GetElement ();
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
element = new Div ();
|
||||||
|
}
|
||||||
|
|
||||||
var ops = initialSize.Split (' ');
|
var ops = initialSize.Split (' ');
|
||||||
var initialWidth = double.Parse (ops[0]);
|
var initialWidth = double.Parse (ops[0]);
|
||||||
var initialHeight = double.Parse (ops[1]);
|
var initialHeight = double.Parse (ops[1]);
|
||||||
|
|
Loading…
Reference in New Issue