jingle sessions now get terminated proberly on success

This commit is contained in:
Daniel Gultsch 2014-04-16 12:50:53 +02:00
parent bdf9770a61
commit e711da7248
2 changed files with 34 additions and 17 deletions

View File

@ -288,6 +288,7 @@ public class XmppConnectionService extends Service {
} else { } else {
Contact contact = findContact(account, fromParts[0]); Contact contact = findContact(account, fromParts[0]);
if (contact == null) { if (contact == null) {
//Log.d(LOGTAG,"contact was null");
// most likely roster not synced // most likely roster not synced
return; return;
} }
@ -325,8 +326,10 @@ public class XmppConnectionService extends Service {
databaseBackend.updateContact(contact); databaseBackend.updateContact(contact);
} }
} else if (type.equals("subscribe")) { } else if (type.equals("subscribe")) {
Log.d(LOGTAG,"received subscribe packet from "+packet.getFrom());
if (contact if (contact
.getSubscriptionOption(Contact.Subscription.PREEMPTIVE_GRANT)) { .getSubscriptionOption(Contact.Subscription.PREEMPTIVE_GRANT)) {
Log.d(LOGTAG,"preemptive grant; granting");
sendPresenceUpdatesTo(contact); sendPresenceUpdatesTo(contact);
contact.setSubscriptionOption(Contact.Subscription.FROM); contact.setSubscriptionOption(Contact.Subscription.FROM);
contact.resetSubscriptionOption(Contact.Subscription.PREEMPTIVE_GRANT); contact.resetSubscriptionOption(Contact.Subscription.PREEMPTIVE_GRANT);

View File

@ -76,12 +76,17 @@ public class JingleConnection {
if (packet.isAction("session-terminate")) { if (packet.isAction("session-terminate")) {
Reason reason = packet.getReason(); Reason reason = packet.getReason();
if (reason.hasChild("cancel")) { if (reason!=null) {
if (reason.hasChild("cancel")) {
this.cancel();
} else if (reason.hasChild("success")) {
this.finish();
}
} else {
Log.d("xmppService","remote terminated for no reason");
this.cancel(); this.cancel();
} else if (reason.hasChild("success")) {
this.finish();
} }
} else if (packet.isAction("session-accept")) { } else if (packet.isAction("session-accept")) {
accept(packet); accept(packet);
} else if (packet.isAction("transport-info")) { } else if (packet.isAction("transport-info")) {
transportInfo(packet); transportInfo(packet);
@ -150,8 +155,7 @@ public class JingleConnection {
} }
private void sendInitRequest() { private void sendInitRequest() {
JinglePacket packet = this.bootstrapPacket(); JinglePacket packet = this.bootstrapPacket("session-initiate");
packet.setAction("session-initiate");
this.content = new Content(); this.content = new Content();
if (message.getType() == Message.TYPE_IMAGE) { if (message.getType() == Message.TYPE_IMAGE) {
content.setAttribute("creator", "initiator"); content.setAttribute("creator", "initiator");
@ -177,8 +181,7 @@ public class JingleConnection {
content.addCandidate(candidate); content.addCandidate(candidate);
} }
} }
JinglePacket packet = bootstrapPacket(); JinglePacket packet = bootstrapPacket("session-accept");
packet.setAction("session-accept");
packet.setContent(content); packet.setContent(content);
account.getXmppConnection().sendIqPacket(packet, new OnIqPacketReceived() { account.getXmppConnection().sendIqPacket(packet, new OnIqPacketReceived() {
@ -195,8 +198,9 @@ public class JingleConnection {
} }
private JinglePacket bootstrapPacket() { private JinglePacket bootstrapPacket(String action) {
JinglePacket packet = new JinglePacket(); JinglePacket packet = new JinglePacket();
packet.setAction(action);
packet.setFrom(account.getFullJid()); packet.setFrom(account.getFullJid());
packet.setTo(this.message.getCounterpart()); //fixme, not right in all cases; packet.setTo(this.message.getCounterpart()); //fixme, not right in all cases;
packet.setSessionId(this.sessionId); packet.setSessionId(this.sessionId);
@ -224,7 +228,7 @@ public class JingleConnection {
if (this.connections.containsKey(cid)) { if (this.connections.containsKey(cid)) {
SocksConnection connection = this.connections.get(cid); SocksConnection connection = this.connections.get(cid);
if (connection.isEstablished()) { if (connection.isEstablished()) {
if (status!=STATUS_TRANSMITTING) { if (status==STATUS_ACCEPTED) {
this.connect(connection); this.connect(connection);
} else { } else {
Log.d("xmppService","ignoring canditate used because we are already transmitting"); Log.d("xmppService","ignoring canditate used because we are already transmitting");
@ -245,10 +249,9 @@ public class JingleConnection {
@Override @Override
public void onFileTransmitted(JingleFile file) { public void onFileTransmitted(JingleFile file) {
if (initiator.equals(account.getFullJid())) { if (responder.equals(account.getFullJid())) {
sendSuccess();
mXmppConnectionService.markMessage(message, Message.STATUS_SEND); mXmppConnectionService.markMessage(message, Message.STATUS_SEND);
} else {
mXmppConnectionService.markMessage(message, Message.STATUS_RECIEVED);
} }
Log.d("xmppService","sucessfully transmitted file. sha1:"+file.getSha1Sum()); Log.d("xmppService","sucessfully transmitted file. sha1:"+file.getSha1Sum());
} }
@ -284,6 +287,18 @@ public class JingleConnection {
} }
} }
private void sendSuccess() {
JinglePacket packet = bootstrapPacket("session-terminate");
Reason reason = new Reason();
reason.addChild("success");
packet.setReason(reason);
Log.d("xmppService","sending success. "+packet.toString());
this.account.getXmppConnection().sendIqPacket(packet, responseListener);
this.disconnect();
this.status = STATUS_FINISHED;
this.mXmppConnectionService.markMessage(this.message, Message.STATUS_RECIEVED);
}
private void finish() { private void finish() {
this.status = STATUS_FINISHED; this.status = STATUS_FINISHED;
this.mXmppConnectionService.markMessage(this.message, Message.STATUS_SEND); this.mXmppConnectionService.markMessage(this.message, Message.STATUS_SEND);
@ -319,7 +334,7 @@ public class JingleConnection {
@Override @Override
public void established() { public void established() {
if (candidatesUsedByCounterpart.contains(socksConnection.getCid())) { if (candidatesUsedByCounterpart.contains(socksConnection.getCid())) {
if (status!=STATUS_TRANSMITTING) { if (status==STATUS_ACCEPTED) {
connect(socksConnection); connect(socksConnection);
} else { } else {
Log.d("xmppService","ignoring cuz already transmitting"); Log.d("xmppService","ignoring cuz already transmitting");
@ -341,8 +356,7 @@ public class JingleConnection {
} }
private void sendCandidateUsed(final String cid) { private void sendCandidateUsed(final String cid) {
JinglePacket packet = bootstrapPacket(); JinglePacket packet = bootstrapPacket("transport-info");
packet.setAction("transport-info");
Content content = new Content(); Content content = new Content();
content.setUsedCandidate(this.content.getTransportId(), cid); content.setUsedCandidate(this.content.getTransportId(), cid);
packet.setContent(content); packet.setContent(content);
@ -352,7 +366,7 @@ public class JingleConnection {
@Override @Override
public void onIqPacketReceived(Account account, IqPacket packet) { public void onIqPacketReceived(Account account, IqPacket packet) {
Log.d("xmppService","got ack for our candidate used"); Log.d("xmppService","got ack for our candidate used");
if (status!=STATUS_TRANSMITTING) { if (status==STATUS_ACCEPTED) {
connect(connections.get(cid)); connect(connections.get(cid));
} else { } else {
Log.d("xmppService","ignoring cuz already transmitting"); Log.d("xmppService","ignoring cuz already transmitting");