33 lines
1.2 KiB
TypeScript
33 lines
1.2 KiB
TypeScript
/**
|
|
* WebSocket utility functions
|
|
*
|
|
* This module provides smartproxy-specific WebSocket utilities
|
|
* and re-exports protocol utilities from the protocols module
|
|
*/
|
|
|
|
// Import and re-export from protocols
|
|
import { getMessageSize as protocolGetMessageSize, toBuffer as protocolToBuffer } from '../../protocols/websocket/index.js';
|
|
export type { RawData } from '../../protocols/websocket/index.js';
|
|
|
|
/**
|
|
* Get the length of a WebSocket message regardless of its type
|
|
* (handles all possible WebSocket message data types)
|
|
*
|
|
* @param data - The data message from WebSocket (could be any RawData type)
|
|
* @returns The length of the data in bytes
|
|
*/
|
|
export function getMessageSize(data: import('../../protocols/websocket/index.js').RawData): number {
|
|
// Delegate to protocol implementation
|
|
return protocolGetMessageSize(data);
|
|
}
|
|
|
|
/**
|
|
* Convert any raw WebSocket data to Buffer for consistent handling
|
|
*
|
|
* @param data - The data message from WebSocket (could be any RawData type)
|
|
* @returns A Buffer containing the data
|
|
*/
|
|
export function toBuffer(data: import('../../protocols/websocket/index.js').RawData): Buffer {
|
|
// Delegate to protocol implementation
|
|
return protocolToBuffer(data);
|
|
} |