--- /dev/null
+package Display::Plugins::Asterisk;
+
+use base ("Display::Plugin");
+
+use strict;
+use Carp;
+
+use POE qw( Component::Client::Asterisk::Manager );
+use Data::Dumper;
+
+sub new {
+ my $proto = shift;
+ my $class = ref($proto) || $proto;
+
+ my $self = $class->SUPER::new(@_);
+
+ bless ($self, $class);
+
+ $self->{'kernel'}->state('asterisk_delayed_start', $self, 'delayed_start');
+
+ POE::Component::Client::Asterisk::Manager->new(
+ Alias => 'asterisk',
+ RemoteHost => $self->{config}{_config}{plugins}{Asterisk}{RemoteHost},
+ RemotePort => $self->{config}{_config}{plugins}{Asterisk}{RemotePort},
+ Username => $self->{config}{_config}{plugins}{Asterisk}{Username},
+ Password => $self->{config}{_config}{plugins}{Asterisk}{Password},
+
+ CallBacks => {
+ asterisk_ring => {
+ 'Event' => 'Newchannel',
+ 'State' => 'Ring'
+ },
+ asterisk_ringing => {
+ 'Event' => 'Newstate',
+ 'State' => 'Ringing',
+ },
+ asterisk_hangup => {
+ 'Event' => 'Hangup'
+ },
+ asterisk_input => ':all',
+ },
+
+ inline_states => {
+ # When we're connected to Asterisk, post back to the main session for the rest of
+ # out states to be setup in asterisk_start. This is to make sure the states are
+ # created in the correct session with a reference to $self.
+ _connected => sub { $self->{'kernel'}->post('display' => 'asterisk_delayed_start') },
+ asterisk_start => sub {
+ my ($kernel, $self) = @_[KERNEL, ARG0];
+
+ $kernel->state('asterisk_input', $self, 'input');
+ $kernel->state('asterisk_ring', $self, 'ring');
+ $kernel->state('asterisk_ringing', $self, 'ringing');
+ $kernel->state('asterisk_hangup', $self, 'hangup');
+ },
+ },
+ );
+
+ return $self;
+}
+
+sub delayed_start {
+ my ($self) = shift;
+
+ $self->{'kernel'}->post('asterisk_client' => 'asterisk_start' => $self);
+}
+
+sub ring {
+ my ($self, $kernel, $session, $input) = @_[OBJECT, KERNEL, SESSION, ARG0];
+
+ print STDERR "RING! $input->{Channel}\n";
+ print Dumper($input);
+}
+
+sub ringing {
+ my ($self, $kernel, $session, $input) = @_[OBJECT, KERNEL, SESSION, ARG0];
+
+ print STDERR "RING, RING! $input->{Channel}, $input->{'CallerID'} , $input->{'CallerIDName'}\n";
+ print Dumper($input);
+}
+
+sub input {
+ my ($self, $kernel, $input) = @_[OBJECT, KERNEL, ARG0];
+
+ print STDERR "Other input - $input->{Event}\n";
+ #print Dumper($input);
+}
+
+sub hangup {
+ my ($self, $kernel, $input) = @_[OBJECT, KERNEL, ARG0];
+}
+
+1;