Class QWBPConnection

High-level connection manager for QWBP

Handles the complete flow from QR generation to DataChannel establishment

// Device A
const connA = new QWBPConnection();
await connA.initialize();
const qrDataA = connA.getQRPayload();
// Display qrDataA as QR code

// After scanning Device B's QR:
connA.processScannedPayload(scannedData);

connA.onDataChannel((channel) => {
channel.send('Hello!');
});

Constructors

Accessors

  • get assignedRole(): null | Role
  • Assigned role (offerer or answerer), null until both QRs scanned

    Returns null | Role

Methods

  • Get the established DataChannel

    Returns null | RTCDataChannel

  • Gets the binary payload for QR code generation

    Returns Uint8Array

    Uint8Array to encode as QR code (use Byte mode)

    QWBPConnectionError if called in wrong state or connection not initialized

  • Get the Short Authentication String (SAS) for visual verification

    Both peers should display this code and users should verify they match. This detects active MITM attacks where an attacker substitutes their own QR.

    Returns Promise<null | string>

    4-digit verification code, or null if not yet connected

    const sas = await connection.getSAS();
    if (sas) {
    console.log(`Verify this code matches: ${sas}`);
    }
  • Initialize the connection and gather ICE candidates

    Creates a PC with derived ICE credentials (HKDF from fingerprint). The same PC is reused for the actual connection after role assignment.

    Must be called before getQRPayload()

    Returns Promise<void>

    QWBPConnectionError if called in wrong state or ICE gathering fails

  • Register callback for when DataChannel is ready

    Parameters

    • callback: ((channel: RTCDataChannel) => void)
        • (channel): void
        • Parameters

          • channel: RTCDataChannel

          Returns void

    Returns void

  • Process a scanned QR payload from the remote peer

    Parameters

    • data: Uint8Array

      Binary data from QR code scan

    Returns Promise<void>

    QWBPConnectionError if called in wrong state or packet is invalid

    QWBPSelfConnectionError if the scanned QR is from this device