ViewVC Help
View File | Revision Log | Show Annotations | Download File
/cvs/cvsroot/Net-XMPP2/samples/disco_test
Revision: 1.3
Committed: Tue Jul 24 12:31:15 2007 UTC (16 years, 11 months ago) by elmex
Branch: MAIN
CVS Tags: HEAD
Changes since 1.2: +1 -4 lines
Log Message:
documentation update

File Contents

# User Rev Content
1 elmex 1.1 #!/opt/perl/bin/perl
2     use strict;
3     use utf8;
4     use Event;
5     use AnyEvent;
6     use Net::XMPP2::Client;
7     use Net::XMPP2::Ext::Disco;
8 elmex 1.2 use Net::XMPP2::Ext::DataForm;
9 elmex 1.1
10     my $j = AnyEvent->condvar;
11     my $cl = Net::XMPP2::Client->new (debug => 1);
12     my $d = Net::XMPP2::Ext::Disco->new;
13     $cl->add_extension ($d);
14     $cl->add_account ('net_xmpp2@jabber.org/test', 'test');
15     $cl->reg_cb (
16     contact_request_subscribe => sub {
17     my ($xmpp, $acc, $roster, $contact, $rdoit) = @_;
18     $$rdoit = 1;
19     $contact->send_subscribe;
20     },
21     error => sub {
22     my ($cl, $acc, $err) = @_;
23     print "ERROR: " . $err->string . "\n";
24     },
25     session_ready => sub {
26     my ($cl, $acc) = @_;
27 elmex 1.2 $d->request_info ($acc->connection (), 'ukaetec@conference.jabber.org', undef, sub {
28     my ($d, $i, $e) = @_;
29     my (@q) = $i->xml_node ()->find_all ([qw/data_form x/]);
30     return unless @q;
31     my $df = Net::XMPP2::Ext::DataForm->new;
32     $df->from_node (@q);
33     print "occupants: " . $df->get_field ('muc#roominfo_occupants')->{values}->[0] . "\n";
34     });
35 elmex 1.1 print "session ready\n";
36 elmex 1.3 $cl->unreg_me
37 elmex 1.1 },
38     message => sub {
39     my ($cl, $acc, $msg) = @_;
40     print "message from: " . $msg->from . ": " . $msg->any_body . "\n";
41     if ($msg->any_body =~ /remove/) {
42     $cl->remove_extension ($d);
43     } elsif ($msg->any_body =~ /add/) {
44     $cl->add_extension ($d);
45     }
46     }
47     );
48    
49     $cl->start;
50     $j->wait;
51