AnyEvent-XMPP
view release on metacpan or search on metacpan
lib/AnyEvent/XMPP/Component.pm view on Meta::CPAN
=back
=cut
sub new {
my $this = shift;
my $class = ref($this) || $this;
my %args = @_;
unless (exists $args{initial_presence}) {
$args{stream_namespace} = 'component';
}
$args{host} ||= delete $args{server};
$args{host}
or die "Required 'host' argument missing to new for this component!";
unless (defined $args{port}) {
$args{port} = 5347;
}
my $self = $class->SUPER::new (%args);
$self->{parser}->set_stream_cb (sub {
my $secret = $self->{parser}->{parser}->xml_escape ($self->{secret});
my $id = $self->{stream_id} = $_[0]->attr ('id');
$self->{writer}->send_handshake ($id, $secret);
});
$self->reg_cb (recv_stanza_xml => sub {
my ($self, $node) = @_;
if ($node->eq (component => 'handshake')) {
$self->{authenticated} = 1;
$self->event ('session_ready');
}
},
stream_pre_authentication => sub {
my ($self, $rcon) = @_;
$$rcon = 0;
});
$self
}
sub default_namespace {
return 'component';
}
sub authenticate {
warn "authenticate called! Please read the documentation of "
."AnyEvent::XMPP::Component why this is an error!"
}
=back
=head1 EVENTS
These additional events can be registered on with C<reg_cb>:
NOTE: The event C<stream_pre_authentication> should _not_ be handled
and just ignored. Don't attach callbacks to it!
=over 4
=item session_ready
This event indicates that the component has connected successfully
and can now be used to transmit stanzas.
=back
=head1 AUTHOR
Robin Redeker, C<< <elmex at ta-sa.org> >>, JID: C<< <elmex at jabber.org> >>
=head1 COPYRIGHT & LICENSE
Copyright 2007, 2008 Robin Redeker, all rights reserved.
This program is free software; you can redistribute it and/or modify it
under the same terms as Perl itself.
=cut
1; # End of AnyEvent::XMPP::Component
( run in 1.982 second using v1.01-cache-2.11-cpan-39bf76dae61 )