NAME

PAGI::Middleware::WebSocket::Heartbeat - WebSocket keepalive via ping/pong

SYNOPSIS

use PAGI::Middleware::Builder;

my $app = builder {
    enable 'WebSocket::Heartbeat',
        interval => 30,
        timeout  => 10;
    $my_app;
};

DESCRIPTION

PAGI::Middleware::WebSocket::Heartbeat sends periodic ping frames to WebSocket clients and monitors for pong responses. Connections that don't respond within the timeout are closed.

CONFIGURATION

  • interval (default: 30)

    Seconds between ping frames.

  • timeout (default: 10)

    Seconds to wait for pong response before considering connection dead.

  • loop (optional)

    IO::Async::Loop instance for scheduling.

HOW IT WORKS

After the application sends websocket.accept, this middleware begins sending ping frames at the configured interval. When a pong is received, the timeout is reset. If no pong arrives within the timeout period, the connection is closed with code 1001 (Going Away).

The middleware is transparent to the application - ping/pong frames are handled automatically without passing through to the app.

SCOPE EXTENSIONS

  • pagi.websocket.heartbeat

    Hashref containing interval and timeout settings.

SEE ALSO

PAGI::Middleware - Base class for middleware

PAGI::Middleware::WebSocket::RateLimit - Rate limiting for WebSocket