Some checks failed
Build and Deploy / build-windows (CLANG64) (push) Has been cancelled
Build and Deploy / package-dist (push) Has been cancelled
Build and Deploy / deploy-itch (push) Has been cancelled
Build and Deploy / deploy-gitea (push) Has been cancelled
Build and Deploy / build-linux (push) Has been cancelled
152 lines
4.9 KiB
JavaScript
152 lines
4.9 KiB
JavaScript
// enet.js doc (updated)
|
|
var enet = this;
|
|
|
|
//------------------------------------------------
|
|
// Top-level ENet functions
|
|
//------------------------------------------------
|
|
|
|
enet.initialize[prosperon.DOC] = `
|
|
Initialize the ENet library. Must be called before using any ENet functionality.
|
|
Throws an error if initialization fails.
|
|
|
|
:return: None
|
|
`;
|
|
|
|
enet.deinitialize[prosperon.DOC] = `
|
|
Deinitialize the ENet library, cleaning up all resources. Call this when you no longer
|
|
need any ENet functionality.
|
|
|
|
:return: None
|
|
`;
|
|
|
|
enet.create_host[prosperon.DOC] = `
|
|
Create an ENet host for either a client-like unbound host or a server bound to a specific
|
|
address and port:
|
|
|
|
- If no argument is provided, creates an unbound "client-like" host with default settings
|
|
(maximum 32 peers, 2 channels, unlimited bandwidth).
|
|
- If you pass an "ip:port" string (e.g. "127.0.0.1:7777"), it creates a server bound to
|
|
that address. The server supports up to 32 peers, 2 channels, and unlimited bandwidth.
|
|
|
|
Throws an error if host creation fails for any reason.
|
|
|
|
:param address: (optional) A string in 'ip:port' format to bind the host (server), or
|
|
omit to create an unbound client-like host.
|
|
:return: An ENetHost object.
|
|
`;
|
|
|
|
//------------------------------------------------
|
|
// ENetHost methods
|
|
//------------------------------------------------
|
|
|
|
var enet_host = prosperon.c_types.enet_host;
|
|
|
|
enet_host.service[prosperon.DOC] = `
|
|
Poll for and process any available network events (connect, receive, disconnect, or none)
|
|
from this host, calling the provided callback for each event. This function loops until
|
|
no more events are available in the current timeframe.
|
|
|
|
Event object properties:
|
|
- type: String, one of "connect", "receive", "disconnect", or "none".
|
|
- peer: (present if type = "connect") The ENetPeer object for the new connection.
|
|
- channelID: (present if type = "receive") The channel on which the data was received.
|
|
- data: (present if type = "receive") The received data as a *plain JavaScript object*.
|
|
If the JSON parse fails or the data isn't an object, a JavaScript error is thrown.
|
|
|
|
:param callback: A function called once for each available event, receiving an event
|
|
object as its single argument.
|
|
:param timeout: (optional) Timeout in milliseconds. Defaults to 0 (non-blocking).
|
|
:return: None
|
|
`;
|
|
|
|
enet_host.connect[prosperon.DOC] = `
|
|
Initiate a connection from this host to a remote server. Throws an error if the
|
|
connection cannot be started.
|
|
|
|
:param host: The hostname or IP address of the remote server (e.g. "example.com" or "127.0.0.1").
|
|
:param port: The port number to connect to.
|
|
:return: An ENetPeer object representing the connection.
|
|
`;
|
|
|
|
enet_host.flush[prosperon.DOC] = `
|
|
Flush all pending outgoing packets for this host immediately.
|
|
|
|
:return: None
|
|
`;
|
|
|
|
enet_host.broadcast[prosperon.DOC] = `
|
|
Broadcast a JavaScript object to all connected peers on channel 0. The object is
|
|
serialized to JSON, and the packet is sent reliably. Throws an error if serialization fails.
|
|
|
|
:param data: A JavaScript object to broadcast to all peers.
|
|
:return: None
|
|
`;
|
|
|
|
//------------------------------------------------
|
|
// ENetPeer methods
|
|
//------------------------------------------------
|
|
|
|
var enet_peer = prosperon.c_types.enet_peer;
|
|
|
|
enet_peer.send[prosperon.DOC] = `
|
|
Send a JavaScript object to this peer on channel 0. The object is serialized to JSON and
|
|
sent reliably. Throws an error if serialization fails.
|
|
|
|
:param data: A JavaScript object to send.
|
|
:return: None
|
|
`;
|
|
|
|
enet_peer.disconnect[prosperon.DOC] = `
|
|
Request a graceful disconnection from this peer. The connection will close after
|
|
pending data is sent.
|
|
|
|
:return: None
|
|
`;
|
|
|
|
enet_peer.disconnect_now[prosperon.DOC] = `
|
|
Immediately terminate the connection to this peer, discarding any pending data.
|
|
|
|
:return: None
|
|
`;
|
|
|
|
enet_peer.disconnect_later[prosperon.DOC] = `
|
|
Request a disconnection from this peer after all queued packets are sent.
|
|
|
|
:return: None
|
|
`;
|
|
|
|
enet_peer.reset[prosperon.DOC] = `
|
|
Reset this peer's connection, immediately dropping it and clearing its internal state.
|
|
|
|
:return: None
|
|
`;
|
|
|
|
enet_peer.ping[prosperon.DOC] = `
|
|
Send a ping request to this peer to measure latency.
|
|
|
|
:return: None
|
|
`;
|
|
|
|
enet_peer.throttle_configure[prosperon.DOC] = `
|
|
Configure the throttling behavior for this peer, controlling how ENet adjusts its sending
|
|
rate based on packet loss or congestion.
|
|
|
|
:param interval: The interval (ms) between throttle adjustments.
|
|
:param acceleration: The factor to increase sending speed when conditions improve.
|
|
:param deceleration: The factor to decrease sending speed when conditions worsen.
|
|
:return: None
|
|
`;
|
|
|
|
enet_peer.timeout[prosperon.DOC] = `
|
|
Set timeout parameters for this peer, determining how long ENet waits before considering
|
|
the connection lost.
|
|
|
|
:param timeout_limit: The total time (ms) before the peer is disconnected.
|
|
:param timeout_min: The minimum timeout (ms) used for each timeout attempt.
|
|
:param timeout_max: The maximum timeout (ms) used for each timeout attempt.
|
|
:return: None
|
|
`;
|
|
|
|
// Return the enet object.
|
|
return enet;
|