Subject: | Net::SIP::Simple invite callbacks not working |
Date: | Mon, 9 Apr 2018 15:18:54 +0000 |
To: | "bug-Net-SIP [...] rt.cpan.org" <bug-Net-SIP [...] rt.cpan.org> |
From: | Richard Carver <richard.carver [...] cloudmont.co.uk> |
#!/usr/bin/perl -w
use strict;
use Net::SIP;
Net::SIP::Debug->level(50);
# create new agent
my $ua = Net::SIP::Simple->new(
outgoing_proxy => 'sip:proxy.ip.addr:5060',
from => '+445000000@test.caller.local',
);
# Invite other party
$ua->invite( 'sip:username@domainname:5060',
cb_preliminary => sub { print STDERR 'cb_prelim'; },
cb_final => sub { print STDERR 'cb_final'; },
);
# Mainloop
$ua->loop;
This does not call either of the two callbacks. The reason is that in Net::SIP::Simple::Call / reinvite the first argument to $cb is undef. This is presumably because $self is weakened when it sets up the callback and it then goes out of scope. If I change my script to assign the result of $ua->invite to a variable then the callbacks work.
You could just update the example code in the Net::SIP::Simple documentation to say that it must be referenced for callbacks to work.