| 1 | package Minion::Notifier::Transport::WebSocket; | ||
| 2 | |||
| 3 | 1 | ▶ | use Mojo::Base 'Minion::Notifier::Transport'; |
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||
| 4 | |||
| 5 | 1 | ▶ | use Mojo::URL; |
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||
| 6 | 1 | ▶ | use Mojo::UserAgent; |
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||
| 7 | |||
| 8 | 0 | ▶ | has ua => sub { Mojo::UserAgent->new }; |
|
Subroutine
__ANON__: not called CC=1 SCAR=1.2
| |||
| 9 | 0 | ▶ | has url => sub { die 'url is required' }; |
|
Subroutine
__ANON__: not called CC=1 SCAR=1.2
| |||
| 10 | |||
| 11 | 1 | ▶ | sub listen { |
|
Subroutine
listen: called CC=1 SCAR=0.0
Pod
undocumented
| |||
| 12 | 1 | my $self = shift; | |
| 13 | 1 | ▶ | $self->ua->websocket($self->url => sub { |
|
Subroutine
__ANON__: called CC=1 SCAR=0.0
| |||
| 14 | 1 | my ($ua, $tx) = @_; | |
| 15 | 3 | ▶ | $tx->on(json => sub { |
|
Subroutine
__ANON__: called CC=1 SCAR=0.0
| |||
| 16 | 3 | my ($tx, $data) = @_; | |
| 17 | 3 | $self->emit(notified => @$data); | |
| 18 | 1 | }); | |
| 19 | 1 | }); | |
| 20 | } | ||
| 21 | |||
| 22 | 3 | ▶ | sub send { |
|
Subroutine
send: called CC=1 SCAR=0.0
Pod
undocumented
| |||
| 23 | 3 | my ($self, $id, $message) = @_; | |
| 24 | 3 | ▶ | $self->ua->websocket($self->url => sub { |
|
Subroutine
__ANON__: called CC=1 SCAR=0.0
| |||
| 25 | 3 | my ($ua, $tx) = @_; | |
| 26 | 3 | $tx->send({json => [$id, $message]}); #TODO finish after send? | |
| 27 | 3 | }); | |
| 28 | } | ||
| 29 | |||
| 30 | |||
| 31 | 1 | 1; | |
| 32 | |||