sub websockets_handler { my $self = shift; # Opened $self->app->log->debug('WebSocket opened.'); # Increase inactivity timeout for connection a bit Mojo::IOLoop->stream($self->tx->connection)->timeout(300); # Incoming message $self->on(message => sub { my ($self, $msg) = @_; $self->send({text => $msg}); }); # Closed $self->on(finish => sub { my ($self, $code, $reason) = @_; $self->app->log->debug("WebSocket closed with status $code."); }); }