Appearance
Class: MemoryTransport
A transport with a wire made of function calls.
It lets a test run the whole client with no socket at all: the test builds a MemoryTransport, drives the client exactly as a host would, and answers the frames the client sends by hand — including the ones a real server would find hard to produce on demand, like a session_expired on resume or a Pong that never comes.
Bytes cross verbatim. Nothing here decodes, so a test that asserts on what was sent asserts on the same bytes the socket would have carried.
Implements
Constructors
Constructor
ts
new MemoryTransport(opts?): MemoryTransport;Parameters
| Parameter | Type | Description |
|---|---|---|
opts | { autoOpen?: boolean; onSend?: (bytes, transport) => void; } | - |
opts.autoOpen? | boolean | Open on open(). False leaves it connecting until acceptOpen(). |
opts.onSend? | (bytes, transport) => void | Called for each frame the client sends, after it is recorded. |
Returns
MemoryTransport
Properties
| Property | Modifier | Type | Default value | Description |
|---|---|---|---|---|
sent | readonly | Uint8Array<ArrayBufferLike>[] | [] | Every frame the client sent, in order, encoded. |
Accessors
state
Get Signature
ts
get state(): TransportState;Returns
Implementation of
Methods
acceptOpen()
ts
acceptOpen(): void;Returns
void
close()
ts
close(code?, reason?): void;Parameters
| Parameter | Type | Default value |
|---|---|---|
code | number | 1000 |
reason | string | '' |
Returns
void
Implementation of
deliver()
ts
deliver(bytes): void;Deliver a frame to the client.
Parameters
| Parameter | Type |
|---|---|
bytes | Uint8Array |
Returns
void
open()
ts
open(handlers): void;Begins connecting. handlers.onOpen or handlers.onClose will follow.
Parameters
| Parameter | Type |
|---|---|
handlers | TransportHandlers |
Returns
void
Implementation of
send()
ts
send(bytes): void;Never throws: a send on a dead socket is reported through onClose, which is the path a caller already has to handle.
Parameters
| Parameter | Type |
|---|---|
bytes | Uint8Array |
Returns
void
Implementation of
serverClose()
ts
serverClose(code?, reason?): void;Kill the socket the way a tunnel does: no close handshake, code 1006.
Parameters
| Parameter | Type | Default value |
|---|---|---|
code | number | 1006 |
reason | string | 'test' |
Returns
void