[API reference](https://jsprismarine.dev/api/index.md) / [@jsprismarine/prismarine](https://jsprismarine.dev/api/@jsprismarine/prismarine/index.md) / network/MinecraftSession

# network/MinecraftSession

## Classes

- [MinecraftSession](https://jsprismarine.dev/api/@jsprismarine/prismarine/network/MinecraftSession/classes/MinecraftSession.md)

## Interfaces

### PacketBatchSendOptions

Defined in: [packages/prismarine/src/network/MinecraftSession.ts:880](https://github.com/JSPrismarine/JSPrismarine/blob/e928b08f56694af6821b757ce6b196faebd3199c/packages/prismarine/src/network/MinecraftSession.ts#L880)

Options for a session to frame packets as one batch.

#### Extends

- [`PacketBatchOptions`](https://jsprismarine.dev/api/@jsprismarine/prismarine/network/encodePacketBatch/index.md#packetbatchoptions)

#### Properties

##### compressed?

> `optional` **compressed?**: `boolean`

Defined in: [packages/prismarine/src/network/encodePacketBatch.ts:11](https://github.com/JSPrismarine/JSPrismarine/blob/e928b08f56694af6821b757ce6b196faebd3199c/packages/prismarine/src/network/encodePacketBatch.ts#L11)

Whether the negotiated batch format includes a compression prefix.

###### Inherited from

[`PacketBatchOptions`](https://jsprismarine.dev/api/@jsprismarine/prismarine/network/encodePacketBatch/index.md#packetbatchoptions).[`compressed`](https://jsprismarine.dev/api/@jsprismarine/prismarine/network/encodePacketBatch/index.md#compressed)

##### compressionAlgorithm?

> `optional` **compressionAlgorithm?**: [`PacketCompressionAlgorithm`](https://jsprismarine.dev/api/@jsprismarine/minecraft/index.md#packetcompressionalgorithm)

Defined in: [packages/prismarine/src/network/encodePacketBatch.ts:13](https://github.com/JSPrismarine/JSPrismarine/blob/e928b08f56694af6821b757ce6b196faebd3199c/packages/prismarine/src/network/encodePacketBatch.ts#L13)

Algorithm advertised by this connection in `NetworkSettings`.

###### Inherited from

[`PacketBatchOptions`](https://jsprismarine.dev/api/@jsprismarine/prismarine/network/encodePacketBatch/index.md#packetbatchoptions).[`compressionAlgorithm`](https://jsprismarine.dev/api/@jsprismarine/prismarine/network/encodePacketBatch/index.md#compressionalgorithm)

##### compressionLevel?

> `optional` **compressionLevel?**: `number`

Defined in: [packages/prismarine/src/network/encodePacketBatch.ts:17](https://github.com/JSPrismarine/JSPrismarine/blob/e928b08f56694af6821b757ce6b196faebd3199c/packages/prismarine/src/network/encodePacketBatch.ts#L17)

zlib level for this batch; omitted to use Protocol's default.

###### Inherited from

[`PacketBatchOptions`](https://jsprismarine.dev/api/@jsprismarine/prismarine/network/encodePacketBatch/index.md#packetbatchoptions).[`compressionLevel`](https://jsprismarine.dev/api/@jsprismarine/prismarine/network/encodePacketBatch/index.md#compressionlevel)

##### compressionThreshold?

> `optional` **compressionThreshold?**: `number`

Defined in: [packages/prismarine/src/network/encodePacketBatch.ts:15](https://github.com/JSPrismarine/JSPrismarine/blob/e928b08f56694af6821b757ce6b196faebd3199c/packages/prismarine/src/network/encodePacketBatch.ts#L15)

Smallest batch payload size to compress; zero leaves every batch uncompressed.

###### Inherited from

[`PacketBatchOptions`](https://jsprismarine.dev/api/@jsprismarine/prismarine/network/encodePacketBatch/index.md#packetbatchoptions).[`compressionThreshold`](https://jsprismarine.dev/api/@jsprismarine/prismarine/network/encodePacketBatch/index.md#compressionthreshold)

##### direct?

> `optional` **direct?**: `boolean`

Defined in: [packages/prismarine/src/network/MinecraftSession.ts:882](https://github.com/JSPrismarine/JSPrismarine/blob/e928b08f56694af6821b757ce6b196faebd3199c/packages/prismarine/src/network/MinecraftSession.ts#L882)

Whether RakNet should send the framed bytes in their own datagram.

##### fragmentCache?

> `optional` **fragmentCache?**: [`FullFlushFragmentCache`](https://jsprismarine.dev/api/@jsprismarine/prismarine/network/encodePacketBatch/classes/FullFlushFragmentCache.md)

Defined in: [packages/prismarine/src/network/encodePacketBatch.ts:23](https://github.com/JSPrismarine/JSPrismarine/blob/e928b08f56694af6821b757ce6b196faebd3199c/packages/prismarine/src/network/encodePacketBatch.ts#L23)

Cache shared fragments for the lifetime appropriate to the caller.

###### Inherited from

[`PacketBatchOptions`](https://jsprismarine.dev/api/@jsprismarine/prismarine/network/encodePacketBatch/index.md#packetbatchoptions).[`fragmentCache`](https://jsprismarine.dev/api/@jsprismarine/prismarine/network/encodePacketBatch/index.md#fragmentcache)

##### fragmentCodec?

> `optional` **fragmentCodec?**: [`ProtocolCodec`](https://jsprismarine.dev/api/@jsprismarine/protocol/index.md#protocolcodec)

Defined in: [packages/prismarine/src/network/encodePacketBatch.ts:21](https://github.com/JSPrismarine/JSPrismarine/blob/e928b08f56694af6821b757ce6b196faebd3199c/packages/prismarine/src/network/encodePacketBatch.ts#L21)

The protocol layout owner used as part of each fragment cache key.

###### Inherited from

[`PacketBatchOptions`](https://jsprismarine.dev/api/@jsprismarine/prismarine/network/encodePacketBatch/index.md#packetbatchoptions).[`fragmentCodec`](https://jsprismarine.dev/api/@jsprismarine/prismarine/network/encodePacketBatch/index.md#fragmentcodec)

##### fragmentKeyDiscriminators?

> `optional` **fragmentKeyDiscriminators?**: readonly `string`[]

Defined in: [packages/prismarine/src/network/encodePacketBatch.ts:27](https://github.com/JSPrismarine/JSPrismarine/blob/e928b08f56694af6821b757ce6b196faebd3199c/packages/prismarine/src/network/encodePacketBatch.ts#L27)

Extra packet identity when a stable key alone does not identify the full packet.

###### Inherited from

[`PacketBatchOptions`](https://jsprismarine.dev/api/@jsprismarine/prismarine/network/encodePacketBatch/index.md#packetbatchoptions).[`fragmentKeyDiscriminators`](https://jsprismarine.dev/api/@jsprismarine/prismarine/network/encodePacketBatch/index.md#fragmentkeydiscriminators)

##### fragmentKeys?

> `optional` **fragmentKeys?**: readonly `Buffer`\<`ArrayBufferLike`\>[]

Defined in: [packages/prismarine/src/network/encodePacketBatch.ts:25](https://github.com/JSPrismarine/JSPrismarine/blob/e928b08f56694af6821b757ce6b196faebd3199c/packages/prismarine/src/network/encodePacketBatch.ts#L25)

Optional stable per-packet cache keys, used by serialized chunk payloads.

###### Inherited from

[`PacketBatchOptions`](https://jsprismarine.dev/api/@jsprismarine/prismarine/network/encodePacketBatch/index.md#packetbatchoptions).[`fragmentKeys`](https://jsprismarine.dev/api/@jsprismarine/prismarine/network/encodePacketBatch/index.md#fragmentkeys)

##### fullFlushFragments?

> `optional` **fullFlushFragments?**: `boolean`

Defined in: [packages/prismarine/src/network/encodePacketBatch.ts:19](https://github.com/JSPrismarine/JSPrismarine/blob/e928b08f56694af6821b757ce6b196faebd3199c/packages/prismarine/src/network/encodePacketBatch.ts#L19)

Use independently compressed, reusable packet fragments for this batch.

###### Inherited from

[`PacketBatchOptions`](https://jsprismarine.dev/api/@jsprismarine/prismarine/network/encodePacketBatch/index.md#packetbatchoptions).[`fullFlushFragments`](https://jsprismarine.dev/api/@jsprismarine/prismarine/network/encodePacketBatch/index.md#fullflushfragments)

## Functions

### broadcastSharedBatches()

> **broadcastSharedBatches**(`sessions`, `packets`, `compressionLevel`, `onError`, `compressionThreshold?`, `fragmentOptions?`): `Promise`\<`void`\>

Defined in: [packages/prismarine/src/network/MinecraftSession.ts:815](https://github.com/JSPrismarine/JSPrismarine/blob/e928b08f56694af6821b757ce6b196faebd3199c/packages/prismarine/src/network/MinecraftSession.ts#L815)

Fans one packet out as shared batches, compressed once per protocol codec.

The shared-batch win - one deflate serving every recipient - used to be one global batch,
which handed a 2225 session the 2193 layout for any packet whose wire changed between
them. Sessions are grouped by codec and each group gets bytes encoded under its own: the
single compression survives within a group, and a mixed-version audience each receives its
negotiated layout. A group whose encode fails is logged and skipped; the others still send.

#### Parameters

##### sessions

readonly [`MinecraftSession`](https://jsprismarine.dev/api/@jsprismarine/prismarine/network/MinecraftSession/classes/MinecraftSession.md)[]

Who receives it.

##### packets

[`NetworkPacket`](https://jsprismarine.dev/api/@jsprismarine/protocol/classes/NetworkPacket.md)\<`unknown`\> \| readonly [`NetworkPacket`](https://jsprismarine.dev/api/@jsprismarine/protocol/classes/NetworkPacket.md)\<`unknown`\>[]

The packets, as the caller built them.

##### compressionLevel

`number`

The batch compression level.

##### onError

(`error`) => `void`

Where an encode failure goes.

##### compressionThreshold?

`number`

Optional override for the minimum batch-body size to compress.

##### fragmentOptions?

`Pick`\<[`PacketBatchOptions`](https://jsprismarine.dev/api/@jsprismarine/prismarine/network/encodePacketBatch/index.md#packetbatchoptions), `"fullFlushFragments"` \| `"fragmentCache"`\> = `{}`

#### Returns

`Promise`\<`void`\>

***

### debugPacketNames()

> **debugPacketNames**(`value`): `ReadonlySet`\<`string`\>

Defined in: [packages/prismarine/src/network/MinecraftSession.ts:37](https://github.com/JSPrismarine/JSPrismarine/blob/e928b08f56694af6821b757ce6b196faebd3199c/packages/prismarine/src/network/MinecraftSession.ts#L37)

The packet class names a debugging variable lists, comma-separated.

Two variables use this. `JSP_DEBUG_DROP_PACKETS` names clientbound packets that never
reach the wire, which bisects a join stream one packet type at a time against a client
that leaves without saying why. `JSP_DEBUG_DUMP_PACKETS` names packets whose encoded bytes
are written to a file, one per packet, so what a real client was given can be decoded
offline. Both leave a warn line per packet. Read when a session is created, from the
environment the server was started with.

#### Parameters

##### value

`string` \| `undefined`

The variable's value.

#### Returns

`ReadonlySet`\<`string`\>

The names listed, empty when the variable is unset.
