change format of sharing URL

This commit is contained in:
weboko 2023-01-12 01:14:50 +01:00
parent 1aa1823963
commit 8f04dc659e
No known key found for this signature in database

View File

@ -23,20 +23,18 @@ const wakuStatusSpan = document.getElementById("waku-status");
const handshakeStatusSpan = document.getElementById("handshake-status"); const handshakeStatusSpan = document.getElementById("handshake-status");
function getPairingInfofromUrl() { function getPairingInfofromUrl() {
const urlParts = window.location.href.split("?"); const urlParams = new URLSearchParams(window.location.search);
if (urlParts.length < 2) return undefined;
const pairingParts = decodeURIComponent(urlParts[1]).split(":"); const messageNameTag = urlParams.get("messageNameTag");
if (pairingParts.length < 6) const qrCodeString = urlParams.get("qrCode");
throw new Error("invalid pairing information format");
const qrMessageNameTag = new Uint8Array( if (!(messageNameTag && qrCodeString)) {
utils.hexToBytes(pairingParts.shift()) return undefined;
); }
return new noise.InitiatorParameters( return new noise.InitiatorParameters(
pairingParts.join(":"), qrCodeString,
qrMessageNameTag utils.hexToBytes(messageNameTag)
); );
} }
@ -233,10 +231,11 @@ async function main() {
const pInfo = pairingObj.getPairingInfo(); const pInfo = pairingObj.getPairingInfo();
// Data to encode in the QR code. The qrMessageNametag too to the QR string (separated by ) // Data to encode in the QR code. The qrMessageNametag too to the QR string (separated by )
const qrString = const messageNameTagParam = `messageNameTag=${utils.bytesToHex(
utils.bytesToHex(pInfo.qrMessageNameTag) + ":" + pInfo.qrCode; pInfo.qrMessageNameTag
const qrURLString = )}`;
window.location.href + "?" + encodeURIComponent(qrString); const qrCodeParam = `qrCode=${encodeURIComponent(pInfo.qrCode)}`;
const qrURLString = `${window.location.href}?${messageNameTagParam}&${qrCodeParam}`;
handshakeStatusSpan.innerHTML = "generating QR code..."; handshakeStatusSpan.innerHTML = "generating QR code...";