AnyEvent-XMPP
view release on metacpan or search on metacpan
lib/AnyEvent/XMPP/IM/Connection.pm view on Meta::CPAN
my ($self) = @_;
$self->{roster}
}
sub handle_iq_set {
my ($self, $node, $handled) = @_;
if ($node->find_all ([qw/roster query/])) {
$self->store_roster ($node);
$self->reply_iq_result ($node);
$$handled = 1;
}
}
sub handle_presence {
my ($self, $node) = @_;
if (defined ($node->attr ('to')) && !cmp_bare_jid ($node->attr ('to'), $self->jid)) {
return; # ignore presence that is not for us
}
if ($node->attr ('type') eq 'error') {
my $error = AnyEvent::XMPP::Error::Presence->new (node => $node);
$self->event (presence_error => $error);
return if $error->type ne 'continue';
}
my ($contact, $old, $new) = $self->{roster}->update_presence ($node);
$self->event (presence_update => $self->{roster}, $contact, $old, $new)
}
sub handle_message {
my ($self, $node) = @_;
if ($node->attr ('type') eq 'error') {
my $error = AnyEvent::XMPP::Error::Message->new (node => $node);
$self->event (message_error => $error);
return if $error->type ne 'continue';
}
my $msg = AnyEvent::XMPP::IM::Message->new (connection => $self);
$msg->from_node ($node);
$self->event (message => $msg);
}
sub handle_disconnect {
my ($self) = @_;
delete $self->{roster};
}
=back
=head1 EVENTS
These additional events can be registered on with C<reg_cb>:
In the following events C<$roster> is the L<AnyEvent::XMPP::IM::Roster>
object you get by calling C<get_roster>.
NODE: The first argument to each callback is always the L<AnyEvent::XMPP::IM::Connection>
object itself. Also see L<Object::Event> for more information about registering
callbacks.
=over 4
=item session_ready
This event is generated when the session has been fully established and
can be used to send around messages and other stuff.
=item session_error => $error
If an error happened during establishment of the session this
event will be generated. C<$error> will be an L<AnyEvent::XMPP::Error::IQ>
error object.
=item roster_update => $roster, $contacts
This event is emitted when a roster update has been received.
C<$contacts> is an array reference of L<AnyEvent::XMPP::IM::Contact> objects
which have changed. If a contact was removed it will return 'remove'
when you call the C<subscription> method on it.
The first time this event is sent is when the roster was received
for the first time.
=item roster_error => $error
If an error happened during retrieval of the roster this event will
be generated.
C<$error> will be an L<AnyEvent::XMPP::Error::IQ> error object.
=item presence_update => $roster, $contact, $old_presence, $new_presence
This event is emitted when the presence of a contact has changed.
C<$contact> is the L<AnyEvent::XMPP::IM::Contact> object which presence status
has changed.
C<$old_presence> is a L<AnyEvent::XMPP::IM::Presence> object which represents the
presence prior to the change.
C<$new_presence> is a L<AnyEvent::XMPP::IM::Presence> object which represents the
presence after to the change. The new presence might be undef if the new presence
is 'unavailable'.
=item presence_error => $error
This event is emitted when a presence stanza error was received.
C<$error> will be an L<AnyEvent::XMPP::Error::Presence> error object.
=item message => $msg
This event is emitted when a message was received.
C<$msg> is a L<AnyEvent::XMPP::IM::Message> object.
=item message_error => $error
This event is emitted when a message stanza error was received.
C<$error> will be an L<AnyEvent::XMPP::Error::Message> error object.
=item contact_request_subscribe => $roster, $contact, $message
This event is generated when the C<$contact> wants to subscribe
to your presence.
( run in 0.768 second using v1.01-cache-2.11-cpan-39bf76dae61 )