API reference / @jsprismarine/nethernet / Connection
Class: Connection
Defined in: packages/nethernet/src/Connection.ts:129
One NetherNet connection: a peer connection with its reliable and unreliable channels. Messages go out on the reliable channel, segmented, and are queued until it opens. Messages arrive on either channel: whole on the unreliable one, which carries no segments.
Events: message (Buffer), close (reason).
Extends
EventEmitter
Constructors
Constructor
new Connection(
id,peer,options?):Connection
Defined in: packages/nethernet/src/Connection.ts:146
Parameters
id
bigint
The connection ID the client picked.
peer
The peer connection underneath.
options?
ConnectionOptions = {}
How much the connection accepts and buffers.
Returns
Connection
Overrides
EventEmitter.constructor
Properties
id
readonlyid:bigint
Defined in: packages/nethernet/src/Connection.ts:147
The connection ID the client picked.
identityProof
identityProof:
IdentityProof|undefined
Defined in: packages/nethernet/src/Connection.ts:134
What the peer's description offered as proof of its key, when it carried an identity.
peer
readonlypeer:DriverPeer
Defined in: packages/nethernet/src/Connection.ts:148
The peer connection underneath.
reliable
reliable:
DriverChannel|undefined
Defined in: packages/nethernet/src/Connection.ts:130
unreliable
unreliable:
DriverChannel|undefined
Defined in: packages/nethernet/src/Connection.ts:131
Accessors
closed
Get Signature
get closed():
boolean
Defined in: packages/nethernet/src/Connection.ts:175
Whether the connection has closed; nothing more is sent or received.
Returns
boolean
Methods
close()
close(
reason?):void
Defined in: packages/nethernet/src/Connection.ts:261
Closes the channels and the peer connection.
Parameters
reason?
string = 'closed'
Why, which close carries.
Returns
void
peerEnded()
peerEnded(
reason?):void
Defined in: packages/nethernet/src/Connection.ts:246
Ends the connection because the peer connection went down. The reliable channel's close is ordered behind the data on it, and the peer connection's state is not: it can be reported before the channel's last messages. So an open reliable channel is left to close by itself, which delivers what came before; the fallback only covers a channel that never reports it.
Parameters
reason?
string = 'disconnected'
Why, which close carries.
Returns
void
provesKey()
provesKey(
publicKey):Promise<boolean>
Defined in: packages/nethernet/src/Connection.ts:162
Whether the peer proved it holds a key: its description's identity signed the fingerprint of the certificate this connection's DTLS handshake checked, with that key.
Parameters
publicKey
string
The key, as base64 DER.
Returns
Promise<boolean>
False when it did not, or sent no identity.
send()
send(
message):number
Defined in: packages/nethernet/src/Connection.ts:228
Sends one message, or queues it until the reliable channel opens.
Parameters
message
Uint8Array
The message.
Returns
number
The bytes sent or queued.
Throws
When the connection has closed.
Throws
When the message is empty or too long to segment.
setReliable()
setReliable(
channel):void
Defined in: packages/nethernet/src/Connection.ts:183
Takes the reliable channel, whose messages are the connection's.
Parameters
channel
The ReliableDataChannel.
Returns
void
setUnreliable()
setUnreliable(
channel):void
Defined in: packages/nethernet/src/Connection.ts:206
Takes the unreliable channel. Nothing is sent on it, and a message the peer sends there is delivered like any other: it is whole, since the channel carries no segments.
Parameters
channel
The UnreliableDataChannel.
Returns
void
useRemoteDescription()
useRemoteDescription(
description):void
Defined in: packages/nethernet/src/Connection.ts:170
Sizes outgoing segments to what the peer's description allows.
Parameters
description
string
The remote SDP description.
Returns
void