diff --git a/examples/sendE2E/README.md b/examples/sendE2E/README.md index ade0f0e9b14db5285eb03956e3d2a0a5fd3d33d5..48c53c59d2a91c541f04483c7b8d8396f883ec3e 100644 --- a/examples/sendE2E/README.md +++ b/examples/sendE2E/README.md @@ -1,4 +1,7 @@ # SendE2E Test This test sets up two clients in the browser and has one client send an E2E -message to the other. \ No newline at end of file +message to the other. + +## Running the Test + diff --git a/examples/sendE2E/receiver.html b/examples/sendE2E/receiver.html index cfe2d11233f29703bc496bb7f18ee1f09c906180..3ef4f64bfbd5a7b6fab03f82814440e904ff4729 100644 --- a/examples/sendE2E/receiver.html +++ b/examples/sendE2E/receiver.html @@ -32,6 +32,9 @@ // Get element to print log messages to const logOutput = document.getElementById("logOutput") + // Get button that will stop the network follower + const stopNetworkFollowerBtn = document.getElementById("stopNetworkFollowerBtn") + // Client specific parameters const recipientContactFile = ''; const myContactFileName = 'receiverContact.xxc'; @@ -41,7 +44,7 @@ document.getElementById('ndfInput').addEventListener('change', e => { let reader = new FileReader(); reader.onload = function (e) { - SendE2e(logOutput, e.target.result, + SendE2e(logOutput, stopNetworkFollowerBtn, e.target.result, recipientContactFile, myContactFileName, statePath, statePass); }; @@ -53,6 +56,7 @@ <body> <h1 style="margin-top: 0">SendE2E: Receiver</h1> <input type="button" style="float:right;" value="Download Log File" id="logFileDownload"> +<input type="button" style="float:right;display:none;" value="Stop Network Follower" id="stopNetworkFollowerBtn"> <p>Selecting an NDF will start the client.</p> <form id="startCmix"> <div> diff --git a/examples/sendE2E/sender.html b/examples/sendE2E/sender.html index da6a347c48248ce22a192f577934f368b123997f..f051b24cf83d530d252c30d22d46e20c0c629888 100644 --- a/examples/sendE2E/sender.html +++ b/examples/sendE2E/sender.html @@ -17,8 +17,6 @@ <script type="text/javascript" src="xxdk.js"></script> <script type="text/javascript" src="../wasm_exec.js"></script> <script> - // Use the encoder to convert a string to Uint8Array using enc.encode() - const go = new Go(); WebAssembly.instantiateStreaming(fetch("../xxdk.wasm"), go.importObject).then((result) => { go.run(result.instance); @@ -34,6 +32,9 @@ // Get element to print log messages to const logOutput = document.getElementById("logOutput") + // Get button that will stop the network follower + const stopNetworkFollowerBtn = document.getElementById("stopNetworkFollowerBtn") + // Client specific parameters const recipientContactFile = '<xxc(2)3Rk5yAbf4xfrKbxuHXudBmy6Y8ftb9fxpqPzBOZL2nIDrgZ7Ugdw/BAr6UOUDFtAKbqUp7U6rfxNbwkYOuTySVFQqKpGAVNVaSWgNEUmG2fkK0bTCGamLELsIn+1dWmO3vA+TXx8HPq1Y79pFvs87wN5bD+F97sOto085y5oMuEwoSuQu4nwS9vCoXPgOpXJjeRBqKYOM/ObbtF4OAhwmR5C86F2pDSBAkenKVt2/4/SeHdlZqmriqd5QDMhEQlXdyjUl/GfuqOFHiTyqcfQq7krE3pNhI0YYZ2VPK+gnM7klGbTJeNZ23jQLxC8UjSTd/tZbz764dv3ncqQDhdGpqEjk/0larKIscMcKFT/JqHyduiVW6PjZ382vO+TZYre0pF4fG4bnY7rbiy2iegeH/GtemJJLtYsww1PFFRKEz7tM1P/B3+eT/CkrFwT2O7l6lobi7kamO4mmxX26IF7WOHc68c99SrIUKBzFViY67TCRvO3/yt11TOpudAsnoix7sEW8ZwozVnLvVvSBMr6FTEyDdn2JncL3l5xtWH7L5cimQsl+PLJTwtBKMX6aek9W4IuIBhdSu1yYQAAAgA7UO/H/diSxQainCF4/o6URQ==xxc>'; const myContactFileName = 'theirE2eContact.xxc'; @@ -41,20 +42,21 @@ const statePass = 'password'; document.getElementById('ndfInput').addEventListener('change', e => { - let reader = new FileReader(); - reader.onload = function (e) { - SendE2e(logOutput, e.target.result, - recipientContactFile, myContactFileName, statePath, - statePass); - }; - reader.readAsText(e.target.files[0]); - }, false); + let reader = new FileReader(); + reader.onload = function (e) { + SendE2e(logOutput, stopNetworkFollowerBtn, e.target.result, + recipientContactFile, myContactFileName, statePath, + statePass); + }; + reader.readAsText(e.target.files[0]); + }, false); }); </script> </head> <body> <h1 style="margin-top: 0">SendE2E: Sender</h1> <input type="button" style="float:right;" value="Download Log File" id="logFileDownload"> +<input type="button" style="float:right;display:none;" value="Stop Network Follower" id="stopNetworkFollowerBtn"> <p>Selecting an NDF will start the client.</p> <form id="startCmix"> <div> diff --git a/examples/sendE2E/xxdk.js b/examples/sendE2E/xxdk.js index 0a72338611f8450f88968268a2c412d0cf3e6441..b8ba56d3c6ee5d6fccc7ac813c0dd93009564c0a 100644 --- a/examples/sendE2E/xxdk.js +++ b/examples/sendE2E/xxdk.js @@ -5,8 +5,9 @@ // LICENSE file. // //////////////////////////////////////////////////////////////////////////////// -async function SendE2e(logOutput, ndf, recipientContactFile, myContactFileName, - statePath, statePassString) { +async function SendE2e(logOutput, stopNetworkFollowerBtn, ndf, + recipientContactFile, myContactFileName, statePath, + statePassString) { const htmlConsole = newHtmlConsole(logOutput) @@ -101,6 +102,12 @@ async function SendE2e(logOutput, ndf, recipientContactFile, myContactFileName, htmlConsole.log("Started network follower") + stopNetworkFollowerBtn.style.display = 'block'; + stopNetworkFollowerBtn.addEventListener('click', () => { + htmlConsole.log("Stopping network follower") + net.StopNetworkFollower() + }) + // Provide a callback that will be signalled when network health status changes let health = false net.AddHealthCallback({ @@ -112,11 +119,11 @@ async function SendE2e(logOutput, ndf, recipientContactFile, myContactFileName, htmlConsole.log("Waiting for network to be healthy") try { await sleepUntil(() => health === true, 25000); - htmlConsole.log("Network is healthy: " + health) } catch { htmlConsole.error("Timed out. Network is not healthy: " + health) throw new Error("Timed out. Network is not healthy: " + health) } + htmlConsole.log("Network is healthy: " + health) ////////////////////////////////////////////////////////////////////////////