API reference / @jsprismarine/nethernet / NetherNetServer
Class: NetherNetServer
Defined in: packages/nethernet/src/NetherNetServer.ts:64
NetherNet's server side: turns each client's offer into an answer over a WebRTC driver, and keeps the connection it negotiates. Offers arrive through NetherNetServer.handleOffer, from HTTP signaling, or from LAN discovery on UDP 7551 once NetherNetServer.listen binds it.
Events: openConnection (Connection), once both channels are open and the peer is connected; closeConnection (connection ID, reason); encapsulated (message, connection ID).
Extends
EventEmitter
Constructors
Constructor
new NetherNetServer(
options):NetherNetServer
Defined in: packages/nethernet/src/NetherNetServer.ts:79
Parameters
options
The driver and how to build each peer.
Returns
NetherNetServer
Overrides
EventEmitter.constructor
Properties
connections
readonlyconnections:Map<bigint,Connection>
Defined in: packages/nethernet/src/NetherNetServer.ts:67
Every connection by the ID its client picked, opened or still negotiating.
networkId
readonlynetworkId:bigint
Defined in: packages/nethernet/src/NetherNetServer.ts:65
Methods
close()
close(
reason?):void
Defined in: packages/nethernet/src/NetherNetServer.ts:238
Closes every connection and LAN discovery.
Parameters
reason?
string = 'Server closed'
Why, which each connection's closeConnection carries.
Returns
void
handleCandidate()
handleCandidate(
signal,respond?):void
Defined in: packages/nethernet/src/NetherNetServer.ts:189
Adds a candidate a client trickled after its offer.
Parameters
signal
The CANDIDATEADD.
respond?
Sends a signal back to that client.
Returns
void
handleOffer()
handleOffer(
signal,respond,proof?):Promise<void>
Defined in: packages/nethernet/src/NetherNetServer.ts:93
Negotiates a peer for a client's offer and sends the answer, with every candidate, through respond. An offer for a connection ID already in use is ignored.
Parameters
signal
The CONNECTREQUEST.
respond
Sends a signal back to that client.
proof?
What the offer's a=identity proves, when the caller took it out of the offer already; read from the offer when absent.
Returns
Promise<void>
listen()
listen():
Promise<void>
Defined in: packages/nethernet/src/NetherNetServer.ts:220
Binds UDP 7551 and answers LAN discovery: requests with the advertisement, and signals addressed to this server's network ID.
Returns
Promise<void>
Throws
When the port cannot be bound.
setAdvertisement()
setAdvertisement(
advertisement):void
Defined in: packages/nethernet/src/NetherNetServer.ts:211
Sets what a LAN discovery request is answered with.
Parameters
advertisement
Buffer
The bytes encodeLanAdvertisement makes.
Returns
void