API reference / @jsprismarine/client / ClientSession
Class: ClientSession
Defined in: client/src/net/ClientSession.ts:22
The Minecraft layer on top of a transport: batching, compression, and turning bytes into decoded packets.
The counterpart of the server's MinecraftSession, and it has the same job, but it owns one thing that one does not: the compression state machine. A client sends RequestNetworkSettings and receives NetworkSettings with no algorithm prefix on either, and from the packet after that every batch carries one. Getting that transition wrong does not fail loudly - the first compressed batch is read as if its prefix byte were part of a packet length, and the connection dies several packets later with a decode error that points at the wrong packet entirely.
Extends
EventEmitter
Constructors
Constructor
new ClientSession(
transport,registry,logger):ClientSession
Defined in: client/src/net/ClientSession.ts:50
Parameters
transport
registry
logger
Returns
ClientSession
Overrides
EventEmitter.constructor
Methods
enableCompression()
enableCompression(
settings):void
Defined in: client/src/net/ClientSession.ts:67
Switches to the negotiated compression, once and in one place.
Parameters
settings
what NetworkSettings agreed to.
Returns
void
enableEncryption()
enableEncryption(
key):void
Defined in: client/src/net/ClientSession.ts:83
Switches encryption on, in both directions at once.
Once and never off, and both directions together: the server enables its own the moment it sends the handshake, so the very next batch either way is encrypted. There is no packet that is sent in the clear after this point, including the ClientToServerHandshake that acknowledges it.
Not on a transport that encrypts the wire itself: over NetherNet, Bedrock Dedicated Server sends the handshake but keeps batches in the clear under DTLS, and so does this client.
Parameters
key
Buffer
the 32 bytes derived from the shared secret and the server's salt.
Returns
void
isCompressionEnabled()
isCompressionEnabled():
boolean
Defined in: client/src/net/ClientSession.ts:92
Returns
boolean
isEncryptionEnabled()
isEncryptionEnabled():
boolean
Defined in: client/src/net/ClientSession.ts:88
Returns
boolean
send()
send(
packet,priority?):Promise<void>
Defined in: client/src/net/ClientSession.ts:101
Serializes a packet, batches it and hands it to the transport.
Parameters
packet
NetworkPacket<any>
a packet already carrying its data.
priority?
SendPriority = SendPriority.NORMAL
IMMEDIATE for anything the handshake is waiting on.
Returns
Promise<void>
sendImmediate()
sendImmediate(
packet):Promise<void>
Defined in: client/src/net/ClientSession.ts:111
The handshake steps, which the server is blocking on and must not be held behind anything.
Parameters
packet
NetworkPacket<any>
Returns
Promise<void>