Options
All
  • Public
  • Public/Protected
  • All
Menu

Interface WebSocketBehavior

A structure holding settings and handlers for a WebSocket URL route handler.

Hierarchy

  • WebSocketBehavior

Index

Properties

Optional close

close: (ws: WebSocket, code: number, message: ArrayBuffer) => void

Handler for close event, no matter if error, timeout or graceful close. You may not use WebSocket after this event. Do not send on this WebSocket from within here, it is closed.

Type declaration

    • (ws: WebSocket, code: number, message: ArrayBuffer): void
    • Parameters

      • ws: WebSocket
      • code: number
      • message: ArrayBuffer

      Returns void

Optional compression

compression: CompressOptions

What permessage-deflate compression to use. uWS.DISABLED, uWS.SHARED_COMPRESSOR or any of the uWS.DEDICATED_COMPRESSOR_xxxKB.

Optional drain

drain: (ws: WebSocket) => void

Handler for when WebSocket backpressure drains. Check ws.getBufferedAmount(). Use this to guide / drive your backpressure throttling.

Type declaration

Optional idleTimeout

idleTimeout: number

Maximum amount of seconds that may pass without sending or getting a message. Connection is closed if this timeout passes. Resolution (granularity) for timeouts are typically 4 seconds, rounded to closest. Disable by leaving 0.

Optional maxBackpressure

maxBackpressure: number

Maximum length of allowed backpressure per socket when PUBLISHING messages (does not apply to ws.send). Slow receivers with too high backpressure will be skipped until they catch up or timeout.

Optional maxPayloadLength

maxPayloadLength: number

Maximum length of received message. If a client tries to send you a message larger than this, the connection is immediately closed.

Optional message

message: (ws: WebSocket, message: ArrayBuffer, isBinary: boolean) => void

Handler for a WebSocket message. Messages are given as ArrayBuffer no matter if they are binary or not. Given ArrayBuffer is valid during the lifetime of this callback (until first await or return) and will be neutered.

Type declaration

    • (ws: WebSocket, message: ArrayBuffer, isBinary: boolean): void
    • Parameters

      • ws: WebSocket
      • message: ArrayBuffer
      • isBinary: boolean

      Returns void

Optional open

open: (ws: WebSocket) => void

Handler for new WebSocket connection. WebSocket is valid from open to close, no errors.

Type declaration

Optional ping

ping: (ws: WebSocket) => void

Handler for received ping control message. You do not need to handle this, pong messages are automatically sent as per the standard.

Type declaration

Optional pong

pong: (ws: WebSocket) => void

Handler for received pong control message.

Type declaration

Optional upgrade

upgrade: (res: HttpResponse, req: HttpRequest, context: us_socket_context_t) => void

Upgrade handler used to intercept HTTP upgrade requests and potentially upgrade to WebSocket. See UpgradeAsync and UpgradeSync example files.

Type declaration

Generated using TypeDoc