Skip to content

Commit

Permalink
updated a few WebSocket examples
Browse files Browse the repository at this point in the history
  • Loading branch information
kraih committed Apr 12, 2013
1 parent c381eee commit 360d51b
Show file tree
Hide file tree
Showing 5 changed files with 15 additions and 12 deletions.
6 changes: 3 additions & 3 deletions lib/Mojo/Transaction/WebSocket.pm
Expand Up @@ -314,8 +314,8 @@ Mojo::Transaction::WebSocket - WebSocket transaction
say "Message: $msg";
});
$ws->on(finish => sub {
my $ws = shift;
say 'WebSocket closed.';
my ($ws, $code, $reason) = @_;
say "WebSocket closed with status $code.";
});
=head1 DESCRIPTION
Expand Down Expand Up @@ -517,7 +517,7 @@ Connection identifier or socket.
$ws = $ws->finish(1000);
$ws = $ws->finish(1003 => 'Cannot accept data!');
Finish the WebSocket connection gracefully.
Close WebSocket connection gracefully.
=head2 is_websocket
Expand Down
5 changes: 4 additions & 1 deletion lib/Mojo/UserAgent.pm
Expand Up @@ -1007,7 +1007,10 @@ L<Mojo::Transaction::HTTP> object.
$ua->websocket('ws://localhost:3000/echo' => sub {
my ($ua, $tx) = @_;
say 'WebSocket handshake failed!' and return unless $tx->is_websocket;
$tx->on(finish => sub { say 'WebSocket closed.' });
$tx->on(finish => sub {
my ($tx, $code, $reason) = @_;
say "WebSocket closed with status $code.";
});
$tx->on(message => sub {
my ($tx, $msg) = @_;
say "WebSocket message: $msg";
Expand Down
2 changes: 1 addition & 1 deletion lib/Mojolicious/Controller.pm
Expand Up @@ -556,7 +556,7 @@ Access request cookie values and create new response cookies.
$c = $c->finish(1003 => 'Cannot accept data!');
$c = $c->finish('Bye!');
Gracefully end WebSocket connection or long poll stream.
Close WebSocket connection or long poll stream gracefully.
=head2 flash
Expand Down
10 changes: 5 additions & 5 deletions lib/Mojolicious/Guides/Cookbook.pod
Expand Up @@ -464,8 +464,8 @@ method L<Mojolicious::Controller/"on">.
websocket '/echo' => sub {
my $self = shift;

# Connected
$self->app->log->debug('WebSocket connected.');
# Opened
$self->app->log->debug('WebSocket opened.');

# Increase inactivity timeout for connection a bit
Mojo::IOLoop->stream($self->tx->connection)->timeout(300);
Expand All @@ -476,10 +476,10 @@ method L<Mojolicious::Controller/"on">.
$self->send("echo: $msg");
});

# Disconnected
# Closed
$self->on(finish => sub {
my $self = shift;
$self->app->log->debug('WebSocket disconnected.');
my ($self, $code, $reason) = @_;
$self->app->log->debug("WebSocket closed with status $code.");
});
};

Expand Down
4 changes: 2 additions & 2 deletions lib/Test/Mojo.pm
Expand Up @@ -599,13 +599,13 @@ Opposite of C<element_exists>.
$t = $t->finish_ok(1000);
$t = $t->finish_ok(1003 => 'Cannot accept data!');
Finish WebSocket connection gracefully.
Close WebSocket connection gracefully.
=head2 finished_ok
$t = $t->finished_ok(1000);
Wait for WebSocket connection to finish gracefully and check status.
Wait for WebSocket connection to be closed gracefully and check status.
=head2 get_ok
Expand Down

0 comments on commit 360d51b

Please sign in to comment.