1
votes

I want to send the following IQ stanza to Ejabberd XMPP Server using Smack Android Library. How can I send?

<iq from='[email protected]'
    to='[email protected]'
    type='set'
    id='E6E10350-76CF-40C6-B91B-1EA08C332FC7'>   

     <subscribe xmlns='urn:xmpp:mucsub:0'
             nick='mynick'
             password='roompassword'>
    <event node='urn:xmpp:mucsub:nodes:messages' />
    <event node='urn:xmpp:mucsub:nodes:affiliations' />
    <event node='urn:xmpp:mucsub:nodes:subject' />
    <event node='urn:xmpp:mucsub:nodes:config' />  
  </subscribe> 
  </iq>

I want to Subscribe to MUC/Sub events as described in https://docs.ejabberd.im/developer/xmpp-clients-bots/proposed-extensions/muc-sub/

1
Hey! did u implemented that ? if yes then please guide me too..Abdul Momen Khan
Hi @Abdul Momen Khan ..no I didn't..what's your purpose of implementation?Indranil Talukdar
I need to implement the mucsub....Abdul Momen Khan
ok..what feature you want to build?...like Multi User Chat? @Abdul Momen KhanIndranil Talukdar
Yes Multi User Chat Sub which is enable in ejjabered ..Abdul Momen Khan

1 Answers

0
votes

I have done using following code please check might be helpful you.

     try {
                IQ iq=new IQ("mynick","urn:xmpp:mucsub:0") {
                    @Override
                    protected IQChildElementXmlStringBuilder getIQChildElementBuilder(IQChildElementXmlStringBuilder xml) {
                        xml.setEmptyElement();
                        return xml;
                    }
                };
                iq.setType(IQ.Type.get);
                //add your urn:xmpp:muclight:0#affiliations extension element
                iq.addExtension();
                iq.setTo(AppConstants.CHAT_HOSTNAME);
                iq.setFrom(connection.getUser());
                debugLog("ping send stanza:"+iq.toXML());
                connection.sendStanza(iq);
            } catch (SmackException.NotConnectedException e) {
                e.printStackTrace();
            } catch (InterruptedException e) {
                e.printStackTrace();
            }