Quantcast
Channel: Ignite Realtime: Message List
Viewing all articles
Browse latest Browse all 11413

Re: Can openfire supports mobility XMPP protocols (XEP-198)?

$
0
0

Hi All,

i just want to share with you how i've fixed this problem. To be clear i've not implemented the XEP-0198 standard but i developed a trick that works fine for me.

Here what i did.

I've developed a packet interceptor, when a packet of my interest reach the openfire server this is what i do:

 

1. first of all i check if the user is online, if is not online i let the openfire to store messages on its offline table

2. if the user is online i do this

 

               var pencoded=java.net.URLEncoder.encode(packet.toXML(), "UTF-8");

                var millis=org.jivesoftware.util.StringUtils.dateToMillis(new java.util.Date());

                var pid=java.net.URLEncoder.encode(packet.getID().toString(), "UTF-8");

                sendMessageToQueue(pencoded,millis,pid);

                 if (packet.getFrom()!=null && packet.getID()!=null){

                    var iq = new org.xmpp.packet.IQ();

                    iq.setType(org.xmpp.packet.IQ.Type.result);

                    iq.setChildElement("ack","mynamespace").addText(packet.getID());

                    iq.setTo(packet.getFrom());

                    log.info("myFrom:"+packet.getFrom().toString());

                    var iqRouter = server.getIQRouter();

                    iqRouter.route(iq);

                }

 

     The first thing this code does is to store the message in a database table called MessageQueue, after this send an iq of type set to the client with the messageID. Of course the client knows how to handle this, and know that the message reached the server.

 

At the server side (to handle the fact that a client can lose the connection but for a while is seen ONLINE by the server), i do this:

 

 

if (!incoming && !processed){

              if (packet.toString().indexOf("my tag")>0 && packet.getType()=="set" )

                {

 

 

                var id=packet.getChildElement().getText();

                log.info("AckManagementRemoveQueue Log Start");

                log.info("packet: " + packet);

                log.info("id: " + id);

                deleteMessageFromQueue(id);

                log.info("AckManagementRemoveQueue Log End")

              

              

                }

                }

              

              }

i check if a packet is of type SET and if contains a tag sent by the client, if yes the server remove the message from its own queue. If this ack never arrives in 1 minutes i simply put the message in the openfire offline table (with the format openfire can handle); in this way when a client reconnect the message is sent to him.

 

If anyone is interested to know more, just drop me a message and i will be more than welcome to help.

 

I know is not the best way but works like a charm for me and overcome a big problem!.


Viewing all articles
Browse latest Browse all 11413

Trending Articles