[Freeswitch-svn] [commit] r5355 - freeswitch/trunk/scripts/contrib/trixter
Freeswitch SVN
trixter at freeswitch.org
Wed Jun 13 18:24:52 EDT 2007
Author: trixter
Date: Wed Jun 13 18:24:52 2007
New Revision: 5355
Added:
freeswitch/trunk/scripts/contrib/trixter/conf-dtmf.pl (contents, props changed)
Log:
example of how to parse dtmf events from event socket via conference::maintainence - requires FreeSWITCH::Client also in scripts
Added: freeswitch/trunk/scripts/contrib/trixter/conf-dtmf.pl
==============================================================================
--- (empty file)
+++ freeswitch/trunk/scripts/contrib/trixter/conf-dtmf.pl Wed Jun 13 18:24:52 2007
@@ -0,0 +1,94 @@
+#!/usr/bin/perl
+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
+
+
+# configure these
+my $password = "ClueCon"; # the password for event socket
+my $host = "localhost"; # the hostname to connect to
+my $port = 8021; # the port to connect to
+my $timeout = 30; # seconds to expect a heartbeat event or reconnect
+
+# 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',
+ );
+
+
+
+##
+# dont touch these
+##
+my $fs;
+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;
+ }
+}
+
+
+sigaction SIGALRM, new POSIX::SigAction sub {
+ if ($lastheartbeat < (time - $timeout)) {
+ print "Did not receive a heartbeat in the specified timeout\n";
+ if (defined $fs) {
+ $fs->disconnect();
+ undef $fs;
+ }
+ es_connect();
+ }
+
+ # reset the alarm
+ alarm $timeout;
+} or die "Error setting SIGALRM handler: $!\n";
+
+
+
+es_connect();
+alarm $timeout;
+
+while (1) {
+ if(defined $fs) {
+ my $reply = $fs->readhash(undef);
+ if ($reply->{socketerror}) {
+ es_connect();
+ }
+
+ if ($reply->{body}) {
+ $myhash = $reply->{event};
+
+ if ($myhash->{'event-name'} eq "HEARTBEAT") { ## Deal with heartbeats
+ $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
+ 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'}}"});
+ } else {
+ $fs->sendmsg({'command' => "api conference $myhash->{'conference-name'} play $soundfile{'default'}"});
+ }
+
+ } 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
+ }
+
+ }
+ }
+}
More information about the Freeswitch-svn
mailing list