2014-04-08 21:15:55 +00:00
|
|
|
package eu.siacs.conversations.xmpp.jingle;
|
2014-04-07 18:05:45 +00:00
|
|
|
|
|
|
|
import java.util.ArrayList;
|
|
|
|
import java.util.List;
|
|
|
|
|
|
|
|
import android.util.Log;
|
|
|
|
|
|
|
|
import eu.siacs.conversations.entities.Account;
|
|
|
|
import eu.siacs.conversations.entities.Message;
|
|
|
|
import eu.siacs.conversations.services.XmppConnectionService;
|
|
|
|
import eu.siacs.conversations.xml.Element;
|
2014-04-08 21:15:55 +00:00
|
|
|
import eu.siacs.conversations.xmpp.OnIqPacketReceived;
|
|
|
|
import eu.siacs.conversations.xmpp.jingle.stanzas.Content;
|
|
|
|
import eu.siacs.conversations.xmpp.jingle.stanzas.JinglePacket;
|
|
|
|
import eu.siacs.conversations.xmpp.stanzas.IqPacket;
|
2014-04-07 18:05:45 +00:00
|
|
|
|
|
|
|
public class JingleConnection {
|
|
|
|
|
|
|
|
private JingleConnectionManager mJingleConnectionManager;
|
|
|
|
private XmppConnectionService mXmppConnectionService;
|
|
|
|
|
2014-04-08 21:15:55 +00:00
|
|
|
private Message message;
|
2014-04-07 18:05:45 +00:00
|
|
|
private String sessionId;
|
|
|
|
private Account account;
|
2014-04-08 21:15:55 +00:00
|
|
|
private String initiator;
|
|
|
|
private String responder;
|
2014-04-07 18:05:45 +00:00
|
|
|
private List<Element> canditates = new ArrayList<Element>();
|
|
|
|
|
2014-04-08 21:15:55 +00:00
|
|
|
private OnIqPacketReceived responseListener = new OnIqPacketReceived() {
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public void onIqPacketReceived(Account account, IqPacket packet) {
|
|
|
|
Log.d("xmppService",packet.toString());
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
|
|
|
public JingleConnection(JingleConnectionManager mJingleConnectionManager) {
|
2014-04-07 18:05:45 +00:00
|
|
|
this.mJingleConnectionManager = mJingleConnectionManager;
|
|
|
|
this.mXmppConnectionService = mJingleConnectionManager.getXmppConnectionService();
|
2014-04-08 21:15:55 +00:00
|
|
|
this.sessionId = this.mJingleConnectionManager.nextRandomId();
|
2014-04-07 18:05:45 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
public String getSessionId() {
|
|
|
|
return this.sessionId;
|
|
|
|
}
|
|
|
|
|
|
|
|
public void init(Message message) {
|
2014-04-08 21:15:55 +00:00
|
|
|
this.message = message;
|
|
|
|
this.account = message.getConversation().getAccount();
|
|
|
|
this.initiator = this.account.getFullJid();
|
|
|
|
if (this.canditates.size() > 0) {
|
|
|
|
this.sendInitRequest();
|
|
|
|
} else {
|
|
|
|
this.mJingleConnectionManager.getPrimaryCanditate(account, new OnPrimaryCanditateFound() {
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public void onPrimaryCanditateFound(boolean success, Element canditate) {
|
|
|
|
if (success) {
|
|
|
|
canditates.add(canditate);
|
|
|
|
}
|
|
|
|
sendInitRequest();
|
|
|
|
}
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
private void sendInitRequest() {
|
2014-04-07 18:05:45 +00:00
|
|
|
JinglePacket packet = this.bootstrapPacket();
|
|
|
|
packet.setAction("session-initiate");
|
|
|
|
packet.setInitiator(this.account.getFullJid());
|
|
|
|
Content content = new Content();
|
|
|
|
if (message.getType() == Message.TYPE_IMAGE) {
|
|
|
|
content.setAttribute("creator", "initiator");
|
|
|
|
content.setAttribute("name", "a-file-offer");
|
|
|
|
content.offerFile(this.mXmppConnectionService.getFileBackend().getImageFile(message));
|
|
|
|
content.setCanditates(this.canditates);
|
|
|
|
packet.setContent(content);
|
|
|
|
Log.d("xmppService",packet.toString());
|
2014-04-08 21:15:55 +00:00
|
|
|
account.getXmppConnection().sendIqPacket(packet, this.responseListener);
|
2014-04-07 18:05:45 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
private JinglePacket bootstrapPacket() {
|
|
|
|
JinglePacket packet = new JinglePacket();
|
|
|
|
packet.setFrom(account.getFullJid());
|
2014-04-08 21:15:55 +00:00
|
|
|
packet.setTo(this.message.getCounterpart()+"/Gajim"); //fixme, not right in all cases;
|
2014-04-07 18:05:45 +00:00
|
|
|
packet.setSessionId(this.sessionId);
|
|
|
|
return packet;
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|