NAME

Net::XMPP2::Ext::MUC - Implements XEP-0045: Multi-User Chat

SYNOPSIS

my $con = Net::XMPP2::Connection->new (...);
$con->add_extension (my $disco = Net::XMPP2::Ext::Disco->new);
$con->add_extension (
   my $muc = Net::XMPP2::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 Net::XMPP2::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 Net::XMPP2::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 Net::XMPP2::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 Net::XMPP2::Ext::MUC::Room object (the one of the joined room) and the second is a Net::XMPP2::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 Net::XMPP2::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.

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 the did_create_room statusflag on your own instance of Net::XMPP2::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 and request_configuration methods of Net::XMPP2::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 Net::XMPP2::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 Net::XMPP2::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 Net::XMPP2::Connection the MUC operates on, the second is always the Net::XMPP2::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 Net::XMPP2::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 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.