line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
package Minion::Notifier::Transport::WebSocket; |
2
|
|
|
|
|
|
|
|
3
|
1
|
|
|
1
|
|
7
|
use Mojo::Base 'Minion::Notifier::Transport'; |
|
1
|
|
|
|
|
2
|
|
|
1
|
|
|
|
|
8
|
|
4
|
|
|
|
|
|
|
|
5
|
1
|
|
|
1
|
|
80
|
use Mojo::URL; |
|
1
|
|
|
|
|
2
|
|
|
1
|
|
|
|
|
8
|
|
6
|
1
|
|
|
1
|
|
27
|
use Mojo::UserAgent; |
|
1
|
|
|
|
|
2
|
|
|
1
|
|
|
|
|
17
|
|
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
|
|
9685
|
my ($ua, $tx) = @_; |
15
|
|
|
|
|
|
|
$tx->on(json => sub { |
16
|
3
|
|
|
|
|
7926
|
my ($tx, $data) = @_; |
17
|
3
|
|
|
|
|
34
|
$self->emit(notified => @$data); |
18
|
1
|
|
|
|
|
19
|
}); |
19
|
1
|
|
|
|
|
4
|
}); |
20
|
|
|
|
|
|
|
} |
21
|
|
|
|
|
|
|
|
22
|
|
|
|
|
|
|
sub send { |
23
|
3
|
|
|
3
|
0
|
81
|
my ($self, $id, $message) = @_; |
24
|
|
|
|
|
|
|
$self->ua->websocket($self->url => sub { |
25
|
3
|
|
|
3
|
|
31781
|
my ($ua, $tx) = @_; |
26
|
3
|
|
|
|
|
21
|
$tx->send({json => [$id, $message]}); #TODO finish after send? |
27
|
3
|
|
|
|
|
27
|
}); |
28
|
|
|
|
|
|
|
} |
29
|
|
|
|
|
|
|
|
30
|
|
|
|
|
|
|
|
31
|
|
|
|
|
|
|
1; |
32
|
|
|
|
|
|
|
|