sock.pl 866 B

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849
  1. #!/usr/bin/perl
  2. use FreeSWITCH::Client;
  3. use Data::Dumper;
  4. my $fs = init FreeSWITCH::Client {} or die "Error $@";
  5. my $pid;
  6. for (;;) {
  7. $fs->accept();
  8. if (!($pid = fork)) {
  9. last;
  10. }
  11. }
  12. my $data = $fs->call_data();
  13. #print Dumper $data
  14. print "Call: $data->{'caller-channel-name'} $data->{'unique-id'}\n";
  15. $o = $fs->call_command("answer");
  16. #to turn on events when in async mode
  17. $o = $fs->raw_command("myevents");
  18. $o = $fs->call_command("playback", "/ram/swimp.raw");
  19. #comment exit in async mode
  20. #exit;
  21. while(my $r = $fs->readhash(undef)) {
  22. if ($r->{socketerror}) {
  23. last;
  24. }
  25. if ($r->{has_event}) {
  26. print Dumper $r->{event};
  27. }
  28. if ($r->{event}->{'event-name'} !~ /execute/i) {
  29. printf "uuid: $data->{'unique-id'}\n";
  30. $o = $fs->call_command("break");
  31. $o = $fs->call_command("hangup");
  32. }
  33. }
  34. $fs->disconnect();
  35. print "done\n";