Skip to content

Instantly share code, notes, and snippets.

@clkao
Created May 26, 2010 13:37
Show Gist options
  • Save clkao/414488 to your computer and use it in GitHub Desktop.
Save clkao/414488 to your computer and use it in GitHub Desktop.
function log_it(stuff) {
$("#log").append(stuff+'<br/>');
}
$(function() {
var hippie = new Hippie( document.location.host, 5, function() {
log_it("connected");
},
function() {
log_it("disconnected");
},
function(e) {
log_it("got message: type = "+e.type+", time = "+e.time);
} );
});
mount '/_hippie' => builder {
enable "+Web::Hippie";
sub {
my $env = shift;
my $interval = $env->{'hippie.args'} || 5;
my $h = $env->{'hippie.handle'};
if ($env->{PATH_INFO} eq '/init') {
my $w; $w = AnyEvent->timer( interval => $interval,
cb => sub {
$h->send_msg({
type => 'timer',
time => AnyEvent->now,
});
$w;
});
}
else {
return [ '400', [ 'Content-Type' => 'text/plain' ], [ "" ] ]
unless $h;
if ($env->{PATH_INFO} eq '/error') {
warn "==> disconnecting $h";
}
else {
die "unknown hippie message";
}
}
return [ '200', [ 'Content-Type' => 'application/hippie' ], [ "" ] ]
};
};
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment