import {useRef, useState} from 'react' import {formatBytes, randomBytes} from '../util' type Props = { target: string | null targetName: string onSendText: (text: string, target: string | null) => void onSendBinary: ( data: Uint8Array, fileName: string, mime: string, target: string | null ) => Promise } const RANDOM_SIZES = [ {label: '256 KB', bytes: 256 * 1024}, {label: '1 MB', bytes: 1024 * 1024}, {label: '8 MB', bytes: 8 * 1024 * 1024}, {label: '32 MB', bytes: 32 * 1024 * 1024} ] export function Composer({target, targetName, onSendText, onSendBinary}: Props) { const [text, setText] = useState('') const [file, setFile] = useState(null) const [randomSize, setRandomSize] = useState(RANDOM_SIZES[1].bytes) const [sending, setSending] = useState(false) const fileInputRef = useRef(null) const sendText = () => { const trimmed = text.trim() if (!trimmed) return onSendText(trimmed, target) setText('') } const sendFile = async () => { if (!file || sending) return setSending(true) try { const buf = new Uint8Array(await file.arrayBuffer()) await onSendBinary( buf, file.name, file.type || 'application/octet-stream', target ) } finally { setSending(false) } } const sendRandom = async () => { if (sending) return setSending(true) try { const bytes = randomBytes(randomSize) const name = `random-${formatBytes(randomSize).replace(' ', '')}.bin` await onSendBinary(bytes, name, 'application/octet-stream', target) } finally { setSending(false) } } return (

Compose → {targetName}

setText(e.target.value)} onKeyDown={e => { if (e.key === 'Enter') sendText() }} />
binary payload
setFile(e.target.files?.[0] ?? null)} />
{file && (

Selected: {file.name} ({formatBytes(file.size)})

)}

Large payloads are automatically chunked & throttled by Trystero and sent directly peer-to-peer (end-to-end encrypted). A SHA-256 is computed on both ends so you can confirm the bytes arrived intact.

) }