Use compressed connection codes in the transfer panel

Offers and answers now go through the HC1 codec: the sender creates a
ref per session and the answer must echo it, so pasting an offer as the
answer or an answer for another code is rejected with a specific message
while the live offer stays usable. Pasted input may be a full link.

webrtc.ts drops its Base64 JSON signaling and exchanges validated SDP
only; identity hellos travel in the code envelope. Tests, the browser
check, compare-ice and the docs follow the new format.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
SchluffeandClaude Opus 5.5 committed 2026-10-19 22:35:44 +02:00
1 parent da2999ed5d
commit 8bd37ac8b1
10 files changed
+68 -89

No files matched your search

+7 -23
View File
@@ -1,6 +1,6 @@
import test from 'node:test';
import assert from 'node:assert/strict';
import { iceConfiguration, validateDescription, getFingerprints, signalIdentity, encodeSignal, decodeSignal, waitForIceComplete, waitForBufferDrain, MAX_SIGNAL_LENGTH, MAX_BUFFERED } from '../src/lib/webrtc.ts';
import { iceConfiguration, validateDescription, getFingerprints, waitForIceComplete, waitForBufferDrain, MAX_SIGNAL_LENGTH, MAX_BUFFERED } from '../src/lib/webrtc.ts';
const fingerprint = Array.from({ length: 32 }, (_, i) => i.toString(16).padStart(2, '0')).join(':');
const sdp = `v=0\r\nm=application 9 UDP/DTLS/SCTP webrtc-datachannel\r\na=fingerprint:sha-256 ${fingerprint}\r\n`;
@@ -15,8 +15,8 @@ test('TURN is absent by default and dormant credentials cannot enable it', () =>
test('remote relay candidates require local explicit opt-in', () => {
const relayed = sdp + 'a=candidate:1 1 udp 10 192.0.2.1 5000 typ relay raddr 0.0.0.0 rport 0\r\n';
assert.throws(() => decodeSignal(encodeSignal(relayed)), /explicitly enable TURN/);
assert.equal(decodeSignal(encodeSignal(relayed), { allowTurn: true }), relayed);
assert.throws(() => validateDescription(relayed), /explicitly enable TURN/);
assert.equal(validateDescription(relayed, { allowTurn: true }), validateDescription(sdp));
});
test('fingerprints show all 32 bytes and reject ambiguous descriptions', () => {
@@ -28,12 +28,10 @@ test('fingerprints show all 32 bytes and reject ambiguous descriptions', () => {
assert.throws(() => validateDescription(sdp + 'm=audio 9 UDP/TLS/RTP/SAVPF 111\r\n'));
});
test('signals round-trip but reject legacy, malformed and oversized codes', () => {
assert.equal(decodeSignal(encodeSignal(sdp)), sdp);
assert.throws(() => decodeSignal(btoa(sdp)));
assert.throws(() => decodeSignal('bad!'));
assert.throws(() => decodeSignal('a'.repeat(MAX_SIGNAL_LENGTH + 1)));
assert.throws(() => decodeSignal(btoa(JSON.stringify({ version: 2, sdp }))));
test('descriptions are bounded and printable', () => {
assert.throws(() => validateDescription(sdp + 'a'.repeat(MAX_SIGNAL_LENGTH)), /Invalid connection description/);
assert.throws(() => validateDescription(sdp + 'a=x:\u00e9\r\n'), /Invalid connection description/);
assert.throws(() => validateDescription(42), /Invalid connection description/);
});
class Peer extends EventTarget { iceGatheringState: RTCIceGatheringState = 'gathering'; connectionState: RTCPeerConnectionState = 'new'; }
@@ -62,17 +60,3 @@ test('buffer wait resolves when already drained and rejects close or cancellatio
const cancelled = waitForBufferDrain(channel, { signal: controller.signal }); controller.abort();
await assert.rejects(cancelled, /interrupted/);
});
test('identity signaling is versioned, bounded, and optional for temporary sessions', () => {
const identity = { key: '04' + 'ab'.repeat(64), nonce: 'cd'.repeat(32) };
const code = encodeSignal(sdp, identity);
assert.equal(JSON.parse(atob(code)).version, 4);
assert.equal(decodeSignal(code), sdp);
assert.deepEqual(signalIdentity(code), identity);
assert.equal(signalIdentity(encodeSignal(sdp)), undefined);
assert.equal(JSON.parse(atob(encodeSignal(sdp))).version, 3);
assert.throws(() => decodeSignal(btoa(JSON.stringify({ version: 4, sdp }))));
assert.throws(() => decodeSignal(btoa(JSON.stringify({ version: 4, sdp, identity: { ...identity, nonce: 'bad' } }))));
assert.throws(() => decodeSignal(btoa(JSON.stringify({ version: 5, sdp, identity }))));
});