NAME
PAGI::App::SSE::Pubsub - Pub/sub Server-Sent Events
SYNOPSIS
use PAGI::App::SSE::Pubsub;
my $app = PAGI::App::SSE::Pubsub->new->to_app;
# From elsewhere, publish events
PAGI::App::SSE::Pubsub->publish('news', { data => 'Hello!' });
DESCRIPTION
Pub/sub pattern for Server-Sent Events. Clients subscribe to channels and receive events published to those channels.
OPTIONS
channel- Channel name (default: 'default')retry- Reconnection time in millisecondshistory- Number of events to keep for replayon_connect- Callback when client connectson_close- Callback when client disconnectsheaders- Additional response headers
CLASS METHODS
publish($channel, $event)
Publish an event to all subscribers of a channel.
PAGI::App::SSE::Pubsub->publish('news', {
event => 'update',
id => '123',
data => 'News content here',
});
client_count($channel)
Get number of connected clients, optionally filtered by channel.
list_channels()
Get list of active channel names.