0.12.0 • Published 3 years ago
ataraxia-ws-server v0.12.0
ataraxia-ws-server
Server that allows clients to connect to an Ataraxia network via websockets. This implementation uses ws to serve the websockets. Clients may use a websocket client to connect to the network.
Installation
npm install ataraxia-ws-server
Usage
import { Network, AnonymousAuth } from 'ataraxia';
import { WebSocketServerTransport } from 'ataraxia-ws-server';
// Setup a network with a WebSocket server
const net = new Network({
name: 'name-of-your-app-or-network',
transport: [
new WebSocketServerTransport({
port: 7000,
authentication: [
new AnonymousAuth()
]
})
]
});
await net.join();
API
new WebSocketServerTransport(options)
Create a new transport using the given options.
options
host?: string
, hostname where to bind the server.port?: number
, port where to bind the server.authentication: AuthProvider[]
, array of authentication providers.backlog?: number
, maximum length of the queue of pending connections.server?: http.Server | https.Server
, pre-created Node.js HTTP/S server.verifyClient?: function
, a function which can be used to validate incoming connections. See WS docs for details.handleProtocols?: function
, a function which can be used to handle the WebSocket subprotocols. See WS docs for details.noServer?: boolean
, enable no server mode.clientTracking?: boolean
, specifies whether or not to track clients.perMessageDeflate: boolean|object
, enable/disable permessage-deflate. See WS docs for details.maxPayload: number
, the maximum allowed message size in bytes.
WebSocketServerTransport
extends the options of WebSocket.Server. Detailed description of many of these
options can be find in its documentation.