Skip to content

Instantly share code, notes, and snippets.

@jbarber
Created April 2, 2015 14:49
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 jbarber/42bb0d70bbab84728929 to your computer and use it in GitHub Desktop.
Save jbarber/42bb0d70bbab84728929 to your computer and use it in GitHub Desktop.
Example of Net::SIP and AnyEvent with hanging up caller
#!/usr/bin/env perl
# Make call when program receives SIGHUP, hangup when call is answered
use strict;
use warnings;
use 5.10.0;
use Net::SIP 0.687;
#use Net::SIP::Debug 1;
use AnyEvent::SIP 0.002;
my $proxy = 'voip.example.com';
my $user = 'example';
my $secret = 's3cr3t!';
# Create agent
my $ua = Net::SIP::Simple->new(
outgoing_proxy => $proxy,
registrar => $proxy,
domain => $proxy,
from => $user,
auth => [ $user, $secret ]
);
# Register
$ua->register;
# Listen for HUP signal, when recieved call the Net::SIP::Simple invite method
my $w = AnyEvent->signal(
signal => "HUP",
cb => sub {
$ua->invite(
'555-111-000',
# Hangup when media starts playing
init_media => sub { $_[0]->bye() },
# Empty callback - stops Net::SIP from calling loop() which causes
# an AnyEvent recursive call
cb_final => sub { },
)
}
);
# Run forever
AnyEvent->condvar->recv;
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment