tasq/node_modules/@supabase/realtime-js/dist/main/lib/websocket-factory.d.ts

81 lines
2.6 KiB
TypeScript
Raw Permalink Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

export interface WebSocketLike {
readonly CONNECTING: number;
readonly OPEN: number;
readonly CLOSING: number;
readonly CLOSED: number;
readonly readyState: number;
readonly url: string;
readonly protocol: string;
/**
* Closes the socket, optionally providing a close code and reason.
*/
close(code?: number, reason?: string): void;
/**
* Sends data through the socket using the underlying implementation.
*/
send(data: string | ArrayBufferLike | Blob | ArrayBufferView): void;
onopen: ((this: any, ev: Event) => any) | null;
onmessage: ((this: any, ev: MessageEvent) => any) | null;
onclose: ((this: any, ev: CloseEvent) => any) | null;
onerror: ((this: any, ev: Event) => any) | null;
/**
* Registers an event listener on the socket (compatible with browser WebSocket API).
*/
addEventListener(type: string, listener: EventListener): void;
/**
* Removes a previously registered event listener.
*/
removeEventListener(type: string, listener: EventListener): void;
binaryType?: string;
bufferedAmount?: number;
extensions?: string;
dispatchEvent?: (event: Event) => boolean;
}
export interface WebSocketEnvironment {
type: 'native' | 'ws' | 'cloudflare' | 'unsupported';
constructor?: any;
error?: string;
workaround?: string;
}
/**
* Utilities for creating WebSocket instances across runtimes.
*/
export declare class WebSocketFactory {
/**
* Static-only utility prevent instantiation.
*/
private constructor();
private static detectEnvironment;
/**
* Returns the best available WebSocket constructor for the current runtime.
*
* @category Realtime
*
* @example Example with error handling
* ```ts
* try {
* const WS = WebSocketFactory.getWebSocketConstructor()
* const socket = new WS('wss://example.com/socket')
* } catch (error) {
* console.error('WebSocket not available in this environment.', error)
* }
* ```
*/
static getWebSocketConstructor(): typeof WebSocket;
/**
* Detects whether the runtime can establish WebSocket connections.
*
* @category Realtime
*
* @example Example in a Node.js script
* ```ts
* if (!WebSocketFactory.isWebSocketSupported()) {
* console.error('WebSockets are required for this script.')
* process.exitCode = 1
* }
* ```
*/
static isWebSocketSupported(): boolean;
}
export default WebSocketFactory;
//# sourceMappingURL=websocket-factory.d.ts.map