Options
All
  • Public
  • Public/Protected
  • All
Menu

Class WebSocketNetworkServer

Server for @collabs/ws-client's WebSocketNetwork.

You can start the server by calling the constructor in a Node.js program or by using the collabs-ws-server command.

This server is only minimally configurable; for advanced uses, consider copying and modifying its source code directly.

However, you can configure:

  • Document storage (constructor's docStore argument).
  • Client/docID authentication (constructor's authenticate argument).
  • Error handling/logging, by listening on your WebSocketServer's "error" and "connection" events (registering a per-WebSocket error handler in the latter).

Hierarchy

  • WebSocketNetworkServer

Index

Constructors

Properties

Constructors

  • new WebSocketNetworkServer(wss: WebSocketServer, docStore?: ServerDocStore, authenticate?: ((ws: WebSocket, docID: string) => Promise<boolean>), options?: { heartbeatIntervalMS?: number }): WebSocketNetworkServer
  • Constructs a WebSocketNetworkServer.

    Parameters

    • wss: WebSocketServer

      The WebSocketServer (package ws) to run on top of.

    • docStore: ServerDocStore = ...

      ServerDocStore, for persisting document states. Default: InMemoryDocStore, for demonstration purposes.

    • authenticate: ((ws: WebSocket, docID: string) => Promise<boolean>) = ...

      Callback that returns whether a given client (ws) is allowed to read and write docID. Default: Always true (all docs are public), for demonstration purposes.

        • (ws: WebSocket, docID: string): Promise<boolean>
        • Parameters

          • ws: WebSocket
          • docID: string

          Returns Promise<boolean>

    • options: { heartbeatIntervalMS?: number } = {}
      • Optional heartbeatIntervalMS?: number

        How often to send WebSocket pings, in ms. Set to 0 to disable pings.

    Returns WebSocketNetworkServer

Properties

docStore: ServerDocStore = ...
wss: WebSocketServer

Generated using TypeDoc