chat.html: echo sent message instantly instead of after transmit completes
This commit is contained in:
parent
2cd3c05fee
commit
90a207b8c8
1 changed files with 9 additions and 7 deletions
|
|
@ -1680,27 +1680,29 @@ async function sendCurrentMsg() {
|
||||||
if (!msg) return;
|
if (!msg) return;
|
||||||
if (!carrierOn) { logLine('err', 'start carrier first'); return; }
|
if (!carrierOn) { logLine('err', 'start carrier first'); return; }
|
||||||
const mode = currentMode();
|
const mode = currentMode();
|
||||||
|
if (mode === 'passphrase' && !groupKey) { logLine('err', 'no room key'); return; }
|
||||||
|
if (mode === 'pubkey' && !Array.from(peers.values()).some(p => p.sharedKey)) {
|
||||||
|
logLine('err', 'no pubkey peers ready'); return;
|
||||||
|
}
|
||||||
/* must match the inbound decoder, which stays at ZEBRA_BAUD_HANDSHAKE for the
|
/* must match the inbound decoder, which stays at ZEBRA_BAUD_HANDSHAKE for the
|
||||||
* life of the link — data sent at any other baud won't decode on the far side. */
|
* life of the link — data sent at any other baud won't decode on the far side. */
|
||||||
const baud = ZEBRA_BAUD_HANDSHAKE;
|
const baud = ZEBRA_BAUD_HANDSHAKE;
|
||||||
|
const handle = handleIn.value.trim() || 'me';
|
||||||
|
/* echo immediately so the sender sees the message without waiting for the
|
||||||
|
* (slow, multi-second at low baud) transmit to finish */
|
||||||
|
logLine('me', `<span class="from">${escapeHtml(handle)}:</span> ${escapeHtml(msg)}`);
|
||||||
|
$('msg-in').value = '';
|
||||||
try {
|
try {
|
||||||
if (mode === 'passphrase') {
|
if (mode === 'passphrase') {
|
||||||
if (!groupKey) { logLine('err', 'no room key'); return; }
|
|
||||||
const ct = await aesEncrypt(groupKey, msg);
|
const ct = await aesEncrypt(groupKey, msg);
|
||||||
await txFrame(await buildDataFrame(ct), baud);
|
await txFrame(await buildDataFrame(ct), baud);
|
||||||
} else {
|
} else {
|
||||||
let sent = 0;
|
|
||||||
for (const p of peers.values()) {
|
for (const p of peers.values()) {
|
||||||
if (!p.sharedKey) continue;
|
if (!p.sharedKey) continue;
|
||||||
const ct = await aesEncrypt(p.sharedKey, msg);
|
const ct = await aesEncrypt(p.sharedKey, msg);
|
||||||
await txFrame(await buildDataFrame(ct), baud);
|
await txFrame(await buildDataFrame(ct), baud);
|
||||||
sent++;
|
|
||||||
}
|
}
|
||||||
if (sent === 0) { logLine('err', 'no pubkey peers ready'); return; }
|
|
||||||
}
|
}
|
||||||
const handle = handleIn.value.trim() || 'me';
|
|
||||||
logLine('me', `<span class="from">${escapeHtml(handle)}:</span> ${escapeHtml(msg)}`);
|
|
||||||
$('msg-in').value = '';
|
|
||||||
} catch (e) {
|
} catch (e) {
|
||||||
logLine('err', 'send failed: ' + e.message);
|
logLine('err', 'send failed: ' + e.message);
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue