WebSocket Server

The WebSocketServer class is used to start and configure the WebSocket service. It provides full-duplex communication channels over a single TCP connection using the WebSocket protocol. This enables real-time, two-way communication between a client (e.g., a web browser) and a server, allowing for interactive web applications.

Hierarchy

  • WebsocketServer

Constructors

Properties

connections: WebsocketConnection[] = []
httpServer: Server

The HTTP server object used to start the WebSocket server.

logging: boolean = false
server: Server<WebSocket>
_fetchIpLocation: boolean = false

Accessors

  • get fetchIpLocation(): boolean
  • Determines whether the connection IP location functionality is enabled.

    Returns boolean

    A boolean indicating if the connection IP location functionality is enabled.

Methods

  • Retrieves the recommended WebSocket server options.

    Returns ServerOptions

    The server options object.

  • Updates the client information of the connection.

    Parameters

    • info: {
          browser: string;
      }

      An object containing descriptions concerning the client device.

      • browser: string
    • conn: WebsocketConnection

      The associated WebsocketConnection object.

    Returns void

  • Handles the WebSocket connection close event.

    Parameters

    Returns (() => void)

    A callback function that removes the closed connection from the list of established connections.

      • (): void
      • Returns void

  • Handles the WebSocket connection event.

    Parameters

    • connection: WebSocket

      The WebSocket connection object.

    • req: any

      The request object associated with the connection.

    Returns void

  • Enables the connection IP location functionality. When enabled, location information is fetched for all connections once they establish the connection.

    Returns void

Generated using TypeDoc