The properties with which to create the Server.

interface Props {
    acceptNewUsers?: boolean;
    authTimeoutMilliseconds?: number;
    http?: {
        path?: string;
        queryParams?: ExpectedQueryParams;
        server?: Server<typeof IncomingMessage, typeof ServerResponse>;
    };
    isValidUsername?: ((username) => boolean);
    logger?: false | Logger;
    pingIntervalMilliseconds?: number;
}

Properties

acceptNewUsers?: boolean

Whether the server should accept new users. If set to false, only users joined via server.join() can join the server.

Default

When not provided, the server will accept new users.
authTimeoutMilliseconds?: number

The timeout in milliseconds that the server should wait for the authentication process to complete. If the authentication process does not complete within this time, the connection will be rejected. If a value smaller than 1 is provided, 1 will be used.

Default

When not provided, the server will wait a maximum of 10_000 milliseconds (10 seconds) for the authentication process to complete.
http?: {
    path?: string;
    queryParams?: ExpectedQueryParams;
    server?: Server<typeof IncomingMessage, typeof ServerResponse>;
}

The http configuration that the Server should use.

Type declaration

  • Optional path?: string

    The http path the Server should use for the websocket server.

    Default

    When not provided, the websocket server will use the root path.
    
  • Optional queryParams?: ExpectedQueryParams

    Query string parameters that all connections must provide in their connection url.

    For example: when it is set to { krmx: 'my-server-1-0-2' } a client should connect with 'ws:127.0.0.1:80/example?krmx=my-server-1-0-2'

  • Optional server?: Server<typeof IncomingMessage, typeof ServerResponse>

    The http server that the Server should use.

    Default

    When not provided, a new http server will be created.
    

Default

When not provided, a new http server will be created and the WebSocket server will be on the root path.
isValidUsername?: ((username) => boolean)

A predicate that determines what the server should consider to be a valid username.

Type declaration

    • (username): boolean
    • A predicate that determines what the server should consider to be a valid username.

      Parameters

      • username: string

      Returns boolean

      Default

      When not provided, the server will validate usernames using the username regex (exported by Krmx as usernameRegex).
      

Default

When not provided, the server will validate usernames using the username regex (exported by Krmx as usernameRegex).
logger?: false | Logger

The logger that the Server should use.

Default

When not provided, it will log (non debug) to the standard console.
pingIntervalMilliseconds?: number

The interval in milliseconds at which the server should ping all connections to check if they are still alive. If the number is set to a value 0 or less, the server will not ping connections. If the value is set to a value between 1 and 100, the server will ping connections every 100 milliseconds instead.

If when a connection has not responded to a ping before the server sends out the next ping, the connection will be terminated.

Default

When not provided, the server will ping connections every 15_000 milliseconds (15 seconds).