Skip to content

Instantly share code, notes, and snippets.

@xantus
Created July 16, 2010 23:07
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save xantus/c52492745ca665c1dcec to your computer and use it in GitHub Desktop.
Save xantus/c52492745ca665c1dcec to your computer and use it in GitHub Desktop.
#!/usr/bin/perl
use Mojolicious::Lite;
use Ignite::Lite;
app->log->level( 'debug' );
@ARGV = qw( daemon ) unless @ARGV;
my $buffer = [];
socketio 'open' => sub {
my $client = shift;
$client->send_message({ sessionid => $client->id });
$client->send_message({ buffer => $buffer });
$client->broadcast({ announcement => $client->id . ' connected' });
$client->heartbeat( 10 );
};
socketio 'close' => sub {
my $client = shift;
$client->broadcast({ announcement => $client->id . ' disconnected' });
$client->disconnect();
};
socketio 'message' => sub {
my ( $client, $data ) = @_;
my $msg = { message => [ $client->id, $data ] };
push( @$buffer, $msg );
shift @$buffer if ( $#{$buffer} > 15 );
$client->broadcast($msg);
};
app->start;
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment