Created
August 13, 2015 20:05
-
-
Save JDorpinghaus/3a20bd2ab212d490e3c0 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
$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