diff --git a/examples/sendE2E/receiver.html b/examples/sendE2E/receiver.html index 89a0d62e1c8831c40de35a68319d1e657c0e2252..620de91e7751ae26d143966aca08627f559a56e3 100644 --- a/examples/sendE2E/receiver.html +++ b/examples/sendE2E/receiver.html @@ -31,6 +31,7 @@ // Get element to print log messages to const logOutput = document.getElementById("logOutput") + const htmlConsole = newHtmlConsole(logOutput) // Get button that will stop the network follower const stopNetworkFollowerBtn = document.getElementById("stopNetworkFollowerBtn") @@ -38,15 +39,19 @@ // Client specific parameters const recipientContactFile = ''; const myContactFileName = 'receiverContact.xxc'; - const statePath = 'statePathRecipient'; + const statePath = 'statePathRecipient2'; const statePass = 'password'; document.getElementById('ndfInput').addEventListener('change', e => { let reader = new FileReader(); - reader.onload = function (e) { - SendE2e(logOutput, stopNetworkFollowerBtn, e.target.result, - recipientContactFile, myContactFileName, statePath, - statePass); + reader.onload = async function (e) { + try { + await SendE2e(htmlConsole, stopNetworkFollowerBtn, + e.target.result, recipientContactFile, + myContactFileName, statePath, statePass); + } catch (e) { + htmlConsole.error(e) + } }; reader.readAsText(e.target.files[0]); }, false); diff --git a/examples/sendE2E/sender.html b/examples/sendE2E/sender.html index 911810608ade5788191cdc7b447ab8bcf5778d15..7ece9fe5b7235363eba951a4b3a89b2bcea95154 100644 --- a/examples/sendE2E/sender.html +++ b/examples/sendE2E/sender.html @@ -31,22 +31,27 @@ // Get element to print log messages to const logOutput = document.getElementById("logOutput") + const htmlConsole = newHtmlConsole(logOutput) // Get button that will stop the network follower const stopNetworkFollowerBtn = document.getElementById("stopNetworkFollowerBtn") // Client specific parameters - const recipientContactFile = '<xxc(2)z91w2qXUFQa8VESTtNb3DfAsk92z5hSIffDK1boKo+UDrgZ7Ugdw/BAr6QEXzSXng3CKqgISZEMidcAYP+p1WEQWB0Ixb24KK9mNNzp4sjo1vcRAxrJo14NtM/vTYp6PEK0mh5eshYdq4fCUQWvZKf+sAdLp3bjliSBdKfkHucUHuw66AKsXrdp9YmdeTp1mlf4k68kB0dmaMbFn/76EjH7vceLN0qeek077KD/VOet6UAoczm/WePC+tFsbUx1U11tl4WoBsnsOsn+Sj7bTRQbOGLhs7rxgQ/RntruVt4qdSNrLJ5w8fVKraYyQJsG6nbhC1cRCiEThrluM+tD8rDIhXnOCE7/qVR4O1PTY7VcUDygkt++Gx9xsNCsRddStTwOfCNnpcewzx4arDLAAUnPtSmFZDwkLRY2dIfNTAgW7vihOwMzEoOyq9eSoczRzZ6UH6CIRfxhy9fJzexvpUdcwx2aTBGfncWDOYJXILqwHCgbXGWBKLjxtTYb4YNAkIyULS8FK41s8tPLjUh0rYAQA06lgBJvcdMFUxg3cNU/CE17oWK3GiFNTPArQitNVWm0qJ3nX82l3KAAAAgA7PMmnkLNn1aaBebnustlNYA==xxc>'; - const myContactFileName = 'senderContact.xxc'; - const statePath = 'statePathSender'; + const recipientContactFile = '<xxc(2)I71lyX8LvKP6cJhedliFLIKzXN/2ArmBAfAxkk1QapADrgZ7Ugdw/BAr6RDo4K2MfHn7e06Kru7jW05ROtaaoNSyMIB3R77BIJy7xB/fvkzteTpxxmHtZdXPt9UpYVA9WKzbM57vkmy+U6BlRJIrN97tAlWbODIG1FGpjWI/BCdqwaLgu0wTYLzzEw38NNyax0E2MnvURgQoSfnX5V+m+Qd2sJBqfBKi9tlLuNcaFI+TGyKGbZdSs4AZdiL/Xm94w1/id4SDEoV73RaJb3RH+W+rEMIl1SnZ4U6Ifo39cZfRKevL2mXUZj/SE0NWGl4+10Jovy0Hp6NoW2iMH4zB30xv3fqyp8ATAYXYYO5ToFmHvP1fRLq7TKa+WtGnO70uiykBaYl219WcGYIz4jXDYyN3yNnOhihKo2tauyC0qGeGCSoACDxvzLGTHxHkS/cDA92L0MEsiXy3HIuv5+OYZBuiWl1dLxjkUKKo4f3VyDUaWjrlUFqVO95X29+Zuw++AK1TVnWtt/F4J+L91hwEfDGxYn5f2I6tNKLXnyXlPVDpa1EE6+d1LWznfXVHHzL58lBIK0Yk9MKGHQAAAgA7OaXVXCYpP2SfHIEp3s0tRA==xxc>'; + const myContactFileName = ''; + const statePath = 'statePathSender2'; const statePass = 'password'; document.getElementById('ndfInput').addEventListener('change', e => { let reader = new FileReader(); - reader.onload = function (e) { - SendE2e(logOutput, stopNetworkFollowerBtn, e.target.result, - recipientContactFile, myContactFileName, statePath, - statePass); + reader.onload = async function (e) { + try { + await SendE2e(htmlConsole, stopNetworkFollowerBtn, + e.target.result, recipientContactFile, + myContactFileName, statePath, statePass); + } catch (e) { + htmlConsole.error(e) + } }; reader.readAsText(e.target.files[0]); }, false); diff --git a/examples/sendE2E/xxdk.js b/examples/sendE2E/xxdk.js index b8ba56d3c6ee5d6fccc7ac813c0dd93009564c0a..42aee6c614819a4ff9efd21d10fa6095e8e2c3ca 100644 --- a/examples/sendE2E/xxdk.js +++ b/examples/sendE2E/xxdk.js @@ -5,12 +5,10 @@ // LICENSE file. // //////////////////////////////////////////////////////////////////////////////// -async function SendE2e(logOutput, stopNetworkFollowerBtn, ndf, +async function SendE2e(htmlConsole, stopNetworkFollowerBtn, ndf, recipientContactFile, myContactFileName, statePath, statePassString) { - const htmlConsole = newHtmlConsole(logOutput) - let enc = new TextEncoder(); let dec = new TextDecoder(); @@ -41,7 +39,13 @@ async function SendE2e(logOutput, stopNetworkFollowerBtn, ndf, // Login with the same statePath and statePass used to call NewCmix htmlConsole.log("Starting to load cmix with path " + statePath) - const net = await LoadCmix(statePath, statePass, GetDefaultCMixParams()); + let net; + try { + net = await LoadCmix(statePath, statePass, GetDefaultCMixParams()); + } catch (e) { + htmlConsole.error("Failed to load Cmix: " + e) + return + } htmlConsole.log("Loaded Cmix.") console.log("Loaded Cmix: " + JSON.stringify(net)) @@ -51,8 +55,8 @@ async function SendE2e(logOutput, stopNetworkFollowerBtn, ndf, try { htmlConsole.log("Getting reception identity.") identity = LoadReceptionIdentity(identityStorageKey, net.GetID()); - } catch { - htmlConsole.log("No reception identity found. Generating a new one") + } catch (e) { + htmlConsole.log("No reception identity found. Generating a new one: " + e) // If no extant xxdk.ReceptionIdentity, generate and store a new one identity = net.MakeReceptionIdentity(); @@ -64,8 +68,10 @@ async function SendE2e(logOutput, stopNetworkFollowerBtn, ndf, const myContactFile = dec.decode(GetContactFromReceptionIdentity(identity)) htmlConsole.log("My contact file: " + encodeURIComponent(myContactFile)) - // Start file download. - download(myContactFileName, myContactFile); + // Start contact file download + if (myContactFileName !== '') { + download(myContactFileName, myContactFile); + } let confirm = false; let confirmContact;