/** * RdpBridge — TCP/TLS connection to an RDP server. * * Implements the minimal RDP protocol phases needed for screen + input: * * Phase 1 X.224 Connection Request / Confirm (TPKT/X.224) * Phase 2 TLS upgrade (PROTOCOL_SSL negotiated in Phase 1) * Phase 3 MCS Connect (T.125 / GCC Conference Create) * Phase 4 MCS Erect Domain + Attach User * Phase 5 MCS Channel Joins (Global + optional cliprdr) * Phase 6 RDP Security Exchange + Client Info (Classic RDP Security disabled; TLS carries everything) * Phase 7 Demand-Active / Confirm-Active capability exchange * Phase 8 Running — bitmap updates, input events, clipboard * * Emits: * 'fbu' (rects: RdpRect[]) — one or more bitmap rectangles * 'cursor' ({ hotX, hotY, width, height, rgba: string }) — cursor shape update * 'clipboard' (text: string) — remote clipboard changed * 'error' (err: Error) — unrecoverable error * 'close' () — TCP/TLS connection closed */ import { EventEmitter } from 'events'; import type { RdpInfo, RdpConnectOptions } from './types'; export declare class RdpBridge extends EventEmitter { private _sock; private _closed; private _recvBuf; private _handshakeBuf; private _width; private _height; private _colorDepth; private _userId; private _shareId; private _connected; private _opts; private _reconnectCount; private static readonly _MAX_RECONNECTS; /** Optional external logger — set before calling connect(). */ log: (msg: string) => void; get width(): number; get height(): number; /** * Connect to an RDP server. Resolves once the desktop is ready. */ connect(opts: RdpConnectOptions): Promise; /** Send a mouse event. buttonMask: bit0=left, bit1=right, bit2=middle */ sendMouse(x: number, y: number, buttonMask: number): void; /** Send a key event. jsKeyCode is the browser keyCode value. */ sendKey(jsKeyCode: number, down: boolean): void; /** Push local clipboard text to the remote. */ sendClipboardText(text: string): void; close(): void; /** * Reconnect using saved opts — called after xrdp's clean TCP close that * follows the initial session-creation handshake. */ private _doReconnect; private _handshake; /** * Handle RDP license exchange after Client Info PDU. * Responds to SERVER_LICENSE_REQUEST and PLATFORM_CHALLENGE until the * server completes licensing (or sends a non-license PDU). */ private _doLicenseExchange; private _runLoop; private _dispatchPdu; private _handleDataPdu; private _handleUpdatePdu; private _parseBitmapUpdate; private _sendInput; private _sendX224Data; private _sendMcsData; /** Read a complete TPKT from the given socket (used during handshake only). */ private _readTpkt; /** Read a TPKT and return only the payload (after TPKT+X.224 headers). */ private _readTpktPayload; /** * Wait for an RDP PDU with a specific pduType in the Share Control Header. * Times out after `timeoutMs` ms. */ private _waitForPduType; /** Try to parse one complete TPKT from _recvBuf without blocking. * Fast-path PDUs (first byte != 0x03) are skipped with a warning since we * advertise no fast-path support; they should not appear, but guard anyway. */ private _tryParseTpkt; }