views:

29

answers:

2

I was wondering if anyone here can provide some code samples on the following scenarios. I'm particularly interested in using xmpppy to do this as I'm already using the library for my app, but other libraries ok too. It is unfortunate that the xmpppy project website doesn't have any samples on this. Browsing the expert/advanced API docs, I couldn't figure out how to do it, or is multi-user chat (MUC) not supported with xmpppy?

  • create a MUC by inviting specific users (say 2 or 3)

  • send message to an existing MUC (assuming you know it's MUC JID handle or nickname)

  • look up existing MUCs on the XMPP server, getting the JID or nickname, etc. If this is done by getting roster, we want to only look for MUCs, ignoring users.

I found sort of an answer here, but then I'd probably have to learn new library API calls and figure out how to do my above mentioned scenarios as this sample doesn't cover all of them:

http://stackoverflow.com/questions/2364039/pyxmpp-quick-tutorial-for-creating-a-muc-client

I'm really looking to do a load generator that pumps messages to MUCs and creating large MUCs with many participants. I've already got the part in place for pumping messages to user recipients.

A: 

While I dont know about specific MUC interface there, xmpppy supports custom messages, so it supports whole XMPP.

To join chat, you need to send presence stranza, conn.send(xmpp.Presence(to='{0}/{1}'.format(room, nick)))

To send a message to chat:

    stranza = "<message to='{0}' type='groupchat'><body>{1}</body></message>".format(room, text)
    conn.send(stranza)

As for creating new chat or looking it up in roster, I don't have ready code at hand, but it is easy to write in the same fashion, just look up needed stranzas in XEPs:

http://xmpp.org/extensions/xep-0045.html#createroom

http://xmpp.org/extensions/xep-0045.html#disco-rooms

http://xmpp.org/extensions/xep-0045.html#invite

Daniel Kluev
A: 

Xmpppy does support using MUC services, but the support is very basic and some extra code will be needed to manage multiple rooms.

To "join" a MUC room you need to broadcast your presence to the JID.

conn.send(xmpp.Presence(to="%s/%s" % (room, nickname)))

Then to send messages, you send them using the 'groupchat' message type to the room JID.

msg = xmpp.protocol.Message(body=text)
msg.setTo(room)
msg.setType('groupchat')
conn.send(msg)

As for your question regarding finding MUC rooms, that'll be done via service discovery.

Andrew Williams