# HG changeset patch # User Da Risk # Date 1325886158 -3600 # Node ID a217fc346c2f2b460397ac03856dfee0fdeb1151 # Parent d456bf4dbc17ac0ad17c0b6b5fcb4dd1fc344610 Implements a ping listener from XEP-0199 XMPP ping. In the future, we can send an XMPP ping to the server to check for the state of the connection. diff -r d456bf4dbc17 -r a217fc346c2f src/com/beem/project/beem/BeemService.java --- a/src/com/beem/project/beem/BeemService.java Fri Jan 06 22:39:35 2012 +0100 +++ b/src/com/beem/project/beem/BeemService.java Fri Jan 06 22:42:38 2012 +0100 @@ -90,6 +90,7 @@ import com.beem.project.beem.smack.avatar.AvatarMetadataProvider; import com.beem.project.beem.smack.avatar.AvatarProvider; import com.beem.project.beem.smack.caps.CapsProvider; +import com.beem.project.beem.smack.ping.PingExtension; import de.duenndns.ssl.MemorizingTrustManager; @@ -398,6 +399,9 @@ // pep.registerPEPParserExtension("urn:xmpp:avatar:metadata", avaMeta); // pm.addExtensionProvider("event", "http://jabber.org/protocol/pubsub#event", pep); + // ping + pm.addIQProvider(PingExtension.ELEMENT, PingExtension.NAMESPACE, PingExtension.class); + /* // Private Data Storage pm.addIQProvider("query", "jabber:iq:private", new PrivateDataManager.PrivateDataIQProvider()); diff -r d456bf4dbc17 -r a217fc346c2f src/com/beem/project/beem/service/XmppConnectionAdapter.java --- a/src/com/beem/project/beem/service/XmppConnectionAdapter.java Fri Jan 06 22:39:35 2012 +0100 +++ b/src/com/beem/project/beem/service/XmppConnectionAdapter.java Fri Jan 06 22:42:38 2012 +0100 @@ -43,20 +43,8 @@ */ package com.beem.project.beem.service; -import org.jivesoftware.smack.ConnectionConfiguration; -import org.jivesoftware.smack.ConnectionListener; -import org.jivesoftware.smack.PacketListener; -import org.jivesoftware.smack.PrivacyListManager; -import org.jivesoftware.smack.Roster; -import org.jivesoftware.smack.XMPPConnection; -import org.jivesoftware.smack.XMPPException; -import org.jivesoftware.smack.filter.PacketFilter; -import org.jivesoftware.smack.packet.Packet; -import org.jivesoftware.smack.packet.Presence; -import org.jivesoftware.smack.util.StringUtils; -import org.jivesoftware.smackx.ChatStateManager; -import org.jivesoftware.smackx.ServiceDiscoveryManager; -import org.jivesoftware.smackx.packet.DiscoverInfo; +import java.util.Iterator; +import java.util.List; import android.app.Notification; import android.app.PendingIntent; @@ -67,24 +55,39 @@ import android.os.RemoteException; import android.util.Log; -import java.util.Iterator; -import java.util.List; - +import com.beem.project.beem.BeemApplication; import com.beem.project.beem.BeemService; import com.beem.project.beem.R; -import com.beem.project.beem.BeemApplication; import com.beem.project.beem.service.aidl.IBeemConnectionListener; import com.beem.project.beem.service.aidl.IChatManager; import com.beem.project.beem.service.aidl.IRoster; import com.beem.project.beem.service.aidl.IXmppConnection; +import com.beem.project.beem.smack.avatar.AvatarCache; +import com.beem.project.beem.smack.avatar.AvatarListener; +import com.beem.project.beem.smack.avatar.AvatarMetadataExtension; +import com.beem.project.beem.smack.pep.PepSubManager; +import com.beem.project.beem.smack.ping.PingExtension; import com.beem.project.beem.ui.ChangeStatus; import com.beem.project.beem.ui.Subscription; import com.beem.project.beem.utils.BeemBroadcastReceiver; import com.beem.project.beem.utils.Status; -import com.beem.project.beem.smack.pep.PepSubManager; -import com.beem.project.beem.smack.avatar.AvatarCache; -import com.beem.project.beem.smack.avatar.AvatarListener; -import com.beem.project.beem.smack.avatar.AvatarMetadataExtension; + +import org.jivesoftware.smack.ConnectionConfiguration; +import org.jivesoftware.smack.ConnectionListener; +import org.jivesoftware.smack.PacketListener; +import org.jivesoftware.smack.PrivacyListManager; +import org.jivesoftware.smack.Roster; +import org.jivesoftware.smack.XMPPConnection; +import org.jivesoftware.smack.XMPPException; +import org.jivesoftware.smack.filter.PacketFilter; +import org.jivesoftware.smack.filter.PacketTypeFilter; +import org.jivesoftware.smack.packet.IQ; +import org.jivesoftware.smack.packet.Packet; +import org.jivesoftware.smack.packet.Presence; +import org.jivesoftware.smack.util.StringUtils; +import org.jivesoftware.smackx.ChatStateManager; +import org.jivesoftware.smackx.ServiceDiscoveryManager; +import org.jivesoftware.smackx.packet.DiscoverInfo; /** * This class implements an adapter for XMPPConnection. @@ -119,6 +122,7 @@ private final RemoteCallbackList mRemoteConnListeners = new RemoteCallbackList(); private final SubscribePacketListener mSubscribePacketListener = new SubscribePacketListener(); + private final PingListener mPingListener = new PingListener(); private final ConnexionListenerAdapter mConListener = new ConnexionListenerAdapter(); @@ -239,6 +243,9 @@ mAdaptee.addPacketListener(mSubscribePacketListener, filter); + filter = new PacketTypeFilter(PingExtension.class); + mAdaptee.addPacketListener(mPingListener, filter); + mAdaptee.login(mLogin, mPassword, mResource); mUserInfo = new UserInfo(mAdaptee.getUser()); @@ -483,6 +490,7 @@ sdm.addFeature("urn:xmpp:avatar:data"); sdm.addFeature("http://jabber.org/protocol/nick"); sdm.addFeature("http://jabber.org/protocol/nick+notify"); + sdm.addFeature(PingExtension.NAMESPACE); mChatStateManager = ChatStateManager.getInstance(mAdaptee); BeemCapsManager caps = new BeemCapsManager(sdm, mAdaptee, mService); @@ -534,7 +542,6 @@ /** * Listener for XMPP connection events. It will calls the remote listeners for connection events. - * @author darisk */ private class ConnexionListenerAdapter implements ConnectionListener { @@ -751,4 +758,25 @@ } } + /** + * Listener for Ping request. + * It will respond with a Pong. + */ + private class PingListener implements PacketListener { + + @Override + public void processPacket(Packet packet) { + if (!(packet instanceof PingExtension)) + return; + PingExtension p = (PingExtension) packet; + if (p.getType() == IQ.Type.GET) { + PingExtension pong = new PingExtension(); + pong.setType(IQ.Type.RESULT); + pong.setTo(p.getFrom()); + pong.setPacketID(p.getPacketID()); + mAdaptee.sendPacket(pong); + } + } + } + } diff -r d456bf4dbc17 -r a217fc346c2f src/com/beem/project/beem/smack/ping/PingExtension.java --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/src/com/beem/project/beem/smack/ping/PingExtension.java Fri Jan 06 22:42:38 2012 +0100 @@ -0,0 +1,61 @@ +/* + BEEM is a videoconference application on the Android Platform. + + Copyright (C) 2009 by Frederic-Charles Barthelery, + Jean-Manuel Da Silva, + Nikita Kozlov, + Philippe Lago, + Jean Baptiste Vergely, + Vincent Veronis. + + This file is part of BEEM. + + BEEM is free software: you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation, either version 3 of the License, or + (at your option) any later version. + + BEEM is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License + along with BEEM. If not, see . + + Please send bug reports with examples or suggestions to + contact@beem-project.com or http://dev.beem-project.com/ + +*/ + +package com.beem.project.beem.smack.ping; + +import org.jivesoftware.smack.packet.IQ; + +/** + * This extension represents a iq ping. + * + */ +public class PingExtension extends IQ { + + /** Namespace of the Ping XEP. */ + public static final String NAMESPACE = "urn:xmpp:ping"; + + /** Xml element name for the ping. */ + public static final String ELEMENT = "ping"; + + + /** + * Create a ping iq packet. + */ + public PingExtension() { + } + + @Override + public String getChildElementXML() { + if (getType() == IQ.Type.RESULT) + return null; + return "<" + ELEMENT + " xmlns=\"" + NAMESPACE + "\" />"; + } + +} diff -r d456bf4dbc17 -r a217fc346c2f src/com/beem/project/beem/smack/ping/package-info.java --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/src/com/beem/project/beem/smack/ping/package-info.java Fri Jan 06 22:42:38 2012 +0100 @@ -0,0 +1,34 @@ +/* + BEEM is a videoconference application on the Android Platform. + + Copyright (C) 2009 by Frederic-Charles Barthelery, + Jean-Manuel Da Silva, + Nikita Kozlov, + Philippe Lago, + Jean Baptiste Vergely, + Vincent Veronis. + + This file is part of BEEM. + + BEEM is free software: you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation, either version 3 of the License, or + (at your option) any later version. + + BEEM is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License + along with BEEM. If not, see . + + Please send bug reports with examples or suggestions to + contact@beem-project.com or http://dev.beem-project.com/ + +*/ + +/** + * This package contains implementation of XEP-0199 XMPP Ping. + */ +package com.beem.project.beem.smack.ping;