Skip to content

Commit

Permalink
Emit message events
Browse files Browse the repository at this point in the history
  • Loading branch information
Max Maischein committed May 19, 2023
1 parent eccdee9 commit b913018
Showing 1 changed file with 4 additions and 25 deletions.
29 changes: 4 additions & 25 deletions lib/Chrome/DevToolsProtocol.pm
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,8 @@ use Scalar::Util 'weaken', 'isweak';
use Try::Tiny;
use URI;

with 'MooX::Role::EventEmitter';

our $VERSION = '0.71';
our @CARP_NOT;

Expand Down Expand Up @@ -141,17 +143,6 @@ has 'writer_fh' => (
is => 'ro',
);

=item B<on_message>
A callback invoked for every message
=cut

has 'on_message' => (
is => 'rw',
default => undef,
);

has '_one_shot' => (
is => 'ro',
default => sub { [] },
Expand Down Expand Up @@ -508,20 +499,8 @@ sub on_response( $self, $connection, $message ) {
$handled++;
};

if( $self->on_message ) {
if( $self->_log->is_trace ) {
$self->log( 'trace', "Dispatching", $response );
} else {
my $frameId = $response->{params}->{frameId};
my $requestId = $response->{params}->{requestId};
if( $frameId || $requestId ) {
$self->log( 'debug', sprintf "Dispatching '%s' (%s:%s)", $response->{method}, $frameId || '-', $requestId || '-');
} else {
$self->log( 'debug', sprintf "Dispatching '%s'", $response->{method} );
};
};
$self->on_message->( $response );

if( @{ $self->subscribers('message')} ) {
$self->emit('message', $response );
$handled++;
};

Expand Down

0 comments on commit b913018

Please sign in to comment.