blob: 5f6e5c891b0019592e84dd4162ea4d3100da4586 (
plain) (
blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
|
package chat::websocket;
use strict;
use warnings;
use lib ('/home/franck/code/git/dancer/lib');
use Dancer ':syntax';
use Dancer::Plugin::WebSocket;
load_plugin 'Dancer::Plugin::WebSocket';
use AnyMQ;
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;
|