| 262 | // --- Send side --- |
| 263 | |
| 264 | async function sendStream(addr, size, readChunk, progressEl) { |
| 265 | const conn = await tailcatDial({ addr, derpMapURL, verbose }); |
| 266 | let off = 0; |
| 267 | while (off < size) { |
| 268 | const chunk = await readChunk(off, Math.min(CHUNK, size - off)); |
| 269 | await conn.write(chunk); |
| 270 | off += chunk.length; |
| 271 | progressEl.textContent = `${off} / ${size} bytes`; |
| 272 | } |
| 273 | await conn.closeWrite(); |
| 274 | // Wait for the receiver's close: like the CLI, the peer's EOF is |
| 275 | // the confirmation that everything we sent was delivered. |
| 276 | while ((await conn.read()) !== null) {} |
| 277 | conn.close(); |
| 278 | window.tcTest.sentBytes = off; |
| 279 | window.tcTest.sendDone = true; |
| 280 | progressEl.textContent = `sent ${off} bytes`; |
| 281 | } |
| 282 | |
| 283 | $("send-btn").onclick = async () => { |
| 284 | const addr = $("send-addr").value.trim(); |