Skip to main content

NetworkClient

Duplex byte channel used to exchange protocol messages with the cloud node or a peer.

A session drives it with a fixed rhythm: connect to open a channel for one protocol step, send/read to exchange messages, close when the step is done. The SDK ships CloudWebSocketClient; implement this interface to route protocol traffic over a different transport and pass it as ShardSessionConfig.client.

Methods

close()

close(): Promise<unknown>

Closes the active connection. The client remains usable for a subsequent connect.

Returns

Promise<unknown>


connect()

connect(action): Promise<void>

Opens a channel for one protocol step.

Parameters

action

NetworkAction

The step to perform. Implementations narrow this to the action subtype they route, and reject any other.

Returns

Promise<void>

A promise that resolves when the connection is established.


read()

read(): Promise<Uint8Array>

Reads the next message from the other party.

Returns

Promise<Uint8Array>

A promise that resolves to the received bytes.


reset()

reset(): void

Resets the client, clearing any pending messages and closing the connection.

Returns

void


send()

send(data): Promise<void>

Sends a binary message to the other party.

Parameters

data

Uint8Array

The bytes to send.

Returns

Promise<void>

A promise that resolves when the message is sent.


sendText()

sendText(data): Promise<void>

Sends an 'utf-8' text message to the other party.

Parameters

data

string

An 'utf-8' text message to send.

Returns

Promise<void>

A promise that resolves when the message is sent.


waitRemoteClose()

waitRemoteClose(): Promise<undefined | CloseReason>

Waits for the other party to close the connection.

Returns

Promise<undefined | CloseReason>

A promise that resolves when the remote side closes.