Skip to content

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 ​

ParameterTypeDescription
opts{ autoOpen?: boolean; onSend?: (bytes, transport) => void; }-
opts.autoOpen?booleanOpen on open(). False leaves it connecting until acceptOpen().
opts.onSend?(bytes, transport) => voidCalled for each frame the client sends, after it is recorded.

Returns ​

MemoryTransport

Properties ​

PropertyModifierTypeDefault valueDescription
sentreadonlyUint8Array<ArrayBufferLike>[][]Every frame the client sent, in order, encoded.

Accessors ​

state ​

Get Signature ​

ts
get state(): TransportState;
Returns ​

TransportState

Implementation of ​

Transport.state

Methods ​

acceptOpen() ​

ts
acceptOpen(): void;

Returns ​

void


close() ​

ts
close(code?, reason?): void;

Parameters ​

ParameterTypeDefault value
codenumber1000
reasonstring''

Returns ​

void

Implementation of ​

Transport.close


deliver() ​

ts
deliver(bytes): void;

Deliver a frame to the client.

Parameters ​

ParameterType
bytesUint8Array

Returns ​

void


open() ​

ts
open(handlers): void;

Begins connecting. handlers.onOpen or handlers.onClose will follow.

Parameters ​

ParameterType
handlersTransportHandlers

Returns ​

void

Implementation of ​

Transport.open


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 ​

ParameterType
bytesUint8Array

Returns ​

void

Implementation of ​

Transport.send


serverClose() ​

ts
serverClose(code?, reason?): void;

Kill the socket the way a tunnel does: no close handshake, code 1006.

Parameters ​

ParameterTypeDefault value
codenumber1006
reasonstring'test'

Returns ​

void

Talkline documentation