line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
package Minion::Notifier::Transport::WebSocket; |
2
|
|
|
|
|
|
|
|
3
|
1
|
|
|
1
|
|
6
|
use Mojo::Base 'Minion::Notifier::Transport'; |
|
1
|
|
|
|
|
2
|
|
|
1
|
|
|
|
|
5
|
|
4
|
|
|
|
|
|
|
|
5
|
1
|
|
|
1
|
|
65
|
use Mojo::URL; |
|
1
|
|
|
|
|
2
|
|
|
1
|
|
|
|
|
7
|
|
6
|
1
|
|
|
1
|
|
23
|
use Mojo::UserAgent; |
|
1
|
|
|
|
|
2
|
|
|
1
|
|
|
|
|
7
|
|
7
|
|
|
|
|
|
|
|
8
|
|
|
|
|
|
|
has ua => sub { Mojo::UserAgent->new }; |
9
|
|
|
|
|
|
|
has url => sub { die 'url is required' }; |
10
|
|
|
|
|
|
|
|
11
|
|
|
|
|
|
|
sub listen { |
12
|
1
|
|
|
1
|
0
|
5
|
my $self = shift; |
13
|
|
|
|
|
|
|
$self->ua->websocket($self->url => sub { |
14
|
1
|
|
|
1
|
|
6248
|
my ($ua, $tx) = @_; |
15
|
|
|
|
|
|
|
$tx->on(json => sub { |
16
|
3
|
|
|
|
|
6554
|
my ($tx, $data) = @_; |
17
|
3
|
|
|
|
|
22
|
$self->emit(notified => @$data); |
18
|
1
|
|
|
|
|
6
|
}); |
19
|
1
|
|
|
|
|
2
|
}); |
20
|
|
|
|
|
|
|
} |
21
|
|
|
|
|
|
|
|
22
|
|
|
|
|
|
|
sub send { |
23
|
3
|
|
|
3
|
0
|
42
|
my ($self, $id, $message) = @_; |
24
|
|
|
|
|
|
|
$self->ua->websocket($self->url => sub { |
25
|
3
|
|
|
3
|
|
28987
|
my ($ua, $tx) = @_; |
26
|
3
|
|
|
|
|
18
|
$tx->send({json => [$id, $message]}); #TODO finish after send? |
27
|
3
|
|
|
|
|
18
|
}); |
28
|
|
|
|
|
|
|
} |
29
|
|
|
|
|
|
|
|
30
|
|
|
|
|
|
|
|
31
|
|
|
|
|
|
|
1; |
32
|
|
|
|
|
|
|
|