/** * @file stun-client.ts * @description STUN (Session Traversal Utilities for NAT) client implementation * @module stun/stun-client * * STUN Protocol: RFC 5389 * TURN Protocol: RFC 5766 */ import { EventEmitter } from 'events'; /** * Constructor options for {@link STUNClient}. */ interface STUNClientOptions { /** STUN/TURN server address */ server: string; /** Server port */ port: number; /** TURN username */ username?: string; /** TURN password */ credential?: string; /** Transport protocol (udp/tcp) */ transport?: string; /** Wrap the link to the server in DTLS (TURN-over-DTLS, the `turns:` scheme) */ secure?: boolean; /** * Validate the TURN server's TLS certificate (TURN-over-TLS only). Defaults * to `true`. Set `false` to accept self-signed / otherwise unverifiable * server certificates — insecure, intended for local/test servers only. */ rejectUnauthorized?: boolean; /** Additional query parameters from URL */ params?: Record; } /** * Reflexive address info resolved from a STUN Binding response. */ interface ReflexiveAddress { address: string; port: number; family: string; } /** * Relay address info resolved from a TURN Allocate response. */ interface RelayAddress { relayedAddress: string; relayedPort: number; lifetime: number; type: 'relay'; } /** * Result of a TURN Refresh response. */ interface RefreshResult { lifetime: number; } /** * Result of a generic success response (CreatePermission / ChannelBind). */ interface OkResult { ok: true; } /** * Union of every result shape a transaction may resolve with. */ type TransactionResult = ReflexiveAddress | RelayAddress | RefreshResult | OkResult; /** * @class STUNClient * @description STUN/TURN client for NAT traversal */ declare class STUNClient extends EventEmitter { #private; /** * Create a STUN client * @param {Object} options - Client options * @param {string} options.server - STUN/TURN server address * @param {number} options.port - Server port * @param {string} [options.username] - TURN username * @param {string} [options.credential] - TURN password * @param {string} [options.transport='udp'] - Transport protocol (udp/tcp) * @param {Object} [options.params={}] - Additional query parameters from URL */ constructor(options: STUNClientOptions); /** * Connect to the STUN/TURN server * @returns {Promise} */ connect(): Promise; /** * Send a STUN Binding Request to get reflexive address * @returns {Promise} Reflexive address info */ getReflexiveAddress(): Promise; /** * Send a TURN Allocate Request to get relay address * @param {number} [lifetime=600] - Allocation lifetime in seconds * @returns {Promise} Relay address info */ allocateRelay(lifetime?: number): Promise; /** * Send a TURN Refresh Request to keep allocation alive * @param {number} [lifetime=600] - Allocation lifetime in seconds * @returns {Promise} Updated allocation info */ refreshAllocation(lifetime?: number): Promise; /** * Create a TURN Permission for a peer * @param {string} peerAddress - Peer IP address * @returns {Promise} */ createPermission(peerAddress: string): Promise; /** * Send data to a peer via TURN Send Indication * @param {string} peerAddress - Peer IP address * @param {number} peerPort - Peer port * @param {Buffer} data - Data to send * @returns {Promise} */ sendIndication(peerAddress: string, peerPort: number, data: Buffer): Promise; /** * Close the client */ close(): void; } export default STUNClient; export { STUNClient };