#!/usr/bin/perl
use strict;
use warnings;
use IO::Socket::INET;
my $ip = "127.0.0.1";
my $sock = new IO::Socket::INET ( LocalHost => $ip,
LocalPort => '8040',
Proto => 'tcp',
Listen => 1,
Reuse => 1 );
die "Could not create socket: $!\n" unless $sock;
my $host = "127.0.0.1";
my $port = "8021";
my $pass = "ClueCon";
my $con2 = new ESL::ESLconnection($host, $port, $pass);
for(;;) {
my $new_sock = $sock->accept();
if ($pid) {
print "New child pid $pid created...\n";
next;
}
my $con = new ESL::ESLconnection($fd);
my $info = $con->getInfo();
my $uuid = $info->getHeader("unique-id");
printf "Connected call %s, from %s\n", $uuid, $info->getHeader("caller-caller-id-number");
$con->execute("set", "hangup_after_bridge=false");
$con->execute("set", "continue_on_fail=true");
$con->execute("set", "ignore_early_media=true");
$con->execute("answer");
$con->execute("playback","ivr/ivr-welcome_to_freeswitch.wav");
$con->execute("sleep","500");
my $con2 = new ESL::ESLconnection($host, $port, $pass);
my $out_uuid = $con2->api('create_uuid')->getBody();
my $out_job = $con2->bgapi("originate", "{ignore_early_media=true,hangup_after_bridge=false,continue_on_fail=false,originate_timeout=30,origination_uuid=$out_uuid}sofia/gateway/eliza-outbound/0410001000 9664");
my $job_uuid = $out_job->getHeader("Job-UUID");
print "Call to coach. Job-UUID : $job_uuid, call uuid : $uuid, out_uuid : $out_uuid \n";
my $stay_connected = 1;
$con2->events("plain","all");
while($stay_connected) {
my $e = $con2->recvEvent();
if($e) {
my $ev_uuid = $e->getHeader("Unique-ID");
if ( $ev_uuid && ($ev_uuid eq $out_uuid) ) {
if ( $e->getHeader("Answer-State") eq "answered" ) {
print "Out call $out_uuid got answered!!!\n\n";
} else {
print "Answer State : ".$e->getHeader("Answer-State")."\n";
}
} else {
#nothing...
}
} else {
#$con->execute("set", "playback_timeout_sec=20");
#$con->execute("playback",'$${hold_music}');
}
}
BREAKLOOP:
#$con2->execute('uuid_break',"$out_uuid");
$con2->api("uuid_bridge $uuid $out_uuid");
$con->execute("hangup");
$con->disconnect();
$con2->disconnect();
}
{"html5":"htmlmixed","css":"css","javascript":"javascript","php":"php","python":"python","ruby":"ruby","lua":"text\/x-lua","bash":"text\/x-sh","go":"go","c":"text\/x-csrc","cpp":"text\/x-c++src","diff":"diff","latex":"stex","sql":"sql","xml":"xml","apl":"apl","asterisk":"asterisk","c_loadrunner":"text\/x-csrc","c_mac":"text\/x-csrc","coffeescript":"text\/x-coffeescript","csharp":"text\/x-csharp","d":"d","ecmascript":"javascript","erlang":"erlang","groovy":"text\/x-groovy","haskell":"text\/x-haskell","haxe":"text\/x-haxe","html4strict":"htmlmixed","java":"text\/x-java","java5":"text\/x-java","jquery":"javascript","mirc":"mirc","mysql":"sql","ocaml":"text\/x-ocaml","pascal":"text\/x-pascal","perl":"perl","perl6":"perl","plsql":"sql","properties":"text\/x-properties","q":"text\/x-q","scala":"scala","scheme":"text\/x-scheme","tcl":"text\/x-tcl","vb":"text\/x-vb","verilog":"text\/x-verilog","yaml":"text\/x-yaml","z80":"text\/x-z80"}