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

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 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 elmex 1.9 my $cl = Net::XMPP2::Client->new (debug => 1);
15 elmex 1.10 $cl->set_presence ('away', 'I\'m a bot now.', 1);
16 elmex 1.8 $cl->add_account (@ARGV);
17 elmex 1.1 $cl->reg_cb (
18     connected => sub {
19 elmex 1.9 $cl->send_message ("Hello!" => 'elmex@jabber.org');
20 elmex 1.1 0
21     },
22 elmex 1.3 roster_update => sub {
23     my ($cl, $acc, $roster, $contacts) = @_;
24     $roster->debug_dump;
25 elmex 1.9 #$acc->connection ()->send_presence ('probe' => undef, to => 'elmex@jabfber.org');
26     #print "OEOFWEFIEJWFEWO\n" if not $roster->is_retrieved;
27 elmex 1.3 1
28     },
29     presence_update => sub {
30     my ($cl, $acc, $roster, $contact, $old, $new) = @_;
31     $roster->debug_dump;
32     1
33     },
34 elmex 1.9 error => sub {
35 elmex 1.7 my ($cl, $acc, $error) = @_;
36 elmex 1.9 print "ERROR: ".$error->string."\n";
37 elmex 1.7 },
38 elmex 1.6 disconnect => sub { warn "DISCON[@_]\n"; 1 },
39 elmex 1.1 );
40    
41 elmex 1.4 $cl->reg_cb (contact_request_subscribe => sub {
42 elmex 1.10 my ($cl, $acc, $roster, $contact) = @_;
43 elmex 1.4 $contact->send_subscribe;
44 elmex 1.10 0
45 elmex 1.4 });
46    
47     $cl->reg_cb (contact_did_unsubscribe => sub {
48     my ($cl, $acc, $roster, $contact, $rdoit) = @_;
49     1
50     });
51    
52 elmex 1.3 $cl->reg_cb (roster_update => sub {
53     my ($cl, $acc, $roster, $contacts) = @_;
54 elmex 1.9 $roster->debug_dump;
55 elmex 1.3 0
56     });
57    
58 elmex 1.1 $cl->start;
59    
60     $j->wait;