MultiUserChat Invitations to Smack

I have the following code for listening to chat invitations:

Connection.DEBUG_ENABLED = true; XMPPConnection connection = new XMPPConnection("jabber.org"); connection.connect(); connection.login("username", "password"); MultiUserChat.addInvitationListener(connection, new InvitationListener() { @Override public void invitationReceived(Connection arg0, String arg1, String arg2, String arg3, String arg4, Message arg5) { System.out.println("Invitation Received!"); } }); System.out.println("Connected, waiting for invitation"); while(true) { Thread.yield(); } } 

Then I use a different account to log in using pidgin, which creates the chat, and I invite this user. The inviteReceived method is not called. The smack debugger receives an update of presence at login, but no other packages. However, if I logged in to the specified user using pidgin, I get an invitation. How can I get smack to define an invitation request?

+4
source share
2 answers

Maybe I was late to answer this question, but I would like to share my solution here, I had the same problem,

First of all, it depends on which version of smack you are using (I recommended the latest version)

Secondly, the user sending the MUC invitation and inviting the user to the invitation must be connected to the same server in order to receive the MUC invitation.

The third always allows the smack debugger, it will provide information about the incoming and outgoing stanza.

The fourth factor you should consider is to send your presence to the XMPP server after logging in, as shown below,

  connection.setStatus(true,"ONLINE"); public void setStatus(boolean available, String status) throws XMPPException { Presence.Type type = available? Type.available: Type.unavailable; Presence presence = new Presence(type); presence.setStatus(status); connection.sendPacket(presence); } 

sending a presence informs the xmpp server about the status of the user, and then the presence information, as well as a new invitation, will be received if you turned on the listener on the connection object, this works for me, I hope it will work for you too, please correct me if any information is wrong.

+2
source

Perhaps you are using the wrong username from pidgin. You must use a name followed by an email address.

0
source

Source: https://habr.com/ru/post/1384761/


All Articles