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 b = new Button ("Click Me");
var e = new Div (new Div (l), b);
var c = 0;
b.Click += (s, ee) => {
b.Text = $"Clicked {c} times";
};
UI.SetGlobalElement ("main", e);
return e.ToString ();

View File

@ -322,6 +322,16 @@ function fixupValue (v) {
// == 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 = {
onRuntimeInitialized: function () {
console.log ("Done with WASM module instantiation.");
@ -405,22 +415,20 @@ var MonoRuntime = {
var WebAssemblyApp = {
init: function () {
this.loading = document.getElementById ("loading");
this.output = document.getElementById ("output");
this.findMethods ();
var res = this.runApp ("1", "2");
this.output.value = res;
this.output.hidden = false;
this.loading.hidden = true;
},
runApp: function (a, b) {
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")]);
var res = MonoRuntime.call_method (this.add_method, null, [MonoRuntime.mono_string (a), MonoRuntime.mono_string (b)]);
return MonoRuntime.conv_string (res);
return res;
} catch (e) {
return e.msg;
}

View File

@ -1,5 +1,6 @@
using System;
using System.Collections.Generic;
using System.Text;
namespace Ooui
{
@ -17,16 +18,12 @@ namespace Ooui
protected override void QueueMessage (Message message)
{
WebAssembly.Runtime.InvokeJS ("console.log('q 0')");
base.QueueMessage (message);
WebAssembly.Runtime.InvokeJS ("console.log('q 1')");
TransmitQueuedMessages ();
WebAssembly.Runtime.InvokeJS ("console.log('q end')");
}
void TransmitQueuedMessages ()
{
WebAssembly.Runtime.InvokeJS ("console.log('t 0')");
//
// Dequeue as many messages as we can
//
@ -36,19 +33,23 @@ namespace Ooui
queuedMessages.Clear ();
}
WebAssembly.Runtime.InvokeJS ("console.log('t 1')");
if (messagesToSend.Count == 0)
return;
WebAssembly.Runtime.InvokeJS ("console.log('t 2')");
//
// Now actually send the messages
//
//var json = Newtonsoft.Json.JsonConvert.SerializeObject (messagesToSend);
WebAssembly.Runtime.InvokeJS ("alert(" + messagesToSend.Count + ")");
WebAssembly.Runtime.InvokeJS ("console.log('t end')");
var sb = new StringBuilder ();
var head = "";
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)