API reference / @jsprismarine/nethernet / NetherNetClient
Class: NetherNetClient
Defined in: packages/nethernet/src/NetherNetClient.ts:40
NetherNet's client side: opens a peer with the reliable and unreliable channels, sends the offer with every candidate through the given sender, and connects once the answer arrives through NetherNetClient.handleSignal.
Events: connected (Connection), encapsulated (message), disconnect (reason).
Extends
EventEmitter
Constructors
Constructor
new NetherNetClient(
options):NetherNetClient
Defined in: packages/nethernet/src/NetherNetClient.ts:52
Parameters
options
The driver, the signal sender and the IDs.
Returns
NetherNetClient
Overrides
EventEmitter.constructor
Properties
connectionId
readonlyconnectionId:bigint
Defined in: packages/nethernet/src/NetherNetClient.ts:42
networkId
readonlynetworkId:bigint
Defined in: packages/nethernet/src/NetherNetClient.ts:41
serverNetworkId
readonlyserverNetworkId:bigint
Defined in: packages/nethernet/src/NetherNetClient.ts:43
Accessors
openConnection
Get Signature
get openConnection():
Connection|undefined
Defined in: packages/nethernet/src/NetherNetClient.ts:136
The connection, once it opened.
Returns
Connection | undefined
Methods
close()
close(
reason?):void
Defined in: packages/nethernet/src/NetherNetClient.ts:144
Hangs up.
Parameters
reason?
string = 'client disconnect'
Why, which disconnect carries.
Returns
void
connect()
connect():
Promise<void>
Defined in: packages/nethernet/src/NetherNetClient.ts:65
Starts the join: builds the peer and its two channels, waits for every candidate, and sends the offer. The answer has to come back through NetherNetClient.handleSignal.
Returns
Promise<void>
Resolves once the offer is sent.
Throws
When the client was used before or closed, or the peer cannot be built.
handleSignal()
handleSignal(
signal):void
Defined in: packages/nethernet/src/NetherNetClient.ts:99
Takes a signal from the server: the answer, a trickled candidate, or an error.
Parameters
signal
The signal; one for another connection is ignored.
Returns
void
send()
send(
message):void
Defined in: packages/nethernet/src/NetherNetClient.ts:130
Sends one message.
Parameters
message
Uint8Array
The message.
Returns
void
Throws
When the connection is not open.