=head1 NAME PEF::Front::WebSocket - WebSocket framework for PEF::Front =head1 SYNOPSIS # startup.pl use PEF::Front::Websocket; # usual startup stuff... # $PROJECT_DIR/app/WSTest/WebSocket/Echo.pm package WSTest::WebSocket::Echo; sub on_message { my ($self, $message) = @_; $self->send($message); } 1; =head1 DESCRIPTION This module makes WebSockets really easy. Every kind of WebSocket is in its own module. Default routing scheme is C. WebSocket handlers are located in C<$PROJECT_DIR/app/$MyAPP/WebSocket>. =head2 Prerequisites This module requires L, L and L server that must meet the following requirements. =over =item * C environment is true. =item * C environment is true. =item * C environment holds a valid raw IO socket object. See L. =back L version 2.0.14+ meets all of them with C. =head1 WEBSOCKET EVENT METHODS =head2 on_message($self, $message, $type) A subroutine that is called on new message from client. =head2 on_drain() A subroutine that is called when there's nothing to send to client after some successful send. =head2 on_open() A subroutine that is called each time it establishes a new WebSocket connection to a client. =head2 on_error() A subroutine that is called when some error happens while processing a request. =head2 on_close() A subroutine that is called on WebSocket close event. =head1 INHERITED METHODS Every WebSocket class is derived from C which is derived from C. Even when you don't derive your class from C explicitly, this class will be added automatically to hierarchy. =head2 send($buffer[, $type]) Sends $buffer to client. By default $type is 'text'. =head2 close() Closes WebSocket. =head2 is_defunct() Returns true when socket is closed or there's some error on it. =head1 EXAMPLE #startup.pl use WSTest::AppFrontConfig; use PEF::Front::Config; use PEF::Front::WebSocket; use PEF::Front::Route; PEF::Front::Route::add_route( get '/' => '/appWs', ); PEF::Front::Route->to_app(); # $PROJECT_DIR/app/WSTest/WebSocket/Echo.pm package WSTest::WebSocket::Echo; sub on_message { my ($self, $message) = @_; $self->send($message); } 1; # $PROJECT_DIR/templates/ws.html

WebSocket

# wstest.ini [uwsgi] plugins = coroae chdir = chdir = /$PROJECT_DIR logger = file:log/demo.log psgi = bin/startup.pl master = true processes = 4 coroae = 1000 perl-no-plack = true psgi-enable-psgix-io = true uid = $PROJECT_USER gid = www-data chmod-socket = 664 =head1 AUTHOR This module was written and is maintained by Anton Petrusevich. =head1 Copyright and License Copyright (c) 2016 Anton Petrusevich. Some Rights Reserved. This module is free software; you can redistribute it and/or modify it under the same terms as Perl itself. =cut