NAME

MojoX::Transaction::WebSocket76 - WebSocket version hixie-76 transaction container

SYNOPSIS

    use MojoX::Transaction::WebSocket76;

    my $ws = MojoX::Transaction::WebSocket76->new;

DESCRIPTION

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)
            );
        }
        # ...
    }

EVENTS

MojoX::Transaction::WebSocket76 inherits all events from Mojo::Transaction::WebSocket.

ATTRIBUTES

MojoX::Transaction::WebSocket76 inherits all attributes from Mojo::Transaction::WebSocket.

METHODS

MojoX::Transaction::WebSocket76 inherits all methods from Mojo::Transaction::WebSocket.

Mojo::Transaction::WebSocket76 overrides the following methods from Mojo::Transaction::WebSocket:

build_frame

  my $bytes = $ws->build_frame($fin, $rsv1, $rsv2, $rsv3, $op, $payload);

Build WebSocket frame.

parse_frame

  my $frame = $ws->parse_frame(\$bytes);

Parse WebSocket frame.

server_handshake

  $ws->server_handshake;

Perform WebSocket handshake server-side, used to implement web servers.

DEBUGGING

You can set the MOJO_WEBSOCKET_DEBUG environment variable to get some advanced diagnostics information printed to STDERR.

    MOJO_WEBSOCKET_DEBUG=1

SEE ALSO

Mojolicious, Mojo::Transaction::WebSocket.

SUPPORT

Repository

http://github.com/dionys/mojox-transaction-websocket76

Bug tracker

http://github.com/dionys/mojox-transaction-websocket76/issues

AUTHOR

Denis Ibaev, dionys@cpan.org.

CONTRIBUTORS

Paul Cochrane, cpan:PTC, paul@liekut.de.

COPYRIGHT AND LICENSE

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.