aboutsummaryrefslogtreecommitdiffstats
path: root/src/eu/siacs/conversations/xmpp/XmppConnection.java
diff options
context:
space:
mode:
authorDaniel Gultsch <daniel@gultsch.de>2014-03-11 15:44:22 +0100
committerDaniel Gultsch <daniel@gultsch.de>2014-03-11 15:44:22 +0100
commit0d516b060354f577ff52ce2d3bb73f56557b87d1 (patch)
treeb77371f78047f4dcae10a8402c4ba00085cbae68 /src/eu/siacs/conversations/xmpp/XmppConnection.java
parent08023210ba875f3cd088eca2b4b3df7410966344 (diff)
ping stuff
Diffstat (limited to 'src/eu/siacs/conversations/xmpp/XmppConnection.java')
-rw-r--r--src/eu/siacs/conversations/xmpp/XmppConnection.java23
1 files changed, 22 insertions, 1 deletions
diff --git a/src/eu/siacs/conversations/xmpp/XmppConnection.java b/src/eu/siacs/conversations/xmpp/XmppConnection.java
index 2ffe21fb..6d5d4c46 100644
--- a/src/eu/siacs/conversations/xmpp/XmppConnection.java
+++ b/src/eu/siacs/conversations/xmpp/XmppConnection.java
@@ -29,9 +29,9 @@ import javax.net.ssl.X509TrustManager;
import org.json.JSONException;
import org.xmlpull.v1.XmlPullParserException;
-import android.content.IntentSender.SendIntentException;
import android.os.Bundle;
import android.os.PowerManager;
+import android.os.SystemClock;
import android.util.Log;
import eu.siacs.conversations.entities.Account;
import eu.siacs.conversations.utils.CryptoHelper;
@@ -71,6 +71,9 @@ public class XmppConnection implements Runnable {
private int stanzasReceived = 0;
private int stanzasSent = 0;
+
+ public long lastPaketReceived = 0;
+ public long lastPingSent = 0;
private static final int PACKET_IQ = 0;
private static final int PACKET_MESSAGE = 1;
@@ -214,6 +217,7 @@ public class XmppConnection implements Runnable {
tagWriter.writeStanzaAsync(ack);
} else if (nextTag.isStart("a")) {
Element ack = tagReader.readElement(nextTag);
+ lastPaketReceived = SystemClock.elapsedRealtime();
int serverSequence = Integer.parseInt(ack.getAttribute("h"));
if (serverSequence>this.stanzasSent) {
this.stanzasSent = serverSequence;
@@ -265,6 +269,7 @@ public class XmppConnection implements Runnable {
nextTag = tagReader.readTag();
}
++stanzasReceived;
+ lastPaketReceived = SystemClock.elapsedRealtime();
return element;
}
@@ -580,6 +585,7 @@ public class XmppConnection implements Runnable {
}
private synchronized void sendPacket(final AbstractStanza packet, PacketReceived callback) {
+ // TODO dont increment stanza count if packet = request packet or ack;
++stanzasSent;
tagWriter.writeStanzaAsync(packet);
if (callback != null) {
@@ -589,6 +595,21 @@ public class XmppConnection implements Runnable {
packetCallbacks.put(packet.getId(), callback);
}
}
+
+ public void sendPing() {
+ if (streamFeatures.hasChild("sm")) {
+ Log.d(LOGTAG,"sending r as ping");
+ tagWriter.writeStanzaAsync(new RequestPacket());
+ } else {
+ Log.d(LOGTAG,"sending iq as ping");
+ IqPacket iq = new IqPacket(IqPacket.TYPE_GET);
+ Element ping = new Element("ping");
+ iq.setAttribute("from",account.getFullJid());
+ ping.setAttribute("xmlns", "urn:xmpp:ping");
+ iq.addChild(ping);
+ this.sendIqPacket(iq, null);
+ }
+ }
public void setOnMessagePacketReceivedListener(
OnMessagePacketReceived listener) {