Add file transfer PoC with manual and tracker signaling
- Core in src/main.ts: manual SDP copy/paste exchange (default, no tracker) and optional WebTorrent tracker signaling, STUN opt-out - Fingerprint security check, sender confirms before sending - ICE gathering stops after the first STUN result (5 s hard cap) - Receiver writes to OPFS via an inline dedicated worker instead of RAM - Playwright e2e suite across Chromium/Firefox and all signaling modes, opt-in 2.5 GiB transfer test (pnpm test:large) - TODO.md with review findings and the service worker plan Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
1 parent
24307eb96a
commit
aea75fff92
8 files changed
+670
-4
No files matched your search
+116
-2
@@ -1,10 +1,124 @@
|
||||
<script setup lang="ts">
|
||||
const message = 'Hello, world!';
|
||||
import { reactive, ref } from 'vue';
|
||||
import {
|
||||
answerOffer,
|
||||
createOffer,
|
||||
receiveViaTracker,
|
||||
sendViaTracker,
|
||||
settings as coreSettings,
|
||||
type Check,
|
||||
type Events,
|
||||
} from './main';
|
||||
|
||||
// Same object as the core's, so the core sees every change.
|
||||
const settings = reactive(coreSettings);
|
||||
|
||||
const file = ref<File>();
|
||||
const offer = ref('');
|
||||
const answerInput = ref('');
|
||||
const sendCode = ref('');
|
||||
|
||||
const offerInput = ref('');
|
||||
const answer = ref('');
|
||||
const receiveCode = ref('');
|
||||
|
||||
const check = ref<Check>();
|
||||
const confirmSend = ref<() => void>();
|
||||
const download = ref<{ name: string; url: string }>();
|
||||
const log = ref<string[]>([]);
|
||||
|
||||
const events: Events = {
|
||||
log: (message) => log.value.push(`${new Date().toISOString().slice(11, 23)} ${message}`),
|
||||
file: (name, url) => (download.value = { name, url }),
|
||||
check: (result, confirm) => {
|
||||
check.value = result;
|
||||
confirmSend.value = confirm;
|
||||
},
|
||||
};
|
||||
|
||||
function onConfirm() {
|
||||
confirmSend.value?.();
|
||||
confirmSend.value = undefined;
|
||||
}
|
||||
|
||||
let acceptAnswer: ((answer: string) => Promise<void>) | undefined;
|
||||
|
||||
function onPick(event: Event) {
|
||||
file.value = (event.target as HTMLInputElement).files?.[0];
|
||||
}
|
||||
|
||||
async function onCreateOffer() {
|
||||
const result = await createOffer(file.value!, events);
|
||||
offer.value = result.offer;
|
||||
acceptAnswer = result.accept;
|
||||
}
|
||||
|
||||
function onAcceptAnswer() {
|
||||
acceptAnswer?.(answerInput.value);
|
||||
}
|
||||
|
||||
async function onCreateAnswer() {
|
||||
answer.value = await answerOffer(offerInput.value, events);
|
||||
}
|
||||
|
||||
async function onShare() {
|
||||
sendCode.value = await sendViaTracker(file.value!, events);
|
||||
}
|
||||
|
||||
function onReceive() {
|
||||
receiveViaTracker(receiveCode.value, events);
|
||||
}
|
||||
</script>
|
||||
|
||||
<template>
|
||||
<main>
|
||||
<h1>HellCon</h1>
|
||||
<p>{{ message }}</p>
|
||||
|
||||
<label>
|
||||
<input id="stun" v-model="settings.stun" type="checkbox" />
|
||||
Use STUN
|
||||
</label>
|
||||
|
||||
<h2>Send</h2>
|
||||
<input type="file" @change="onPick" />
|
||||
|
||||
<h3>Manual</h3>
|
||||
<button id="create-offer" :disabled="!file" @click="onCreateOffer">Create offer</button>
|
||||
<template v-if="offer">
|
||||
<p>Offer, send this to the receiver:</p>
|
||||
<textarea id="offer" readonly :value="offer"></textarea>
|
||||
<p>Answer from the receiver:</p>
|
||||
<textarea id="answer-input" v-model="answerInput"></textarea>
|
||||
<button id="accept-answer" @click="onAcceptAnswer">Connect</button>
|
||||
</template>
|
||||
|
||||
<h3>Tracker (optional)</h3>
|
||||
<button id="share" :disabled="!file" @click="onShare">Share via tracker</button>
|
||||
<p v-if="sendCode">Code: <output id="send-code">{{ sendCode }}</output></p>
|
||||
|
||||
<h2>Receive</h2>
|
||||
|
||||
<h3>Manual</h3>
|
||||
<textarea id="offer-input" v-model="offerInput" placeholder="offer"></textarea>
|
||||
<button id="create-answer" @click="onCreateAnswer">Create answer</button>
|
||||
<template v-if="answer">
|
||||
<p>Answer, send this back to the sender:</p>
|
||||
<textarea id="answer" readonly :value="answer"></textarea>
|
||||
</template>
|
||||
|
||||
<h3>Tracker (optional)</h3>
|
||||
<input id="receive-code" v-model="receiveCode" placeholder="code" />
|
||||
<button id="receive" @click="onReceive">Receive</button>
|
||||
|
||||
<p v-if="check">
|
||||
Security check, you: <output id="check-local">{{ check.local }}</output>, peer:
|
||||
<output id="check-remote">{{ check.remote }}</output>. The other side must show the same two codes swapped.
|
||||
<button v-if="confirmSend" id="confirm" @click="onConfirm">Codes match, send</button>
|
||||
</p>
|
||||
|
||||
<p v-if="download"><a id="download" :href="download.url" :download="download.name">{{ download.name }}</a></p>
|
||||
|
||||
<h2>Log</h2>
|
||||
<pre id="log">{{ log.join('\n') }}</pre>
|
||||
</main>
|
||||
</template>
|
||||
Reference in new issue
Block a user