Skip to content

mindc/plack-app-net-async-websocket

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

20 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

NAME

Plack::App::Net::Async::WebSocket - serve WebSocket clients using IO::Async over PSGI

SYNOPSIS

# app.psgi

use Plack::App::Net::Async::WebSocket;

my $app = Plack::App::Net::Async::WebSocket->new(
        on_handshake => sub {
                my ( $websocket ) = @_;
                $websocket->sent_frame( 'Hello' );
        },
        on_frame => sub {
                my ( $websocket, $frame ) = @_;
                $websocket->send_frame( $frame ); # echo
        },
        on_closed => sub {
                my ( $websocket ) = @_;
        }
)->to_app;


# using Plack::Builder

use Plack::Builder;
use Plack::App::Net::Async::WebSocket;

builder {
        mount '/websocket' => Plack::App::Net::Async::WebSocket->new(
                on_frame => sub {
                my ( $websocket, $frame ) = @_;
                        $websocket->send_frame( $frame ); # echo
        },
        );
};

DESCRIPTION

This subclass of Plack::Component accepts WebSocket connections. When a new connection arrives it will perform an initial handshake and take control over existing connection.

PARAMETERS

The following named parameters may be passed to new:

on_handshake => CODE

A CODE reference for when a new connection has been handshaked. This parameter is optional

on_frame => CODE

A CODE reference for when a frame is received

on_close => CODE

This parameter is optional

on_error => CODE

This parameter is optional

METHODS

$client->send_frame( @args )

Sends a frame to the peer containing the given string. The arguments are passed to Protocol::WebSocket::Frame's new method.

SEE ALSO

AUTHOR

Paweł Feruś <[email protected]>

About

Handle WebSocket clients with PSGI using IO::Async

Topics

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages