AnyEvent-XMPP
view release on metacpan or search on metacpan
lib/AnyEvent/XMPP/SimpleConnection.pm view on Meta::CPAN
my ($fh, $peerhost, $peerport) = @_;
unless ($fh) {
$self->disconnect ("Couldn't create socket to $host:$service: $!");
return;
}
$self->{peer_host} = $peerhost;
$self->{peer_port} = $peerport;
binmode $fh, ":raw";
$self->{handle} =
AnyEvent::Handle->new (
fh => $fh,
on_eof => sub {
$self->disconnect ("EOF on connection to $self->{peer_host}:$self->{peer_port}: $!");
},
autocork => 1,
on_error => sub {
$self->disconnect ("Error on connection to $self->{peer_host}:$self->{peer_port}: $!");
samples/disco_info view on Meta::CPAN
#!/opt/perl/bin/perl
use strict;
use utf8;
use AnyEvent;
use AnyEvent::XMPP::Client;
use AnyEvent::XMPP::Ext::Disco;
use AnyEvent::XMPP::Ext::DataForm;
use AnyEvent::XMPP::Ext::Version;
use AnyEvent::XMPP::Namespaces qw/xmpp_ns/;
binmode STDOUT, ":utf8";
my ($jid, $pw, $discodest, $disconode) = @ARGV;
unless (@ARGV >= 3) {
warn "usage: disco_info <jid> <password> <disco-request-destination-jid> [<disco-node>]\n";
exit;
}
my $j = AnyEvent->condvar;
my $cl = AnyEvent::XMPP::Client->new (debug => 1);
samples/display_avatar view on Meta::CPAN
$cl->add_account (@ARGV, undef, undef, {
initial_presence => -1, dont_retrieve_roster => 1
});
my $ex = AnyEvent::XMPP::Ext::VCard->new;
$ex->reg_cb (
vcard => sub {
my ($ex, $jid, $vcard) = @_;
if (my $vc = $ex->my_vcard ($jid)) {
open my $av, ">/tmp/net_xmpp2_avatar" or die "couldn't open avatarfile: $!";
binmode $av;
print $av $vc->{_avatar};
close $av;
system ("display /tmp/net_xmpp2_avatar");
}
}
);
$cl->reg_cb (
stream_ready => sub {
my ($cl, $acc) = @_;
$ex->hook_on ($acc->connection);
samples/retrieve_roster view on Meta::CPAN
#!/opt/perl/bin/perl
use strict;
use AnyEvent;
use AnyEvent::XMPP::IM::Connection;
my $DEBUG = 0; # set to 1 if you want to see a protocol dump
my $TIMEOUT = 30; # timeout the whole program after $TIMEOUT seconds
binmode STDOUT, ":utf8";
my ($jid, $pass) = @ARGV;
my $j = AnyEvent->condvar;
my $con =
AnyEvent::XMPP::IM::Connection->new (
jid => $jid,
password => $pass,
initial_presence => -5,
);
samples/store_avatar view on Meta::CPAN
my $j = AnyEvent->condvar;
my $cl = AnyEvent::XMPP::Client->new (debug => 1);
$cl->add_account ($ARGV[0], $ARGV[1], undef, undef, {
initial_presence => -1, dont_retrieve_roster => 1
});
my $ex = AnyEvent::XMPP::Ext::VCard->new;
my $av = do {
open my $av, $ARGV[2] or die "Couldn't open avatar '$ARGV[2]': $!";
local $/;
binmode $av;
<$av>
};
$cl->reg_cb (
session_ready => sub {
my ($cl, $acc) = @_;
print "session ready\n";
$ex->store ($acc->connection, { _avatar => $av }, sub {
my ($e) = @_;
samples/talkbot view on Meta::CPAN
my @msgs;
sub read_messages {
my ($msgs_file) = @_;
open my $f, $msgs_file
or die "Couldn't open messages file: '$msgs_file'\n";
(@msgs) = map { chomp; $_ } <$f>;
close $f;
}
binmode STDOUT, ":utf8";
my ($jid, $pw, $inputfile) = @ARGV;
unless (@ARGV >= 3) {
warn "usage: talkbot <jid> <password> <talkfile>\n";
exit;
}
read_messages ($inputfile);
samples/talkbot_channel view on Meta::CPAN
(@msgs) = map { chomp; $_ } <$f>;
close $f;
}
sub answer_to {
my ($msg) = @_;
my $talkmsg = $msgs[int (rand (@msgs))];
"You said '$msg' but... " . $talkmsg;
}
binmode STDOUT, ":utf8";
my ($jid, $pw, $inputfile, $room) = @ARGV;
unless (@ARGV >= 3) {
warn "usage: talkbot <jid> <password> <talkfile> [<conference room jid>]\n";
exit;
}
read_messages ($inputfile);
samples/test_client view on Meta::CPAN
#!/opt/perl/bin/perl
use strict;
use utf8;
use AnyEvent;
use AnyEvent::XMPP qw/xep-86/;
use AnyEvent::XMPP::Client;
use Encode;
binmode STDOUT, ":utf8";
my $j = AnyEvent->condvar;
my $cl = AnyEvent::XMPP::Client->new (debug => 1);
$cl->set_presence ('away', 'I\'m a bot now.', 1);
$cl->add_account (@ARGV, undef, undef);
$cl->reg_cb (
connected => sub {
$cl->send_message ("Hello!" => 'elmex@jabber.org');
0
},
t/z_07_vcard.t view on Meta::CPAN
my $C = $cl->client;
my $disco = $cl->instance_ext ('AnyEvent::XMPP::Ext::Disco');
my $vcard = $cl->instance_ext ('AnyEvent::XMPP::Ext::VCard');
$disco->enable_feature ($vcard->disco_feature);
my $test_vcard = {
ADR => [{ HOME => undef, LOCALITY => 'Hannover', PCODE => '23422' }],
DESC => ['Just a test vCard for AnyEvent::XMPP'],
NICKNAME => ['elmex'],
FN => ['Robin'],
_avatar => do { open my $av, "t/n_xmpp2_avatar.png" or die "$!"; local $/; binmode $av; <$av> },
_avatar_type => 'image/png'
};
my $error_free_store = 0;
my $returned_vcard;
my $cached_vcard;
my $discofeature;
$C->reg_cb (
session_ready => sub {
t/z_08_vcard_hook.t view on Meta::CPAN
my $cl = AnyEvent::XMPP::TestClient->new_or_exit (tests => 3, finish_count => 1);
my $C = $cl->client;
my $vcard = $cl->instance_ext ('AnyEvent::XMPP::Ext::VCard');
my $got_my_vcard;
my $my_avatar;
my $my_avatar_hash;
open AVATAR, "t/n_xmpp2_avatar.png" or die "Couldn't open avatar: $!";
my $real_avatar = do { local $/; binmode AVATAR; <AVATAR> };
my $real_avatar_hash = sha1_hex ($real_avatar);
close AVATAR;
$C->reg_cb (
stream_ready => sub {
my ($C, $acc) = @_;
$vcard->reg_cb (
vcard => sub {
my ($vcard, $jid, $vc) = @_;
if (my $vc = $vcard->my_vcard ($jid)) {
( run in 0.444 second using v1.01-cache-2.11-cpan-3cd7ad12f66 )