Options
All
  • Public
  • Public/Protected
  • All
Menu

Actively handles the heartbeat ping/pong mechanism respecting the specified parameters.

Hierarchy

  • HeartbeatHandler

Index

Constructors

constructor

  • new HeartbeatHandler(websocket: WebSocket, pingInterval: number, onDeath?: function): HeartbeatHandler
  • Default constructor.

    Parameters

    • websocket: WebSocket

      The web socket instance on which we want to perform the checks and start the monitoring.

    • pingInterval: number

      The interval between which ping/pong messages are exchanged between client and server (defaults to 1 minute).

    • Optional onDeath: function

      Callback called on client/server connection end, detected from missing heartbeat updates.

        • (): any
        • Returns any

    Returns HeartbeatHandler

Properties

Private STATE_CLOSED

STATE_CLOSED: number = 3

Private STATE_OPEN

STATE_OPEN: number = 1

Private alive

alive: boolean

Private onDeath

onDeath: function

Type declaration

    • (): any
    • Returns any

Private pingInterval

pingInterval: number

Private websocket

websocket: WebSocket

Methods

handle

  • handle(): void

Private handleHeartbeat

  • handleHeartbeat(): void
  • Implements the business logic required for the heartbeat detection to work. If the heartbeat stops respecting the previously-set timeout, the client/server connection is considered dead and the eventually passed in callback is called. The web socket is also closed with code 1008 (policy violation) and message "Heartbeat stopped".

    Returns void

Generated using TypeDoc