Skip to content

WebSocketTransport

Defined in: packages/ws/src/transport.ts:52

A replaceable WebSocket connection.

Generations. Each connect takes a generation, and every event is checked against the current one. A socket that has been replaced still holds its listeners and can still fire — especially a frame that finishes decompressing after the swap — and every such event is dropped. The owner therefore never has to ask “is this still my socket?”.

new WebSocketTransport(options): WebSocketTransport

Defined in: packages/ws/src/transport.ts:62

TransportOptions

WebSocketTransport

get connected(): boolean

Defined in: packages/ws/src/transport.ts:71

Whether a socket is open and able to send.

boolean


get generation(): number

Defined in: packages/ws/src/transport.ts:81

Current connection generation; increments on every connect.

number


get live(): boolean

Defined in: packages/ws/src/transport.ts:76

Whether a socket is connecting or open, and therefore still in play.

boolean

close(code?, reason?): void

Defined in: packages/ws/src/transport.ts:194

Closes the current socket, if any. Its close event still fires.

number = 1000

string = ""

void


connect(url): ConnectResult

Defined in: packages/ws/src/transport.ts:92

Opens a connection, replacing any existing one.

A construction failure is returned rather than reported through onError: the caller is mid-connect and must decide what the failure means for the attempt it is running.

string

ConnectResult


destroy(code?, reason?): void

Defined in: packages/ws/src/transport.ts:210

Abandons the current socket without reporting its close.

Used for a deliberate shutdown, where the owner has already decided the connection is over and must not be woken by the resulting close event.

number = 1000

string = ""

void


send(data): boolean

Defined in: packages/ws/src/transport.ts:174

Writes a frame.

string

boolean

Whether it reached the socket.