The Perl Toolchain Summit needs more sponsors. If your company depends on Perl, please support this very important event.

NAME

Jifty::Plugin::PubSub::Connection - Connection to browser

DESCRIPTION

This class represents a bidirectional channel between the server and the web browser. You may wish to subclass this class as YourApp::PubSub to override the "connect", "receive", or "disconnect" methods.

METHODS

connect

Called when a connection is established from the browser. By default, does nothing.

subscribe TOPIC [, TOPIC, ...]

Subscribes the browser to receive messages on the given topics.

send TYPE DATA

Sends an arbitrary message to the browser. It is not published to the rest of the message bus.

receive DATA

Called when a message is received from the web browser; returns true if the message was processed, false otherwise. If you override this method, be sure you respect this class' return value:

    sub receive {
        my $self = shift;
        my $msg = shift;
        return 1 if $self->SUPER::receive( $msg );
        # ...
    }

disconnect

Called when the connection to the browser is lost when the browser switches to a new page. This is not immediate, but occurs after a 15-second timeout.

web

Returns the constructed Jifty::Web object which is seen as Jifty-web> whenever in the context of this connection's "connect", "receive", "disconnect", or when page regions are rendered to be sent over this channel. This ensures that Jifty-web->current_user> is set whenever it is relevant.

api

A new Jifty::API object is instantiated for each Jifty::Plugin::PubSub::Connection object. You may wish to limit it to limit which actions can be performed by the web browser.

listener

The AnyMQ::Queue object which listens to events for the client.

client_id

Returns a unique identifier associated with this connection.

action_message DATA

Creates, validates, and runs an action if it was received by the client; called by "receive".

region_event EVENT

Called when one or more regions on the page needs to be rendered and pushed to the client, as triggered by an event. The rendered regions will be passed EVENT as an event variable. Currently, rendered regions cannot alter the client's subscription set.