File: dtmf.pl

package info (click to toggle)
libnet-sip-perl 0.66-1
  • links: PTS, VCS
  • area: main
  • in suites: wheezy
  • size: 944 kB
  • sloc: perl: 8,988; makefile: 7
file content (49 lines) | stat: -rw-r--r-- 1,159 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49

use strict;
use warnings;

use Net::SIP;
use Net::SIP::Debug;
use Getopt::Long qw(:config posix_default bundling);


my $debug = 100;
my $from  = 'sip:100@192.168.56.1';
my $to    = 'sip:*69@192.168.56.101';
my $user  = '100';
my $pass  = 'password1234'; 
my $outf  = 'record.raw';
my $hangup = 30; # hang up after 30 sec
my $dtmf  = 'ABCD*#123--4567890';

Net::SIP::Debug->level($debug);
my $leg = Net::SIP::Leg->new( addr => '192.168.56.1' );
my $ua = Net::SIP::Simple->new(
	from => $from,
	auth => [ $user,$pass ],
	leg  => $leg,
);

# invite peer
my $peer_hangup; # did peer hang up?
my $call = $ua->invite( $to,
	# echo back, use -1 instead of 0 for not echoing back
	init_media => $ua->rtp( 'recv_echo',$outf,0 ),
	recv_bye => \$peer_hangup,
) || die "invite failed: ".$ua->error;
die "invite failed(call): ".$call->error if $call->error;

my $dtmf_done;
$call->dtmf( $dtmf, cb_final => \$dtmf_done );

my $stopvar;
$ua->add_timer($hangup,\$stopvar);
$ua->loop( \$stopvar,\$peer_hangup,\$dtmf_done );

# timeout or dtmf done, hang up
if ( $stopvar || $dtmf_done ) {
	$stopvar = undef;
	$call->bye( cb_final => \$stopvar );
	$ua->loop( \$stopvar );
}