// Local network discovery — minimal helper used by the legacy code-pairing probe. // // `getLocalSubnet` returns the /24 prefix (e.g. "192.168.1") that the // browser is on, derived from a host-relative WebRTC ICE candidate. The // extension uses this to scan the LAN for the peer's pairing-port // WebSocket when a legacy addressless code has to be resolved. Legacy v2.14 // discovery/pair probes have been removed — see code-pairing.ts for the // v3 pairing-port scan and sync-transport.ts for the rate-limited // Phase-2 subnet probe. // Returns e.g. "192.168.1" or null if unavailable. export async function getLocalSubnet(): Promise { return new Promise((resolve) => { try { const pc = new RTCPeerConnection({ iceServers: [] }); pc.createDataChannel(''); pc.onicecandidate = (e) => { if (!e.candidate) { pc.close(); resolve(null); return; } const m = e.candidate.candidate.match(/(\d+\.\d+\.\d+)\.\d+/); if (m) { pc.close(); resolve(m[1]); } }; pc.createOffer().then(o => pc.setLocalDescription(o)).catch(() => { pc.close(); resolve(null); }); setTimeout(() => { try { pc.close(); } catch { /* ignore */ } resolve(null); }, 2000); } catch { resolve(null); } }); }