ViewVC Help
View File | Revision Log | Show Annotations | Download File
/cvs/cvsroot/Net-XMPP2/samples/disco_test
Revision: 1.2
Committed: Sun Jul 8 20:56:01 2007 UTC (17 years ago) by elmex
Branch: MAIN
Changes since 1.1: +9 -0 lines
Log Message:
added some more examples  ... err.. utilities

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     1
21     },
22     error => sub {
23     my ($cl, $acc, $err) = @_;
24     print "ERROR: " . $err->string . "\n";
25     1
26     },
27     session_ready => sub {
28     my ($cl, $acc) = @_;
29 elmex 1.2 $d->request_info ($acc->connection (), 'ukaetec@conference.jabber.org', undef, sub {
30     my ($d, $i, $e) = @_;
31     my (@q) = $i->xml_node ()->find_all ([qw/data_form x/]);
32     return unless @q;
33     my $df = Net::XMPP2::Ext::DataForm->new;
34     $df->from_node (@q);
35     print "occupants: " . $df->get_field ('muc#roominfo_occupants')->{values}->[0] . "\n";
36     });
37 elmex 1.1 print "session ready\n";
38     0
39     },
40     message => sub {
41     my ($cl, $acc, $msg) = @_;
42     print "message from: " . $msg->from . ": " . $msg->any_body . "\n";
43     if ($msg->any_body =~ /remove/) {
44     $cl->remove_extension ($d);
45     } elsif ($msg->any_body =~ /add/) {
46     $cl->add_extension ($d);
47     }
48     1
49     }
50     );
51    
52     $cl->start;
53     $j->wait;
54