How to know Typing Status in XMPP openfire using Smack

user2160008 picture user2160008 · Aug 26, 2013 · Viewed 10.9k times · Source

I am developing chat application by using Openfire XMPP server. I can text chat between two user. But i want to know Typing status when some one is typing message. So i created a class :-

public class typingStatus implements ChatStateListener {

    @Override
    public void processMessage(Chat arg0, Message arg1) {
        // TODO Auto-generated method stub

    }

    @Override
    public void stateChanged(Chat arg0, ChatState arg1) {
        // TODO Auto-generated method stub
        System.out.println(arg0.getParticipant() + " is " + arg1.name());

    }

}

But i am confuse so that How will it work? I know that i need a packet where i can it in Listener. But i am unable to find that packet.

Please any one suggest, How will it work?

and also what is difference between Smack and asmack?

Thank you!

Answer

Sunil Mishra picture Sunil Mishra · Aug 26, 2013

To enable ChatStateListener you need to create a custom MessageListener Class

public class MessageListenerImpl implements MessageListener,ChatStateListener  {

    @Override
    public void processMessage(Chat arg0, Message arg1) {
        System.out.println("Received message: " + arg1);

    }

    @Override
    public void stateChanged(Chat arg0, ChatState arg1) {
        if (ChatState.composing.equals(arg1)) {
            Log.d("Chat State",arg0.getParticipant() + " is typing..");
        } else if (ChatState.gone.equals(arg1)) {
            Log.d("Chat State",arg0.getParticipant() + " has left the conversation.");
        } else {
            Log.d("Chat State",arg0.getParticipant() + ": " + arg1.name());
        }

    }

}

Then you create MessageListener object

MessageListener messageListener = new MessageListenerImpl();

And then pass this in the create chat method

Chat newChat = chatmanager.createChat(jabber_id_of_friend, messageListener);

what is difference between Smack and asmack? <-- Check This