wasm: demo js starting to work

This commit is contained in:
Dave Hrycyszyn
2020-04-14 15:58:34 +01:00
parent dddac13496
commit c2e3582032
2 changed files with 44 additions and 0 deletions
@@ -0,0 +1,17 @@
<!DOCTYPE html>
<html lang="en">
<script src="wasm-demo.js" async></script>
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Sphinx Packet Demo (wasm)</title>
</head>
<body>
<p>
<div id="output">Loading JavaScript...</div>
</p>
</body>
</html>
@@ -0,0 +1,27 @@
display("Initialising...");
var port = '1793' // gateway websocket listens on 1793 by default, change if yours is different
var connection = new WebSocket('ws://127.0.0.1:' + port);
// Open a connection and display a status message.
connection.onopen = function () {
display('Opened connection to Nym gateway websocket.');
};
// Log errors
connection.onerror = function (error) {
display('WebSocket Error ' + error);
};
function display(message) {
document.getElementById("output").innerHTML = message;
}
var sequenceNum = 0;
window.setInterval(function () {
var message = "FOOMP FOOMP FOOMP " + sequenceNum;
connection.send(message);
display("Sent: " + message);
sequenceNum += 1;
}, 500);