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 milliseconds

  • history - Number of events to keep for replay

  • on_connect - Callback when client connects

  • on_close - Callback when client disconnects

  • headers - 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.