2020-04-01 08:45:03 +00:00
|
|
|
package eu.siacs.conversations.xmpp.jingle;
|
|
|
|
|
|
|
|
import com.google.common.base.Objects;
|
|
|
|
import com.google.common.base.Preconditions;
|
|
|
|
|
|
|
|
import eu.siacs.conversations.entities.Account;
|
|
|
|
import eu.siacs.conversations.entities.Message;
|
|
|
|
import eu.siacs.conversations.services.XmppConnectionService;
|
|
|
|
import eu.siacs.conversations.xmpp.jingle.stanzas.JinglePacket;
|
|
|
|
import rocks.xmpp.addr.Jid;
|
|
|
|
|
|
|
|
public abstract class AbstractJingleConnection {
|
|
|
|
|
|
|
|
protected final JingleConnectionManager jingleConnectionManager;
|
|
|
|
protected final XmppConnectionService xmppConnectionService;
|
|
|
|
protected final Id id;
|
|
|
|
|
|
|
|
public AbstractJingleConnection(final JingleConnectionManager jingleConnectionManager, final Id id) {
|
|
|
|
this.jingleConnectionManager = jingleConnectionManager;
|
|
|
|
this.xmppConnectionService = jingleConnectionManager.getXmppConnectionService();
|
|
|
|
this.id = id;
|
|
|
|
}
|
|
|
|
|
|
|
|
abstract void deliverPacket(JinglePacket jinglePacket);
|
|
|
|
|
|
|
|
public Id getId() {
|
|
|
|
return id;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
public static class Id {
|
|
|
|
public final Account account;
|
2020-04-02 14:29:33 +00:00
|
|
|
public final Jid with;
|
2020-04-01 08:45:03 +00:00
|
|
|
public final String sessionId;
|
|
|
|
|
2020-04-02 14:29:33 +00:00
|
|
|
private Id(final Account account, final Jid with, final String sessionId) {
|
|
|
|
Preconditions.checkNotNull(with);
|
|
|
|
Preconditions.checkArgument(with.isFullJid());
|
2020-04-01 08:45:03 +00:00
|
|
|
this.account = account;
|
2020-04-02 14:29:33 +00:00
|
|
|
this.with = with;
|
2020-04-01 08:45:03 +00:00
|
|
|
this.sessionId = sessionId;
|
|
|
|
}
|
|
|
|
|
|
|
|
public static Id of(Account account, JinglePacket jinglePacket) {
|
|
|
|
return new Id(account, jinglePacket.getFrom(), jinglePacket.getSessionId());
|
|
|
|
}
|
|
|
|
|
2020-04-02 14:29:33 +00:00
|
|
|
public static Id of(Account account, Jid with, final String sessionId) {
|
|
|
|
return new Id(account, with, sessionId);
|
|
|
|
}
|
|
|
|
|
2020-04-01 08:45:03 +00:00
|
|
|
public static Id of(Message message) {
|
|
|
|
return new Id(
|
|
|
|
message.getConversation().getAccount(),
|
|
|
|
message.getCounterpart(),
|
|
|
|
JingleConnectionManager.nextRandomId()
|
|
|
|
);
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public boolean equals(Object o) {
|
|
|
|
if (this == o) return true;
|
|
|
|
if (o == null || getClass() != o.getClass()) return false;
|
|
|
|
Id id = (Id) o;
|
|
|
|
return Objects.equal(account.getJid(), id.account.getJid()) &&
|
2020-04-02 14:29:33 +00:00
|
|
|
Objects.equal(with, id.with) &&
|
2020-04-01 08:45:03 +00:00
|
|
|
Objects.equal(sessionId, id.sessionId);
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public int hashCode() {
|
2020-04-02 14:29:33 +00:00
|
|
|
return Objects.hashCode(account.getJid(), with, sessionId);
|
2020-04-01 08:45:03 +00:00
|
|
|
}
|
|
|
|
}
|
2020-04-02 19:12:38 +00:00
|
|
|
|
|
|
|
|
|
|
|
public enum State {
|
|
|
|
NULL, //default value; nothing has been sent or received yet
|
|
|
|
PROPOSED,
|
|
|
|
ACCEPTED,
|
|
|
|
PROCEED,
|
|
|
|
SESSION_INITIALIZED, //equal to 'PENDING'
|
|
|
|
SESSION_ACCEPTED, //equal to 'ACTIVE'
|
|
|
|
TERMINATED //equal to 'ENDED'
|
|
|
|
}
|
2020-04-01 08:45:03 +00:00
|
|
|
}
|