NAME
AnyEvent::XMPP::Ext::MUC - Implements XEP-0045: Multi-User Chat
SYNOPSIS
my $con = AnyEvent::XMPP::Connection->new (...);
$con->add_extension (my $disco = AnyEvent::XMPP::Ext::Disco->new);
$con->add_extension (
my $muc = AnyEvent::XMPP::Ext::MUC->new (disco => $disco, connection => $con)
);
...
DESCRIPTION
This module handles multi user chats and provides new events to catch multi user chat messages. It intercepts messages from the connection so they don't interfere with your other callbacks on the connection.
This extension requires the AnyEvent::XMPP::Ext::Disco extension for service discovery.
METHODS
- new
-
This is the constructor for a pubsub object. It takes no further arguments.
- is_conference ($jid, $cb)
-
TODO
- is_room ($jid, $cb)
-
This method sends a information discovery to the
$jid
.$cb
is called when the information arrives or with an error after the usual IQ timeout.When the
$jid
was a room$cb
is called with the first argument being a AnyEvent::XMPP::Ext::MUC::RoomInfo object. If the destination wasn't reachable, the room doesn't exist or some other error happened the first argument will be undefined and the second a AnyEvent::XMPP::Error::IQ object. - join_room ($jid, $nick, $cb, %args)
-
This method joins a room.
$jid
should be the bare jid of the room.$nick
should be your desired nickname in the room.$cb
is called upon successful entering the room or if an error occured. If no error occured the first argument is a AnyEvent::XMPP::Ext::MUC::Room object (the one of the joined room) and the second is a AnyEvent::XMPP::Ext::MUC::User object, the one of yourself. And the third argument is undef.If an error occured and we couldn't join the room, the first two arguments are undef and the third is a AnyEvent::XMPP::Error::MUC object signalling the error.
%args
hash can contain one of the following keys:- timeout => $timeout_in_secs
-
This is the timeout for joining the room. The default timeout is 60 seconds if the timeout is not specified.
- history => {}
-
Manage MUC-history from XEP-0045 (7.1.16) Hash can contain of the following keys:
chars
,stanzas
,seconds
Example:
history => {chars => 0} # don't load history history => {stanzas => 3} # load last 3 history elements history => {seconds => 300, chars => 500} # load history in last 5 minutes, but max 500 characters
TODO: add
since
attributes - create_instant => $bool
-
If you set
$bool
to a true value we try to establish an instant room on joining if it doesn't already exist.The default for this flag is true! So if you want to creat an reserved room with custom creation in the beginning you have to pass a false value as
$bool
.PLEASE NOTE: If you set
$bool
to a false value you have to check thedid_create_room
statusflag on your own instance of AnyEvent::XMPP::Ext::MUC::User (provided as the second argument to the callback) to see whether you need to finish room creation! If you don't do this the room may stay LOCKED for ever.See also the
make_instant
andrequest_configuration
methods of AnyEvent::XMPP::Ext::MUC. - password => $password
-
The password for the room.
- nickcollision_cb => $cb
-
If the join to the room results in a nickname collision the
$cb
will be called with the nickname that collided and the return value will be used as alternate nickname and the join is retried.This function is called everytime the nickname collides on join, so you should take care of possible endless retries.
- get_room ($jid)
-
This returns the AnyEvent::XMPP::Ext::MUC::Room object for the bare part of the
$jid
if we are joining or have joined such a room.If we are not joined undef is returned.
- is_connected
-
This returns whether we are still connected and can send messages.
EVENTS
All events from AnyEvent::XMPP::Ext::MUC::Room instances that were joined with this MUC are forwarded to this object. The events from the room are prefixed with 'room_' and the first argument is always the AnyEvent::XMPP::Connection the MUC operates on, the second is always the AnyEvent::XMPP::Ext::MUC::Room object and the rest of the argument corresponds to the arguments of the event of the room. See the event description for AnyEvent::XMPP::Ext::MUC::Room for details which events are generated. Generally, if you want for example to get the joined event:
$muc->reg_cb (room_enter => sub {
my ($muc, $con, $room) = @_;
# ...
});
These additional events can be registered on with reg_cb
:
AUTHOR
Robin Redeker, <elmex at ta-sa.org>
, JID: <elmex at jabber.org>
COPYRIGHT & LICENSE
Copyright 2007, 2008 Robin Redeker, all rights reserved.
This program is free software; you can redistribute it and/or modify it under the same terms as Perl itself.