Navigation Menu

Skip to content

Commit

Permalink
use real WebSocket example in tutorial
Browse files Browse the repository at this point in the history
  • Loading branch information
kraih committed Apr 8, 2013
1 parent 51be24d commit c522741
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 1 deletion.
2 changes: 1 addition & 1 deletion Changes
@@ -1,5 +1,5 @@

3.94 2013-04-07
3.94 2013-04-08
- Removed deprecated start method from Mojolicious::Commands.
- Improved documentation.

Expand Down
20 changes: 20 additions & 0 deletions lib/Mojolicious/Lite.pm
Expand Up @@ -870,7 +870,27 @@ WebSocket applications have never been this easy before.
});
};
get '/' => 'index';
app->start;
__DATA__
@@ index.html.ep
<!DOCTYPE html>
<html>
<head>
<title>WebSocket</title>
%= javascript begin
var ws = new WebSocket('<%= url_for('echo')->to_abs %>');
ws.onmessage = function (event) {
document.body.innerHTML += event.data + '<br/>';
};
ws.onopen = function (event) {
ws.send("I ♥ Mojolicious!");
};
% end
</head>
</html>
The event L<Mojo::Transaction::WebSocket/"message">, which you can subscribe
to with L<Mojolicious::Controller/"on">, will be emitted for every new
Expand Down

0 comments on commit c522741

Please sign in to comment.