1 package Display::Plugins::Asterisk;
3 use base ("Display::Plugin");
8 use POE qw( Component::Client::Asterisk::Manager );
15 my $class = ref($proto) || $proto;
17 my $self = $class->SUPER::new(@_);
19 bless ($self, $class);
21 $self->{'logo'} = Clutter::Texture->new("$Bin/share/Asterisk.png");
23 $self->{'kernel'}->state('asterisk_delayed_start', $self, 'delayed_start');
25 POE::Component::Client::Asterisk::Manager->new(
27 RemoteHost => $self->{config}{_config}{plugins}{Asterisk}{RemoteHost},
28 RemotePort => $self->{config}{_config}{plugins}{Asterisk}{RemotePort},
29 Username => $self->{config}{_config}{plugins}{Asterisk}{Username},
30 Password => $self->{config}{_config}{plugins}{Asterisk}{Password},
34 'Event' => 'Newchannel',
38 'Event' => 'Newstate',
47 asterisk_input => ':all',
51 # When we're connected to Asterisk, post back to the main session for the rest of
52 # out states to be setup in asterisk_start. This is to make sure the states are
53 # created in the correct session with a reference to $self.
54 _connected => sub { $self->{'kernel'}->post('display' => 'asterisk_delayed_start') },
55 asterisk_start => sub {
56 my ($kernel, $self) = @_[KERNEL, ARG0];
58 $kernel->state('asterisk_input', $self, 'input');
59 $kernel->state('asterisk_ring', $self, 'ring');
60 $kernel->state('asterisk_ringing', $self, 'ringing');
61 $kernel->state('asterisk_hangup', $self, 'hangup');
62 $kernel->state('asterisk_dial', $self, 'dial');
73 $self->{'kernel'}->post('asterisk_client' => 'asterisk_start' => $self);
77 my ($self, $kernel, $session, $input) = @_[OBJECT, KERNEL, SESSION, ARG0];
79 print STDERR "RING! $input->{Channel}\n";
84 my ($self, $kernel, $session, $input) = @_[OBJECT, KERNEL, SESSION, ARG0];
86 print STDERR "RING, RING! $input->{Channel}, $input->{'CallerID'} , $input->{'CallerIDName'}\n";
91 my ($self, $kernel, $input) = @_[OBJECT, KERNEL, ARG0];
93 print STDERR "Other input - $input->{Event}\n";
98 my ($self, $kernel, $input) = @_[OBJECT, KERNEL, ARG0];
102 my ($self, $kernel, $input) = @_[OBJECT, KERNEL, ARG0];
104 my $dest = $input->{Destination};
105 $dest =~ s/(.*)-.*/$1/;
107 my $text = Clutter::Label->new('Sans 20', "Call from " . $input->{CallerIDName} . "\n " . $input->{CallerID} . "\nFor $dest");
108 $text->set_color(Clutter::Color->parse('White'));
109 $text->set_ellipsize('end');
111 $kernel->post('display', 'notifications_add', $text, $self->{'logo'});