Skip to content

Instantly share code, notes, and snippets.

@lathspell
Forked from maximevalette/call.pl
Last active August 29, 2015 14:08
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save lathspell/b79ae4641f6e93fe0eb8 to your computer and use it in GitHub Desktop.
Save lathspell/b79ae4641f6e93fe0eb8 to your computer and use it in GitHub Desktop.
#!/usr/bin/env perl
#
# Forked from https://gist.github.com/tupinek/6605090
#
use strict;
use warnings;
use Getopt::Long qw(:config posix_default bundling);
use Net::SIP;
use Net::SIP::Debug qw( Net::SIP*=2 Registrar=1 );
Net::SIP::Debug->level(2);
# Usage.
sub usage {
if (@_) {
print STDERR "ERROR: @_\n";
}
print STDERR <<EOS;
Usage: $0 [options] tel_on_host
Play a file to a phone after the call is answered
Options:
-R|--registrar host[:port] Register at given address
-S|--send filename Audio file
--username name Registration user name.
--password pass Registration user password.
--domain domain Registration user domain.
--proxy ip Outgoing proxy.
--from username From address.
EOS
exit @_ ? 1 : 0;
}
# Arguments.
my ($file, $registrar, $username, $password, $domain, $proxy, $from, $debug);
GetOptions(
'R|registrar=s' => \$registrar,
'S|send=s' => \$file,
'username=s' => \$username,
'password=s' => \$password,
'domain=s' => \$domain,
'proxy=s' => \$proxy,
'from=s' => \$from,
) or usage('Bad option.');
my ($to) = @ARGV;
$to or usage('No destination.');
if (!defined $file || !-r $file) {
usage('No file.');
}
if ( !defined($from) ) {
$from = $username;
}
# Create new agent.
print "Creating connection.\n";
my $ua = Net::SIP::Simple->new(
'outgoing_proxy' => $proxy,
'registrar' => $registrar,
'domain' => $domain,
'from' => $from,
'auth' => [ $username, $password ],
) or die $!;
# Register agent.
print "Registering from=$from on registrar=$registrar.\n";
$ua->register('expires' => 1800) or die( "Not registered '" . $ua->error . "'" );
# Variables d'arret.(sort de loop quand rtp_done est vrai)
print 'Inviting to=' . $to . " using file=$file.\n";
my $rtp_done;
my $call = $ua->invite(
$to,
'init_media' => $ua->rtp( 'send_recv', $file ),
'cb_rtp_done' => \$rtp_done,
'asymetric_rtp' => 0,
'rtp_param' => [ 8, 160, 160 / 8000, 'PCMA/8000' ],
) or die "Invite failed: '" . $ua->error . "'";
# Mainloop.
print "Looping.\n";
$ua->loop(\$rtp_done);
# Bye.
print "Terminating.\n";
$call->bye();
* * * * * root if [ -e /home/maxime/monitoring/call ]; then rm /home/maxime/monitoring/call; /home/maxime/monitoring/call.pl; fi
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment