noxxi / p5-net-sip

Net::SIP Perl Module
Other
15 stars 22 forks source link

Printing INVITES #49

Closed ghenry closed 3 years ago

ghenry commented 3 years ago

Hi all,

I'm trying to create an open registrar (working) and have some callbacks for save some data like so, but I can get my filter to fire:

use strict;
use warnings;

use Net::SIP;
use Data::Dumper;

#use Net::SIP::Debug '10';

my $ua = Net::SIP::Simple->new( leg => '192.168.XX.XX:5060' );

my $save_invites = sub {
    my ( $from, $call ) = @_;
    print Dumper $call, "\n";
    return 1;
};

$ua->listen( filter => $save_invites );
$ua->create_registrar;
$ua->loop;

What am I not understanding here?

Thanks.

ghenry commented 3 years ago

It looks like I can get to INVITEs via $ua->listen( cb_invite => ()) too, but I'd like the registrar feature as well.

ghenry commented 3 years ago

I think there's a lot for my use case in this https://metacpan.org/release/SULLR/Net-SIP-0.830/source/bin/answer_machine.pl

ghenry commented 3 years ago

Apart from being the registrar though...hmm.

noxxi commented 3 years ago

listen will handle INVITE, create_registrar will handle REGISTER. If you want both it should be doable by using create_chain with the registrar as the first element and the listener as the second.

ghenry commented 3 years ago

Ah, of course! Thanks for your help.

ghenry commented 3 years ago

I've gone for this:

my $ua = Net::SIP::Simple->new( leg => '192.168.100.90:5060' );

my $save_invites = sub {
    my ( $from, $call ) = @_;
    print Dumper $call, "\n";
    return 1;
};

# https://github.com/noxxi/p5-net-sip/issues/49#issuecomment-902025333
$ua->create_chain(
    [ $ua->create_registrar, $ua->listen( filter => $save_invites ) ] );
$ua->loop;

I'm not seeing anything in my print unless STDERR and STDOUT are getting eaten.

Thanks.

ghenry commented 3 years ago

Seeing more now I've put Debug 1 on:

1629406816.7531 DEBUG:<1>   
1629406816.8227 DEBUG:<1> Net::SIP::Registrar::receive[75]: method SUBSCRIBE addr=<sip:1001@192.168.100.90>
1629406816.8228 DEBUG:<1> Net::SIP::Registrar::receive[81]: rewrite URI sip:1001@192.168.100.90 in SUBSCRIBE to sip:1001@192.168.100.90:1401;transport=udp;registering_acc=192_168_100_90
1629406816.8229 DEBUG:<1> Net::SIP::Dispatcher::__ANON__[226]: dispatcher croaked: Can't locate object method "receive" via package "0" (perhaps you forgot to load "0"?) at /usr/local/share/perl5/5.32/Net/SIP/ReceiveChain.pm line 63.
ghenry commented 3 years ago

I need to put the Objects in the chain I think.

ghenry commented 3 years ago

This is OK as it returns an Object:

https://metacpan.org/dist/Net-SIP/source/lib/Net/SIP/Simple.pm#L562

so I think it's my $ua->listen in the chain.

ghenry commented 3 years ago

Any ideas?

noxxi commented 3 years ago

Looks like listen does not return the necessary object for the chain. Please try the change in 6ba8f4e which should hopefully fix the problem. It is not tested though.

ghenry commented 3 years ago

Thanks! Will take a look. Really appreciate you doing this.

ghenry commented 3 years ago

Stupid me. I should have read your tests too. Ideal - https://github.com/noxxi/p5-net-sip/blob/6ba8f4e76382b821ea7c1b76bf18850f714fc3a0/t/02_listen_and_invite.t

But anyway, all working now! Thank you very much for your advice and quick additions.