Wasm is working

This commit is contained in:
Frank A. Krueger 2018-03-09 19:11:57 -08:00
parent 93229cf3c8
commit 5d47c9adef
No known key found for this signature in database
GPG Key ID: 0471C67474FFE664
3 changed files with 29 additions and 16 deletions

View File

@ -9,6 +9,10 @@ public class Program
var l = new Label { Text = "Hello" }; var l = new Label { Text = "Hello" };
var b = new Button ("Click Me"); var b = new Button ("Click Me");
var e = new Div (new Div (l), b); var e = new Div (new Div (l), b);
var c = 0;
b.Click += (s, ee) => {
b.Text = $"Clicked {c} times";
};
UI.SetGlobalElement ("main", e); UI.SetGlobalElement ("main", e);
return e.ToString (); return e.ToString ();

View File

@ -322,6 +322,16 @@ function fixupValue (v) {
// == WASM Support == // == WASM Support ==
window["__oouiReceiveMessages"] = function (sessionId, messages)
{
console.log ("RCV", messages);
messages.forEach (function (m) {
console.log ('Raw value from server', m.v);
m.v = fixupValue (m.v);
processMessage (m);
});
};
var Module = { var Module = {
onRuntimeInitialized: function () { onRuntimeInitialized: function () {
console.log ("Done with WASM module instantiation."); console.log ("Done with WASM module instantiation.");
@ -405,22 +415,20 @@ var MonoRuntime = {
var WebAssemblyApp = { var WebAssemblyApp = {
init: function () { init: function () {
this.loading = document.getElementById ("loading"); this.loading = document.getElementById ("loading");
this.output = document.getElementById ("output");
this.findMethods (); this.findMethods ();
var res = this.runApp ("1", "2"); var res = this.runApp ("1", "2");
this.output.value = res;
this.output.hidden = false;
this.loading.hidden = true; this.loading.hidden = true;
}, },
runApp: function (a, b) { runApp: function (a, b) {
try { try {
var rres = MonoRuntime.call_method (this.add_method, null, [MonoRuntime.mono_string (a), MonoRuntime.mono_string (b)]);
var res = MonoRuntime.conv_string (rres);
MonoRuntime.call_method (this.ooui_method, null, [MonoRuntime.mono_string ("main"), MonoRuntime.mono_string ("main")]); MonoRuntime.call_method (this.ooui_method, null, [MonoRuntime.mono_string ("main"), MonoRuntime.mono_string ("main")]);
var res = MonoRuntime.call_method (this.add_method, null, [MonoRuntime.mono_string (a), MonoRuntime.mono_string (b)]); return res;
return MonoRuntime.conv_string (res);
} catch (e) { } catch (e) {
return e.msg; return e.msg;
} }

View File

@ -1,5 +1,6 @@
using System; using System;
using System.Collections.Generic; using System.Collections.Generic;
using System.Text;
namespace Ooui namespace Ooui
{ {
@ -17,16 +18,12 @@ namespace Ooui
protected override void QueueMessage (Message message) protected override void QueueMessage (Message message)
{ {
WebAssembly.Runtime.InvokeJS ("console.log('q 0')");
base.QueueMessage (message); base.QueueMessage (message);
WebAssembly.Runtime.InvokeJS ("console.log('q 1')");
TransmitQueuedMessages (); TransmitQueuedMessages ();
WebAssembly.Runtime.InvokeJS ("console.log('q end')");
} }
void TransmitQueuedMessages () void TransmitQueuedMessages ()
{ {
WebAssembly.Runtime.InvokeJS ("console.log('t 0')");
// //
// Dequeue as many messages as we can // Dequeue as many messages as we can
// //
@ -36,19 +33,23 @@ namespace Ooui
queuedMessages.Clear (); queuedMessages.Clear ();
} }
WebAssembly.Runtime.InvokeJS ("console.log('t 1')");
if (messagesToSend.Count == 0) if (messagesToSend.Count == 0)
return; return;
WebAssembly.Runtime.InvokeJS ("console.log('t 2')");
// //
// Now actually send the messages // Now actually send the messages
// //
//var json = Newtonsoft.Json.JsonConvert.SerializeObject (messagesToSend); var sb = new StringBuilder ();
WebAssembly.Runtime.InvokeJS ("alert(" + messagesToSend.Count + ")"); var head = "";
WebAssembly.Runtime.InvokeJS ("console.log('t end')"); sb.Append ("[");
foreach (var m in messagesToSend) {
sb.Append (head);
sb.Append (m.ToJson ());
head = ",";
}
sb.Append ("]");
var json = sb.ToString ();
WebAssembly.Runtime.InvokeJS ("__oouiReceiveMessages(\"" + id + "\", " + json + ")");
} }
public void ReceiveMessageJson (string json) public void ReceiveMessageJson (string json)