Search code examples
androidopenfiresmackmultiuserchat

Invitation Listener not working smack 4.2


I can create group chat room successfully XMPP(smack). I have added invitation listener, but never called. Does anyone know how to do it?

Using:

  1. XMPP
  2. Smack 4.2
  3. Openfire server

Send Invitation code:

 muc.invite(userId +"@" +XMPP.getInstance().HOST + "/Smack", "Meet me in this excellent room");

Invitation listener code:

         MultiUserChatManager manager = MultiUserChatManager.getInstanceFor(connection);
            manager.addInvitationListener(new InvitationListener() {
                @Override
                public void invitationReceived(XMPPConnection xmppConnection, MultiUserChat muc, String inviter, String reason, String password, Message message) {
                    try {
                        muc.join(nickname);
                    } catch (SmackException.NoResponseException e) {
                        e.printStackTrace();
                    } catch (XMPPException.XMPPErrorException e) {
                        e.printStackTrace();
                    } catch (SmackException.NotConnectedException e) {
                        e.printStackTrace();
                    }
                }
            });

Solution

  • Probably you have an issue about RESOURCE.

    When you send an invitation to a certain JID, you might omit resource part or the message will be sent only to specified resource.

    JID it's composed in following way:

    user@serverdomain/resource
    

    With this invitation, you are inviting only user using "Smack" as Resource. Resource it's configurated in AbstractXMPPConnection object or in login phase

    XMPPTCPConnectionConfiguration.builder()
                    .setServiceName(serverName)
                    .setHost(server)
                    .setPort(port)
                    .setResource( RESOURCE_IDENTIFIER)
                    .build();
    connection = new XMPPTCPConnection(config);
    
    connection.login(username, password, RESOURCE_IDENTIFIER);
    

    So, probably, you declared as your resource identificator (just an arbitrary String) not "Smack" but "Spark" o something else or left default one.

    Just omit Resource part (or fix with correct one, but I suggest to omit)

     muc.invite(userId +"@" +XMPP.getInstance().HOST, "Meet me in this excellent room");
    

    Of course, userId must exist and HOST it's the valid one