Skip to content

API reference / @jsprismarine/prismarine / network/transport/Transport

network/transport/Transport ​

Interfaces ​

Transport ​

Defined in: packages/prismarine/src/network/transport/Transport.ts:90

A listening transport: accepts connections and surfaces what arrives on them.

Subscriptions rather than an event-map emitter, so each listener keeps its own signature. Listeners of one subscription run in order, each awaited before the next. A transport delivers one connection's connect, frames and disconnect in order, none overtaking another.

Type Parameters ​

C ​

C extends TransportConnection = TransportConnection

The transport's own connection type, for a consumer that needs more than the TransportConnection contract.

Properties ​

connectionIds? ​

readonly optional connectionIds?: ConnectionIds

Defined in: packages/prismarine/src/network/transport/Transport.ts:112

The allocator the transport numbers its connections from. A transport handed to the server in place of its own sockets gives it so the Java Edition listener, which java-enabled starts beside it, numbers its connections from the same one.

Methods ​

close() ​

close(): void

Defined in: packages/prismarine/src/network/transport/Transport.ts:106

Stops listening and drops every connection.

Returns ​

void

onConnect() ​

onConnect(listener): void

Defined in: packages/prismarine/src/network/transport/Transport.ts:92

Calls the listener once per accepted connection.

Parameters ​
listener ​

(connection) => void | Promise<void>

Returns ​

void

onDisconnect() ​

onDisconnect(listener): void

Defined in: packages/prismarine/src/network/transport/Transport.ts:97

Calls the listener when the transport forgets a connection, however it ended. It also runs for a connection whose connect never reached Transport.onConnect listeners.

Parameters ​
listener ​

(id, address, reason) => void | Promise<void>

Returns ​

void

onFrame() ​

onFrame(listener): void

Defined in: packages/prismarine/src/network/transport/Transport.ts:99

Calls the listener with each frame a connected client sent, and the connection's ID.

Parameters ​
listener ​

(payload, id) => void | Promise<void>

Returns ​

void

onRaw()? ​

optional onRaw(listener): void

Defined in: packages/prismarine/src/network/transport/Transport.ts:104

Calls the listener with datagrams from hosts that are not connected, such as queries. Only a transport that shares its socket with such traffic implements it.

Parameters ​
listener ​

(payload, address) => void | Promise<void>

Returns ​

void


TransportCapabilities ​

Defined in: packages/prismarine/src/network/transport/Transport.ts:14

What a transport does for the session layer, so the layers above can decide what they still have to do themselves: batch, compress, encrypt, or re-order.

Properties ​

encrypted ​

readonly encrypted: boolean

Defined in: packages/prismarine/src/network/transport/Transport.ts:16

Whether the transport encrypts frames itself, as a WebRTC data channel does.

maxFrameSize ​

readonly maxFrameSize: number

Defined in: packages/prismarine/src/network/transport/Transport.ts:20

The most payload bytes one TransportConnection.sendFrame call may carry.

reliableOrdered ​

readonly reliableOrdered: boolean

Defined in: packages/prismarine/src/network/transport/Transport.ts:18

Whether frames arrive exactly once and in the order they were framed.


TransportConnection ​

Defined in: packages/prismarine/src/network/transport/Transport.ts:32

One client's duplex byte-frame channel. It knows nothing about the packets it carries: a frame is an opaque payload, already batched, compressed, and encrypted by the layers above as TransportConnection.capabilities requires.

A Bedrock frame is a batch in the form RakNet carries it, starting with the 0xFE batch id. A transport whose wire leaves that byte out, as NetherNet's does, adds it to what it receives and strips it from what it sends, so the batch and encryption codecs above see one format.

Properties ​

address ​

readonly address: InetAddress

Defined in: packages/prismarine/src/network/transport/Transport.ts:43

Where the client connected from: an IP address and port, whichever transport carried it. InetAddress is the value type for that, not a RakNet dependency of the seam. Several connections may share one, and an address may come back on a later connection.

capabilities ​

readonly capabilities: TransportCapabilities

Defined in: packages/prismarine/src/network/transport/Transport.ts:45

What this connection's transport does on its own - see TransportCapabilities.

id ​

readonly id: number

Defined in: packages/prismarine/src/network/transport/Transport.ts:37

The server's ID for this connection, drawn from the allocator every transport of the server shares, so no two live or past connections have the same one.

transport ​

readonly transport: TransportName

Defined in: packages/prismarine/src/network/transport/Transport.ts:47

The transport this connection arrived over.

Methods ​

close() ​

close(reason?): void | Promise<void>

Defined in: packages/prismarine/src/network/transport/Transport.ts:63

Hangs up on the client, after what was already sent has had its chance to arrive.

RakNet holds the session open until the client acknowledges its last datagrams, so it hangs up at once. A transport that would drop frames still in flight waits for them first and returns a promise that settles once it has hung up, so a caller that sent a goodbye can wait for it to arrive before the process exits.

Parameters ​
reason? ​

string

Recorded as the disconnect reason the transport reports back.

Returns ​

void | Promise<void>

provesKey()? ​

optional provesKey(identityPublicKey): Promise<boolean | undefined>

Defined in: packages/prismarine/src/network/transport/Transport.ts:73

Whether the client proved, while connecting, that it holds a key. Only a transport that encrypts the wire itself has this: there the session leaves Minecraft's encryption off, and with it the handshake that proves a login's identity key, so the transport's own handshake has to prove it, or a login somebody recorded could be sent again by anybody.

Parameters ​
identityPublicKey ​

string

The key a login names, as base64 DER.

Returns ​

Promise<boolean | undefined>

False when the client proved another key or none. Undefined when the way this client connected gives it no means to prove a key, as NetherNet's LAN discovery does not.

roundTripTime()? ​

optional roundTripTime(): number | undefined

Defined in: packages/prismarine/src/network/transport/Transport.ts:78

The round trip time to the client in milliseconds, as the transport measures it, or undefined before its first sample. A transport that measures none leaves it out.

Returns ​

number | undefined

sendFrame() ​

sendFrame(payload, immediate?): void

Defined in: packages/prismarine/src/network/transport/Transport.ts:53

Queues one frame for the client.

Parameters ​
payload ​

Buffer

The frame's bytes, ready for the wire.

immediate? ​

boolean

Send in a datagram of its own instead of the next scheduled flush.

Returns ​

void

Type Aliases ​

TransportName ​

TransportName = typeof TransportNames[keyof typeof TransportNames]

Defined in: packages/prismarine/src/network/transport/Transport.ts:8

One of TransportNames: RakNet, NetherNet, or Java for Java Edition over TCP.

Variables ​

TransportNames ​

const TransportNames: object

Defined in: packages/prismarine/src/network/transport/Transport.ts:5

The display name of each transport a connection can arrive over, keyed by a lowercase id.

Type Declaration ​

java ​

readonly java: "Java" = 'Java'

nethernet ​

readonly nethernet: "NetherNet" = 'NetherNet'

raknet ​

readonly raknet: "RakNet" = 'RakNet'