Extend functionality using Middleware
v3.8-mainThe library uses a middleware pattern to intercept and process various stages of the WebSocket lifecycle. You can implement WebSocket\Middleware\MiddlewareInterface to hook into:
- HTTP Handshake:
processHttpIncomingandprocessHttpOutgoing. - WebSocket Messages:
processIncomingandprocessOutgoing. - Lifecycle Ticks:
processTick(useful for periodic tasks like heartbeats).
Common built-in middlewares include:
WebSocket\Middleware\CompressionExtension: For handling per-message compression.WebSocket\Middleware\PingInterval: To automatically send pings.WebSocket\Middleware\SubprotocolNegotiation: To handle WebSocket subprotocols.