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?”.
Constructors
Section titled “Constructors”Constructor
Section titled “Constructor”new WebSocketTransport(
options):WebSocketTransport
Defined in: packages/ws/src/transport.ts:62
Parameters
Section titled “Parameters”options
Section titled “options”Returns
Section titled “Returns”WebSocketTransport
Accessors
Section titled “Accessors”connected
Section titled “connected”Get Signature
Section titled “Get Signature”get connected():
boolean
Defined in: packages/ws/src/transport.ts:71
Whether a socket is open and able to send.
Returns
Section titled “Returns”boolean
generation
Section titled “generation”Get Signature
Section titled “Get Signature”get generation():
number
Defined in: packages/ws/src/transport.ts:81
Current connection generation; increments on every connect.
Returns
Section titled “Returns”number
Get Signature
Section titled “Get Signature”get live():
boolean
Defined in: packages/ws/src/transport.ts:76
Whether a socket is connecting or open, and therefore still in play.
Returns
Section titled “Returns”boolean
Methods
Section titled “Methods”close()
Section titled “close()”close(
code?,reason?):void
Defined in: packages/ws/src/transport.ts:194
Closes the current socket, if any. Its close event still fires.
Parameters
Section titled “Parameters”number = 1000
reason?
Section titled “reason?”string = ""
Returns
Section titled “Returns”void
connect()
Section titled “connect()”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.
Parameters
Section titled “Parameters”string
Returns
Section titled “Returns”ConnectResult
destroy()
Section titled “destroy()”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.
Parameters
Section titled “Parameters”number = 1000
reason?
Section titled “reason?”string = ""
Returns
Section titled “Returns”void
send()
Section titled “send()”send(
data):boolean
Defined in: packages/ws/src/transport.ts:174
Writes a frame.
Parameters
Section titled “Parameters”string
Returns
Section titled “Returns”boolean
Whether it reached the socket.