Options
All
  • Public
  • Public/Protected
  • All
Menu

Interface ServerOptions

Hierarchy

Index

Properties

Optional backlog

backlog: undefined | number

Optional clientTracking

clientTracking: undefined | false | true

Optional handleProtocols

handleProtocols: any

Optional handshake

handshake: undefined | ((token: Id, ws: ClientSocket) => Promise<boolean> | boolean)

An asynchronous function which handles every new connection. It accepts two arguments, token and ws. Function must return true value if we want to establish the connection. And the connection will be dropped otherwise.

param

Unique token of the client

param

A websocket instance of the connection

example
handshake: async (token) => {
  console.log('trying to connect', token);
  if (await theUserExistsInTheDatabase(token)) {
    return true;
  } else {
    return false
  }
}

Optional host

host: undefined | string

Optional maxPayload

maxPayload: undefined | number

Optional noServer

noServer: undefined | false | true

Optional path

path: undefined | string

Optional perMessageDeflate

perMessageDeflate: boolean | PerMessageDeflateOptions

Optional port

port: undefined | number

Optional prepareContext

prepareContext: undefined | ((ctx: RPCContext) => any)

Optional function to define initial context for the Server.register handlers. By default it returns the RPCContext object

param

An object with the token and id properties. Where id - is a unique method call identifier

example
const server = new Server({
  ...
  prepareContext: (ctx) => ({ ...ctx, useWS: true }),
});
server.register('ping', (ctx, params) => {
  console.log(ctx.id, 'server ping from', ctx.token, params, ctx.useWS);
});

Optional server

server: Server | Server

Optional verifyClient

Generated using TypeDoc