/** * @file RTCDataChannel.ts * @description WebRTC DataChannel implementation for peer-to-peer data transfer. * @module datachannel/RTCDataChannel * * Implements the W3C RTCDataChannel interface * (https://www.w3.org/TR/webrtc/#rtcdatachannel). */ import { EventEmitter } from 'events'; /** * RTCDataChannelState - Current state of the data channel * @readonly * @enum {string} */ export declare const RTCDataChannelState: Readonly<{ CONNECTING: "connecting"; OPEN: "open"; CLOSING: "closing"; CLOSED: "closed"; }>; type RTCDataChannelReadyState = 'connecting' | 'open' | 'closing' | 'closed'; type RTCDataChannelBinaryType = 'arraybuffer' | 'blob'; /** * Package-internal events that wire an RTCDataChannel to the SCTP transport. * They are keyed by Symbol so they never collide with — or leak into — the * public event surface ('open'/'message'/'close'/'error'/'bufferedamountlow'). * The SCTP data-channel manager and the channel communicate purely by emitting * these on the channel's own EventEmitter: * * - SEND channel → transport: outbound frame `(data: Buffer, isBinary: boolean)` * - RECEIVE transport → channel: inbound frame `(data: Buffer, isBinary: boolean)` * - OPEN transport → channel: transition the channel to 'open' * - SET_ID transport → channel: assign the SCTP stream id `(id: number)` * - CLOSE channel → transport: the channel reached 'closed'; the manager * drops its entry and detaches its SEND handler so a churned * channel doesn't leak. */ export declare const RTCDataChannelEvents: Readonly<{ SEND: symbol; RECEIVE: symbol; OPEN: symbol; SET_ID: symbol; CLOSE: symbol; }>; /** * RTCDataChannelInit - Configuration for creating a data channel * @typedef {Object} RTCDataChannelInit * @property {boolean} [ordered=true] - Whether messages must arrive in order * @property {number} [maxPacketLifeTime] - Maximum packet lifetime in milliseconds * @property {number} [maxRetransmits] - Maximum number of retransmissions * @property {string} [protocol=''] - Subprotocol name * @property {boolean} [negotiated=false] - Whether channel was negotiated out-of-band * @property {number} [id] - Channel ID (required if negotiated is true) */ export interface RTCDataChannelInit { ordered?: boolean; maxPacketLifeTime?: number; maxRetransmits?: number; protocol?: string; negotiated?: boolean; id?: number; } /** * @class RTCDataChannel * @extends EventEmitter * @description Represents a bidirectional data channel between peers. * Provides reliable or unreliable data transfer with configurable ordering. * * Events: * - 'open': Fired when the channel opens * - 'message': Fired when a message is received * - 'bufferedamountlow': Fired when bufferedAmount drops below threshold * - 'error': Fired when an error occurs * - 'closing': Fired when the channel is closing * - 'close': Fired when the channel closes * * @example * const dataChannel = peerConnection.createDataChannel('myChannel', { * ordered: true, * maxRetransmits: 3 * }); * * dataChannel.on('open', () => { * console.log('Channel opened'); * dataChannel.send('Hello!'); * }); * * dataChannel.on('message', (event) => { * console.log('Received:', event.data); * }); */ export declare class RTCDataChannel extends EventEmitter { #private; /** * Create an RTCDataChannel instance. * @param {string} label - Channel label * @param {RTCDataChannelInit} [init] - Channel configuration */ constructor(label: string, init?: RTCDataChannelInit); /** * Get the channel label. * @returns {string} Channel label */ get label(): string; /** * Check if messages are delivered in order. * @returns {boolean} True if ordered */ get ordered(): boolean; /** * Get the maximum packet lifetime in milliseconds. * @returns {number|null} Maximum lifetime or null if not set */ get maxPacketLifeTime(): number | null; /** * Get the maximum number of retransmissions. * @returns {number|null} Maximum retransmits or null if not set */ get maxRetransmits(): number | null; /** * Get the subprotocol name. * @returns {string} Protocol name */ get protocol(): string; /** * Check if the channel was negotiated out-of-band. * @returns {boolean} True if negotiated */ get negotiated(): boolean; /** * Get the channel ID. * @returns {number|null} Channel ID or null if not assigned */ get id(): number | null; /** * Get the current state of the channel. * @returns {string} Channel state */ get readyState(): RTCDataChannelReadyState; /** * Get the number of bytes queued to send. * @returns {number} Buffered amount in bytes */ get bufferedAmount(): number; /** * Get the threshold for bufferedamountlow event. * @returns {number} Threshold in bytes */ get bufferedAmountLowThreshold(): number; /** * Set the threshold for bufferedamountlow event. * @param {number} value - Threshold in bytes */ set bufferedAmountLowThreshold(value: number); /** * Get the binary data type. * @returns {string} 'arraybuffer' or 'blob' */ get binaryType(): RTCDataChannelBinaryType; /** * Set the binary data type. * @param {string} value - 'arraybuffer' or 'blob' * @throws {TypeError} If value is invalid */ set binaryType(value: RTCDataChannelBinaryType); /** * Check if the channel is reliable (deprecated). * @returns {boolean} True if ordered and no packet lifetime/retransmit limits * @deprecated Use ordered, maxPacketLifeTime, and maxRetransmits instead */ get reliable(): boolean; /** * Send a message through the channel. * @param {string|ArrayBuffer|ArrayBufferView|Blob} data - Data to send * @throws {Error} If channel is not open or data is invalid */ send(data: string | ArrayBuffer | ArrayBufferView | Buffer): void; /** * Close the data channel. */ close(): void; } export {};