npm install giovannicalo/node-wrtc-ws-api-server
Not yet published to NPM. This will install it from GitHub.
const Server = require("wrtc-ws-api-server");
new Server(8080);
Starts a WebSocket server listening on port
.
Options are:
authenticate?(data: JsonSerializable): boolean | Promise<boolean>
: a function to authenticate clients, which must returntrue
if valid andfalse
if not, defaults toundefined
.heartbeatGracePeriod?: number
: how long to keep unresponsive clients alive, in milliseconds, should be greater thanheartbeatInterval
, defaults to15000
.heartbeatInterval?: number
: how often to sendping
events to clients, in milliseconds, should be less thanheartbeatGracePeriod
, defaults to5000
.log?(level: "error" | "info" | "warning", message: string): void
: a logging function that will be called when certain events occur, defaults toundefined
.socketOptions?: WebSocket.ServerOptions
: custom options to pass to theWebSocketServer
constructor, exceptport
.
The authenticate
function passed to the Server
constructor.
A Map
of Client
objects, one for each client connected to the server.
Shuts down the server.
The value of heartbeatGracePeriod
, passed to the Server
constructor.
The value of heartbeatInterval
, passed to the Server
constructor.
The log
function passed to the Server
constructor.
The WebSocketServer
instance used by the Server
.
Each of the clients connected to the Server
.
Clients cannot be created manually, but they can be accessed via Server.clients
.
The Client
's IP address.
Assigns a client
Client
to the current Client
. Only makes sense for worker
Client
s. It should not be used manually.
Forces the Client
to choose a worker
Client
. Only makes sense for client
Client
s. It should not be used manually.
A Map
of client
Client
s assigned to the current Client
. Only makes sense for worker
Client
s.
Closes the Client
's connection.
The time at which the Client
connected.
The Client
's ID.
The time at which the Client
last sent a message (pong
or otherwise).
The Client
's latency, in milliseconds, sampled every heartbeatInterval
milliseconds using ping
events.
Removes a client
Client
from the current Client
. Only makes sense for worker
Client
s. It should not be used manually.
Removes the worker
Client
assigned to the current Client
. Only makes sense for client
Client
s. It should not be used manually.
The Client
's role.
Sends a message
to the client.
The worker
Client
used by the current Client
. Only makes sense for client
Client
s.