#!/opt/perl/bin/perl use strict; use utf8; use Event; use AnyEvent; use Net::XMPP2::Client; use Net::XMPP2::Ext::Disco; use Net::XMPP2::Ext::DataForm; my $j = AnyEvent->condvar; my $cl = Net::XMPP2::Client->new (debug => 1); my $d = Net::XMPP2::Ext::Disco->new; $cl->add_extension ($d); $cl->add_account ('net_xmpp2@jabber.org/test', 'test'); $cl->reg_cb ( contact_request_subscribe => sub { my ($xmpp, $acc, $roster, $contact, $rdoit) = @_; $$rdoit = 1; $contact->send_subscribe; 1 }, error => sub { my ($cl, $acc, $err) = @_; print "ERROR: " . $err->string . "\n"; 1 }, session_ready => sub { my ($cl, $acc) = @_; $d->request_info ($acc->connection (), 'ukaetec@conference.jabber.org', undef, sub { my ($d, $i, $e) = @_; my (@q) = $i->xml_node ()->find_all ([qw/data_form x/]); return unless @q; my $df = Net::XMPP2::Ext::DataForm->new; $df->from_node (@q); print "occupants: " . $df->get_field ('muc#roominfo_occupants')->{values}->[0] . "\n"; }); print "session ready\n"; 0 }, message => sub { my ($cl, $acc, $msg) = @_; print "message from: " . $msg->from . ": " . $msg->any_body . "\n"; if ($msg->any_body =~ /remove/) { $cl->remove_extension ($d); } elsif ($msg->any_body =~ /add/) { $cl->add_extension ($d); } 1 } ); $cl->start; $j->wait;