Quantcast
Channel: Ignite Realtime : Discussion List - All Communities
Viewing all articles
Browse latest Browse all 10742

ChatMessageListener and Pubsub

$
0
0

HI,

I've wrote a software that uses smack API and Openfire for XMPP communication. Currently I'm using both the last version of the Smack library (3.4.1) and the last version of Openfire (3.9.1).

I need to use both the chat and the pubsub services. For this reason, in my code I have something similiar to this snippet of code (taken from the API documentation) for the chat:

 

 

ChatManager chatmanager = connection.getChatManager().addChatListener(    new ChatManagerListener() {        @Override        publicvoid chatCreated(Chat chat, boolean createdLocally)        {            if (!createdLocally)                chat.addMessageListener(new MyNewMessageListener());;        }    }); 

 

 

 

 

and this snippet of code (I've omitted something for brevity) for the Pubsub:

 

 

final PubSubManager pubSubManager = new PubSubManager(connection,pubsubService);final InItemEventCoordinator handler = new InItemEventCoordinator("name");
Node node = pubSubManager.getNode(nodeName);
node.addItemEventListener(handler);

 

 

where ItemEventCoordinator implements ItemEventListener:

 

 

publicabstractclass ItemEventCoordinator implements ItemEventListener<Item> {       publicvoid handlePublishedItems(final ItemPublishEvent items) {               // do something     }}

 

Now, in my opinion, in this situation, I have to receive in MyNewMessageListener (method processMessage) the chat messages and in the ItemEventCoordinator (method handlePublishedItems) I have to receive the pubsub notification.

Instead when a publisher publishes a new event on the node, I receive that event in the ItemEventListener, but in the same time also the chatCreated method is called, and from then on all the events published on the node are received both in the handlePublishedItems method of ItemEventCoordinator AND in the processMessage method.

 

 

Now, I have to questions:

 

 

1) Is it correct that the chatCreated is called when a new pubsub event is sent? In my opinion no, the pubsub events are Messages, but not messages of type Chat..

 

 

2) Is there a simple way to filter the pubsub events, so that you can receive the chat messages in the MaNewMessageListener and the pubsub events in the ItemEventCoordinatoor? Or the only way is to avoid to use the Chat and Pubsub API, and to use custom packet listeners applied on the connection?

 

Thanks in advance,

Davide


Viewing all articles
Browse latest Browse all 10742

Trending Articles