diff --git a/nym-sphinx-wasm/js-examples/socket/index.html b/nym-sphinx-wasm/js-examples/socket/index.html new file mode 100644 index 0000000000..6d4059d2e3 --- /dev/null +++ b/nym-sphinx-wasm/js-examples/socket/index.html @@ -0,0 +1,17 @@ + + + + + + + + Sphinx Packet Demo (wasm) + + + +

+

Loading JavaScript...
+

+ + + \ No newline at end of file diff --git a/nym-sphinx-wasm/js-examples/socket/wasm-demo.js b/nym-sphinx-wasm/js-examples/socket/wasm-demo.js new file mode 100644 index 0000000000..52d27184c3 --- /dev/null +++ b/nym-sphinx-wasm/js-examples/socket/wasm-demo.js @@ -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);