ViewVC Help
View File | Revision Log | Show Annotations | Download File
/cvs/cvsroot/Net-XMPP2/samples/disco_test
Revision: 1.1
Committed: Sat Jul 7 12:39:45 2007 UTC (17 years ago) by elmex
Branch: MAIN
Log Message:
fixed some bugs, redesigned disco mechanism, probably added some bugs,
added samples/disco_test example.

File Contents

# Content
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
9 my $j = AnyEvent->condvar;
10 my $cl = Net::XMPP2::Client->new (debug => 1);
11 my $d = Net::XMPP2::Ext::Disco->new;
12 $cl->add_extension ($d);
13 $cl->add_account ('net_xmpp2@jabber.org/test', 'test');
14 $cl->reg_cb (
15 contact_request_subscribe => sub {
16 my ($xmpp, $acc, $roster, $contact, $rdoit) = @_;
17 $$rdoit = 1;
18 $contact->send_subscribe;
19 1
20 },
21 error => sub {
22 my ($cl, $acc, $err) = @_;
23 print "ERROR: " . $err->string . "\n";
24 1
25 },
26 session_ready => sub {
27 my ($cl, $acc) = @_;
28 print "session ready\n";
29 0
30 },
31 message => sub {
32 my ($cl, $acc, $msg) = @_;
33 print "message from: " . $msg->from . ": " . $msg->any_body . "\n";
34 if ($msg->any_body =~ /remove/) {
35 $cl->remove_extension ($d);
36 } elsif ($msg->any_body =~ /add/) {
37 $cl->add_extension ($d);
38 }
39 1
40 }
41 );
42
43 $cl->start;
44 $j->wait;
45