2020-04-01 08:45:03 +00:00
|
|
|
|
package eu.siacs.conversations.xmpp.jingle;
|
|
|
|
|
|
2022-02-25 15:24:13 +00:00
|
|
|
|
import androidx.annotation.NonNull;
|
|
|
|
|
|
2020-05-27 11:54:35 +00:00
|
|
|
|
import com.google.common.base.MoreObjects;
|
2020-04-01 08:45:03 +00:00
|
|
|
|
import com.google.common.base.Objects;
|
|
|
|
|
import com.google.common.base.Preconditions;
|
|
|
|
|
|
|
|
|
|
import eu.siacs.conversations.entities.Account;
|
2020-04-20 11:08:43 +00:00
|
|
|
|
import eu.siacs.conversations.entities.Contact;
|
2020-04-01 08:45:03 +00:00
|
|
|
|
import eu.siacs.conversations.entities.Message;
|
|
|
|
|
import eu.siacs.conversations.services.XmppConnectionService;
|
2020-05-15 15:06:16 +00:00
|
|
|
|
import eu.siacs.conversations.xmpp.Jid;
|
2021-01-23 08:25:34 +00:00
|
|
|
|
import eu.siacs.conversations.xmpp.jingle.stanzas.JinglePacket;
|
2020-04-01 08:45:03 +00:00
|
|
|
|
|
|
|
|
|
public abstract class AbstractJingleConnection {
|
|
|
|
|
|
2020-04-10 05:45:23 +00:00
|
|
|
|
public static final String JINGLE_MESSAGE_PROPOSE_ID_PREFIX = "jm-propose-";
|
|
|
|
|
public static final String JINGLE_MESSAGE_PROCEED_ID_PREFIX = "jm-proceed-";
|
2020-04-07 09:36:28 +00:00
|
|
|
|
|
2020-06-14 07:01:47 +00:00
|
|
|
|
final JingleConnectionManager jingleConnectionManager;
|
2020-04-01 08:45:03 +00:00
|
|
|
|
protected final XmppConnectionService xmppConnectionService;
|
|
|
|
|
protected final Id id;
|
2020-06-14 07:01:47 +00:00
|
|
|
|
private final Jid initiator;
|
2020-04-01 08:45:03 +00:00
|
|
|
|
|
2020-04-03 06:16:55 +00:00
|
|
|
|
AbstractJingleConnection(final JingleConnectionManager jingleConnectionManager, final Id id, final Jid initiator) {
|
2020-04-01 08:45:03 +00:00
|
|
|
|
this.jingleConnectionManager = jingleConnectionManager;
|
|
|
|
|
this.xmppConnectionService = jingleConnectionManager.getXmppConnectionService();
|
|
|
|
|
this.id = id;
|
2020-04-03 06:16:55 +00:00
|
|
|
|
this.initiator = initiator;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
boolean isInitiator() {
|
|
|
|
|
return initiator.equals(id.account.getJid());
|
2020-04-01 08:45:03 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
abstract void deliverPacket(JinglePacket jinglePacket);
|
|
|
|
|
|
|
|
|
|
public Id getId() {
|
|
|
|
|
return id;
|
|
|
|
|
}
|
|
|
|
|
|
2020-04-13 16:30:12 +00:00
|
|
|
|
abstract void notifyRebound();
|
|
|
|
|
|
2020-04-01 08:45:03 +00:00
|
|
|
|
|
2020-05-02 07:50:17 +00:00
|
|
|
|
public static class Id implements OngoingRtpSession {
|
2020-04-01 08:45:03 +00:00
|
|
|
|
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) {
|
2020-06-14 07:01:47 +00:00
|
|
|
|
Preconditions.checkNotNull(account);
|
2020-04-02 14:29:33 +00:00
|
|
|
|
Preconditions.checkNotNull(with);
|
2020-06-14 07:01:47 +00:00
|
|
|
|
Preconditions.checkNotNull(sessionId);
|
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-05-30 12:56:12 +00:00
|
|
|
|
public static Id of(Account account, Jid with) {
|
|
|
|
|
return new Id(account, with, JingleConnectionManager.nextRandomId());
|
|
|
|
|
}
|
|
|
|
|
|
2020-04-01 08:45:03 +00:00
|
|
|
|
public static Id of(Message message) {
|
|
|
|
|
return new Id(
|
|
|
|
|
message.getConversation().getAccount(),
|
|
|
|
|
message.getCounterpart(),
|
|
|
|
|
JingleConnectionManager.nextRandomId()
|
|
|
|
|
);
|
|
|
|
|
}
|
|
|
|
|
|
2020-04-20 11:08:43 +00:00
|
|
|
|
public Contact getContact() {
|
|
|
|
|
return account.getRoster().getContact(with);
|
|
|
|
|
}
|
|
|
|
|
|
2020-04-01 08:45:03 +00:00
|
|
|
|
@Override
|
|
|
|
|
public boolean equals(Object o) {
|
|
|
|
|
if (this == o) return true;
|
|
|
|
|
if (o == null || getClass() != o.getClass()) return false;
|
|
|
|
|
Id id = (Id) o;
|
2020-05-27 11:54:35 +00:00
|
|
|
|
return Objects.equal(account.getUuid(), id.account.getUuid()) &&
|
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-05-27 11:54:35 +00:00
|
|
|
|
return Objects.hashCode(account.getUuid(), with, sessionId);
|
2020-04-01 08:45:03 +00:00
|
|
|
|
}
|
2020-05-02 07:50:17 +00:00
|
|
|
|
|
|
|
|
|
@Override
|
|
|
|
|
public Account getAccount() {
|
|
|
|
|
return account;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@Override
|
|
|
|
|
public Jid getWith() {
|
|
|
|
|
return with;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@Override
|
|
|
|
|
public String getSessionId() {
|
|
|
|
|
return sessionId;
|
|
|
|
|
}
|
2020-05-27 11:54:35 +00:00
|
|
|
|
|
|
|
|
|
@Override
|
2022-02-25 15:24:13 +00:00
|
|
|
|
@NonNull
|
2020-05-27 11:54:35 +00:00
|
|
|
|
public String toString() {
|
|
|
|
|
return MoreObjects.toStringHelper(this)
|
|
|
|
|
.add("account", account.getJid())
|
|
|
|
|
.add("with", with)
|
|
|
|
|
.add("sessionId", sessionId)
|
|
|
|
|
.toString();
|
|
|
|
|
}
|
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,
|
2020-04-07 19:26:51 +00:00
|
|
|
|
REJECTED,
|
2021-02-11 15:56:57 +00:00
|
|
|
|
REJECTED_RACED, //used when we want to reject but haven’t received session init yet
|
2020-04-07 19:26:51 +00:00
|
|
|
|
RETRACTED,
|
2020-05-09 19:35:21 +00:00
|
|
|
|
RETRACTED_RACED, //used when receiving a retract after we already asked to proceed
|
2020-04-02 19:12:38 +00:00
|
|
|
|
SESSION_INITIALIZED, //equal to 'PENDING'
|
2020-04-08 13:27:17 +00:00
|
|
|
|
SESSION_INITIALIZED_PRE_APPROVED,
|
2020-04-02 19:12:38 +00:00
|
|
|
|
SESSION_ACCEPTED, //equal to 'ACTIVE'
|
2020-04-07 19:26:51 +00:00
|
|
|
|
TERMINATED_SUCCESS, //equal to 'ENDED' (after successful call) ui will just close
|
|
|
|
|
TERMINATED_DECLINED_OR_BUSY, //equal to 'ENDED' (after other party declined the call)
|
|
|
|
|
TERMINATED_CONNECTIVITY_ERROR, //equal to 'ENDED' (but after network failures; ui will display retry button)
|
2020-04-09 13:22:03 +00:00
|
|
|
|
TERMINATED_CANCEL_OR_TIMEOUT, //more or less the same as retracted; caller pressed end call before session was accepted
|
2021-05-04 08:10:30 +00:00
|
|
|
|
TERMINATED_APPLICATION_FAILURE,
|
|
|
|
|
TERMINATED_SECURITY_ERROR
|
2020-04-02 19:12:38 +00:00
|
|
|
|
}
|
2020-04-01 08:45:03 +00:00
|
|
|
|
}
|