MojoX::Transaction::WebSocket76 - WebSocket version hixie-76 transaction container
use MojoX::Transaction::WebSocket76; my $ws = MojoX::Transaction::WebSocket76->new;
MojoX::Transaction::WebSocket76 is a container for WebSocket transactions as described in hixie-76 draft. Support for this version of the protocol was removed in Mojolicious 1.17. However, only old versions of the Safari browser (5.0.1) support only it.
NOTICE: This code tested with Mojolicious 4.xx and below and might not works with higher versions. This code not works with Mojolicious 6.40 and above.
To add support for both versions of the protocol (last and hixie-76 draft) in your Mojolicious application, add:
# In application module. package MyApp; # Override Mojolicious::build_tx(). sub build_tx { my ($self) = @_; # Use your own transaction module. my $tx = MyApp::Transaction->new; $self->plugins->emit_hook(after_build_tx => $tx, $self); return $tx; } # In transaction module. package MyApp::Transaction; use Mojo::Transaction::WebSocket; use MojoX::Transaction::WebSocket76; use Mojo::Base 'Mojo::Transaction::HTTP'; # Override Mojo::Transaction::HTTP::server_read(). sub server_read { # ... # Need to change only this piece of code. if (lc($req->headers->upgrade || '') eq 'websocket') { # Upgrade to WebSocket of needed version. $self->emit(upgrade => ($req->headers->header('Sec-WebSocket-Key1') && $req->headers->header('Sec-WebSocket-Key2')) ? MojoX::Transaction::WebSocket76->new(handshake => $self) : Mojo::Transaction::WebSocket->new(handshake => $self) ); } # ... }
MojoX::Transaction::WebSocket76 inherits all events from Mojo::Transaction::WebSocket.
MojoX::Transaction::WebSocket76 inherits all attributes from Mojo::Transaction::WebSocket.
MojoX::Transaction::WebSocket76 inherits all methods from Mojo::Transaction::WebSocket.
Mojo::Transaction::WebSocket76 overrides the following methods from Mojo::Transaction::WebSocket:
my $bytes = $ws->build_frame($fin, $rsv1, $rsv2, $rsv3, $op, $payload);
Build WebSocket frame.
my $frame = $ws->parse_frame(\$bytes);
Parse WebSocket frame.
$ws->server_handshake;
Perform WebSocket handshake server-side, used to implement web servers.
You can set the MOJO_WEBSOCKET_DEBUG environment variable to get some advanced diagnostics information printed to STDERR.
MOJO_WEBSOCKET_DEBUG
MOJO_WEBSOCKET_DEBUG=1
Mojolicious, Mojo::Transaction::WebSocket.
http://github.com/dionys/mojox-transaction-websocket76
http://github.com/dionys/mojox-transaction-websocket76/issues
Denis Ibaev, dionys@cpan.org.
dionys@cpan.org
Paul Cochrane, cpan:PTC, paul@liekut.de.
paul@liekut.de
Copyright (C) 2012-2016, Denis Ibaev.
This program is free software; you can redistribute it and/or modify it under the same terms as Perl itself.
See http://dev.perl.org/licenses/ for more information.
To install MojoX::Transaction::WebSocket76, copy and paste the appropriate command in to your terminal.
cpanm
cpanm MojoX::Transaction::WebSocket76
CPAN shell
perl -MCPAN -e shell install MojoX::Transaction::WebSocket76
For more information on module installation, please visit the detailed CPAN module installation guide.