AnyEvent-SIP
view release on metacpan or search on metacpan
t/anyevent.t view on Meta::CPAN
from => 'me.uac@example.com',
leg => scalar(create_socket_to( $peer_addr )),
domain2proxy => { 'example.com' => $peer_addr },
);
ok( $uac, 'UAC created' );
ok( <$pipe>, "UAS ready\n" ); # wait until UAS is ready
my $ringing = 0;
my $cv = AE::cv;
my $call = $uac->invite(
'you.uas@example.com',
cb_preliminary => sub {
my ($self,$code,$packet) = @_;
if ( $code == 180 ) {
diag( 'got ringing' );
$ringing ++;
$cv->send;
}
}
);
$cv->recv;
ok( $ringing,'got ringing' );
ok( ! $uac->error, 'no error on UAC' );
ok( $call, 'Call established' );
$cv = AE::cv;
my $timer = AE::timer 1, 0, sub { $cv->send };
$cv->recv;
my $stop = 0;
$cv = AE::cv;
$timer = AE::timer 10, 0, sub { $cv->sned };
$call->bye( cb_final => sub { $stop++; $cv->send } );
$cv->recv;
ok( $stop, 'UAS down' );
}
###############################################
# UAS
###############################################
sub uas {
my ($sock,$pipe) = @_;
Net::SIP::Debug->set_prefix( "DEBUG(uas):" );
my $uas = Net::SIP::Simple->new(
domain => 'example.com',
leg => $sock
) || die $!;
print $pipe "UAS created\n";
# Listen
my $call_closed;
$uas->listen(
cb_create => sub {
my ($call,$request,$leg,$from) = @_;
diag( 'call created' );
my $response = $request->create_response( '180','Ringing' );
$call->{endpoint}->new_response( $call->{ctx},$response,$leg,$from );
1;
},
cb_established => sub { diag( 'call established' ) },
cb_cleanup => sub {
diag( 'call cleaned up' );
$call_closed =1;
},
);
# notify UAC process that I'm listening
print $pipe "UAS ready\n";
# Loop until call is closed, at most 10 seconds
$uas->loop( \$call_closed, 10 );
# done
if ( $call_closed ) {
print $pipe "UAS finished\n";
} else {
print $pipe "call closed by timeout not stopvar\n";
}
}
( run in 3.673 seconds using v1.01-cache-2.11-cpan-d8267643d1d )