-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathclient.html
78 lines (66 loc) · 1.61 KB
/
client.html
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
<!DOCTYPE html>
<html lang="en">
<head>
<title>HTML-Terminal</title>
<script SRC="WSClient.js"></script>
<script>
var ws; //WSClient also uses this as this is lost on onmessage
function init()
{
ws = new WSClient("ws://127.0.0.1:5555/");
}
var a=25;
function rundemo()
{
if (typeof demo_mi !== "undefined") {
demo_mi.then (wmi => {
console.log("subsequent");
const {start} = wmi.instance.exports;
console.log(""+a+"+2+3 = "+start(a));
a=a+25;
})
return;
}
ws.send("Load File:demo.wasm",demo);
}
var demo_mi;
var wmem = new WebAssembly.Memory({initial: 32, maximum:160});
var tbl = new WebAssembly.Table({initial: 0, element: 'anyfunc'});
var wmbp=new Uint8Array(wmem.buffer);
function demo(w)
{
let x;
const view = new DataView(event.data);
x=view.getInt32(0);
if (x != 6386541) {
ws.close(); // not wasm
return;
}
let iobj = {
'env': {
'memoryBase': 0,
'tableBase': 0,
'memory': wmem,
'table': tbl,
'conlogx': function(x,y){ conlog(x,y); },
}
};
demo_mi=WebAssembly.instantiate(w, iobj);
demo_mi.then (wmi => {
console.log("First");
const {start} = wmi.instance.exports;
console.log(""+a+"+2+3 = "+start(a));
a=a+25;
})
}
function conlog(x,y)
{
console.log("x="+x," y="+y);
}
</script>
</head>
<body onload="init();">
Test Demo:
<button onclick="rundemo()">Run Demo</button><br>
</body>
</html>