Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
tree: 62b61c4e91
Fetching contributors…

Cannot retrieve contributors at this time

28 lines (21 sloc) 0.611 kb
package chat::websocket;
use strict;
use warnings;
use Dancer ':syntax';
use Dancer::Plugin::WebSocket;
websocket '/new_listener' => sub {
my $env = request->env;
my $room = $env->{'hippie.args'};
my $topic = $env->{'hippie.bus'}->topic($room);
$env->{'hippie.listener'}->subscribe($topic);
};
websocket '/message' => sub {
my $env = request->env;
my $room = $env->{'hippie.args'};
my $topic = $env->{'hippie.bus'}->topic($room);
my $msg = $env->{'hippie.message'};
$msg->{time} = time;
$msg->{address} = $env->{REMOTE_ADDR};
$topic->publish($msg);
};
1;
Jump to Line
Something went wrong with that request. Please try again.