Skip to content

Instantly share code, notes, and snippets.

@JDorpinghaus
Created August 13, 2015 20:05
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 JDorpinghaus/3a20bd2ab212d490e3c0 to your computer and use it in GitHub Desktop.
Save JDorpinghaus/3a20bd2ab212d490e3c0 to your computer and use it in GitHub Desktop.
$r->websocket('/news')->to(cb => sub {
my $self = shift;
$self->on(message => sub {
my ($self, $msg) = @_;
$msg = decode_json($msg);
if ($msg->{type} eq 'ready'){
my ($sec,$min,$hour,$mday,$mon,$year,$wday,$yday,$isdst) = localtime();
my $headline = 'Bingo at 5 today!';
my $description = 'This message is really long and demonstrates the scrolling ability of the banner text. Go to Bingo at 5PM tonight in the cafeteria! Dinner is at 7PM tonight, meatloaf will be served.';
my $expiration = 30;
my $hash = md5_hex($headline . $description . $expiration);
my $message = {headline => $headline, message => $description, expiration => $expiration, messagehash => $hash};
if ($self->session('closed') ne $hash){
$self->send({json => $message});
}
}
elsif ($msg->{type} eq 'close') {
$self->session(closed => $msg->{messagehash});
say $msg->{messagehash};
say 'closed cookie: ' . $self->session('closed');
}
});
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment