[Freeswitch-svn] [commit] r5467 - freeswitch/trunk/scripts/contrib/trixter
Freeswitch SVN
trixter at freeswitch.org
Tue Jun 26 01:36:01 EDT 2007
Author: trixter
Date: Tue Jun 26 01:36:01 2007
New Revision: 5467
Modified:
freeswitch/trunk/scripts/contrib/trixter/conf-dtmf.pl
Log:
updated conf-dtmf.pl to reconnect with unpatched Client.pm
Modified: freeswitch/trunk/scripts/contrib/trixter/conf-dtmf.pl
==============================================================================
--- freeswitch/trunk/scripts/contrib/trixter/conf-dtmf.pl (original)
+++ freeswitch/trunk/scripts/contrib/trixter/conf-dtmf.pl Tue Jun 26 01:36:01 2007
@@ -1,4 +1,5 @@
#!/usr/bin/perl
+# -*- mode:cperl; tab-width:4; c-basic-offset:4; c-indent-level:4; indent-tabs-mode:nil; -*-
use FreeSWITCH::Client;
use POSIX ':signal_h'; # used for alarm to ensure we get heartbeats
use Data::Dumper; # used to print out myhash debug info
@@ -12,9 +13,9 @@
# hash for music, default must be defined, if you define other entities then the conference name will be used to match against that
my %soundfile = (
- 'default' => '/sounds/fpm-calm-river.wav',
- '123' => '/sounds/welcome.raw',
- );
+ 'default' => '/sounds/fpm-calm-river.wav',
+ '123' => '/sounds/welcome.raw',
+ );
@@ -25,31 +26,35 @@
my $lastheartbeat;
-
# this connects to the event socket
sub es_connect()
-{
+ {
print "Connecting to $host:$port\n";
- $fs = init FreeSWITCH::Client {-password => $password, -host => $host, -port => $port};
- if(defined $fs) {
- $fs->sendmsg({'command' => 'event plain heartbeat CUSTOM conference::maintenence'});
- $lastheartbeat = time;
+ eval {
+ $fs = init FreeSWITCH::Client {-password => $password, -host => $host, -port => $port};
+ if(defined $fs) {
+ $fs->sendmsg({'command' => 'event plain heartbeat CUSTOM conference::maintenence'});
+ $lastheartbeat = time;
+ }
+ } or do {
+ print "Error connecting - waiting for retry\n";
}
-}
+
+ }
sigaction SIGALRM, new POSIX::SigAction sub {
- if ($lastheartbeat < (time - $timeout)) {
+ if ($lastheartbeat < (time - $timeout)) {
print "Did not receive a heartbeat in the specified timeout\n";
if (defined $fs) {
- $fs->disconnect();
- undef $fs;
+ $fs->disconnect();
+ undef $fs;
}
es_connect();
- }
-
- # reset the alarm
- alarm $timeout;
+ }
+
+ # reset the alarm
+ alarm $timeout;
} or die "Error setting SIGALRM handler: $!\n";
@@ -59,36 +64,37 @@
while (1) {
if(defined $fs) {
- my $reply = $fs->readhash(undef);
- if ($reply->{socketerror}) {
+ my $reply = $fs->readhash(undef);
+ if ($reply->{socketerror}) {
es_connect();
- }
+ }
- if ($reply->{body}) {
+ if ($reply->{body}) {
$myhash = $reply->{event};
-
+
if ($myhash->{'event-name'} eq "HEARTBEAT") { ## Deal with heartbeats
- $lastheartbeat = time;
- print "Got a heartbeat\n";
-
+ $lastheartbeat = time;
+ print "Got a heartbeat\n";
+
} elsif ($myhash->{'event-subclass'} eq "conference::maintenence") { ## deal with Conference stuff
-
- if($myhash->{'action'} eq 'dtmf') { ## DTMF event
+
+ if($myhash->{'action'} eq 'dtmf') { ## DTMF event
print "conf: $myhash->{'conference-name'}\tmember: $myhash->{'member-id'}\tDTMF: $myhash->{'dtmf-key'}\n";
if(defined $soundfile{$myhash->{'conference-name'}}) {
- $fs->sendmsg({'command' => "api conference $myhash->{'conference-name'} play $soundfile{$myhash->{'conference-name'}}"});
+ $fs->sendmsg({'command' => "api conference $myhash->{'conference-name'} play $soundfile{$myhash->{'conference-name'}}"});
} else {
- $fs->sendmsg({'command' => "api conference $myhash->{'conference-name'} play $soundfile{'default'}"});
+ $fs->sendmsg({'command' => "api conference $myhash->{'conference-name'} play $soundfile{'default'}"});
}
- } else { ## Just print out all other events
+ } else { ## Just print out all other events
print "conf: $myhash->{'conference-name'}\tmemid: $myhash->{'member-id'}\taction: $myhash->{'action'}\tCLID: $myhash->{'caller-caller-id-number'}\n";
- }
+ }
} else { ## Unknown event
- print Dumper $myhash;
-# print "$reply->{body}\n"; # print out what was sent, myhash is translated by Client.pm
+ print Dumper $myhash;
+ # print "$reply->{body}\n"; # print out what was sent, myhash is translated by Client.pm
}
- }
+ }
}
}
+
More information about the Freeswitch-svn
mailing list