ViewVC Help
View File | Revision Log | Show Annotations | Download File
/cvs/Net-XMPP2/samples/test_client
Revision: 1.10
Committed: Tue Jul 24 13:35:22 2007 UTC (16 years, 10 months ago) by elmex
Branch: MAIN
CVS Tags: HEAD
Changes since 1.9: +3 -5 lines
Log Message:
changed subscription semantics

File Contents

# Content
1 #!/opt/perl/bin/perl
2 use strict;
3 use utf8;
4 use Event;
5 use AnyEvent;
6 use XML::Twig;
7 use Net::XMPP2 qw/xep-86/;
8 use Net::XMPP2::Client;
9 use Encode;
10
11 binmode STDOUT, ":utf8";
12
13 my $j = AnyEvent->condvar;
14 my $cl = Net::XMPP2::Client->new (debug => 1);
15 $cl->set_presence ('away', 'I\'m a bot now.', 1);
16 $cl->add_account (@ARGV);
17 $cl->reg_cb (
18 connected => sub {
19 $cl->send_message ("Hello!" => 'elmex@jabber.org');
20 0
21 },
22 roster_update => sub {
23 my ($cl, $acc, $roster, $contacts) = @_;
24 $roster->debug_dump;
25 #$acc->connection ()->send_presence ('probe' => undef, to => 'elmex@jabfber.org');
26 #print "OEOFWEFIEJWFEWO\n" if not $roster->is_retrieved;
27 1
28 },
29 presence_update => sub {
30 my ($cl, $acc, $roster, $contact, $old, $new) = @_;
31 $roster->debug_dump;
32 1
33 },
34 error => sub {
35 my ($cl, $acc, $error) = @_;
36 print "ERROR: ".$error->string."\n";
37 },
38 disconnect => sub { warn "DISCON[@_]\n"; 1 },
39 );
40
41 $cl->reg_cb (contact_request_subscribe => sub {
42 my ($cl, $acc, $roster, $contact) = @_;
43 $contact->send_subscribe;
44 0
45 });
46
47 $cl->reg_cb (contact_did_unsubscribe => sub {
48 my ($cl, $acc, $roster, $contact, $rdoit) = @_;
49 1
50 });
51
52 $cl->reg_cb (roster_update => sub {
53 my ($cl, $acc, $roster, $contacts) = @_;
54 $roster->debug_dump;
55 0
56 });
57
58 $cl->start;
59
60 $j->wait;