2
0

dispatch.pl 1.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748
  1. #!/usr/bin/perl
  2. use ESL::Dispatch;
  3. use Data::Dumper;
  4. my $daemon = init ESL::Dispatch({});
  5. my $calls;
  6. # Debug Yo!
  7. #ESL::eslSetLogLevel(7);
  8. $| = 1;
  9. sub worker {
  10. my $self = shift;
  11. print "I'm a worker\n";
  12. }
  13. sub register {
  14. my $self = shift;
  15. my $event = shift;
  16. my $esl = $self->{_esl};
  17. my $contact = $event->{contact};
  18. my $profile = $event->{'profile-name'};
  19. my $callid = $event->{'call-id'};
  20. return if $call->{$callid};
  21. $contact =~ s/.*\<(.*)\>.*/{my_call_id=$callid}sofia\/$profile\/$1/;
  22. $esl->api('bgapi', "originate $contact &echo");
  23. print "Adding $callid to calls hash\n";
  24. $call->{$callid} = 1;
  25. }
  26. sub channel_hangup {
  27. my $self = shift;
  28. my $event = shift;
  29. my $callid = $event->{variable_my_call_id};
  30. print "Removing $callid from calls hash\n";
  31. delete $call->{$callid};
  32. }
  33. $0 = "ESL::Dispatch rocks!";
  34. $daemon->set_worker(\&worker, 2000);
  35. $daemon->set_callback("custom", \&register, 'sofia::register');
  36. $daemon->set_callback("channel_hangup", \&channel_hangup);
  37. $daemon->run;