reject call from proceed state; and deal with direct inits

This commit is contained in:
Daniel Gultsch 2020-04-09 09:04:59 +02:00
parent 0bf991d95c
commit 3e5e4e813b

View file

@ -16,10 +16,8 @@ import java.util.List;
import java.util.Map; import java.util.Map;
import eu.siacs.conversations.Config; import eu.siacs.conversations.Config;
import eu.siacs.conversations.entities.Account;
import eu.siacs.conversations.xml.Element; import eu.siacs.conversations.xml.Element;
import eu.siacs.conversations.xml.Namespace; import eu.siacs.conversations.xml.Namespace;
import eu.siacs.conversations.xmpp.OnIqPacketReceived;
import eu.siacs.conversations.xmpp.jingle.stanzas.Group; import eu.siacs.conversations.xmpp.jingle.stanzas.Group;
import eu.siacs.conversations.xmpp.jingle.stanzas.IceUdpTransportInfo; import eu.siacs.conversations.xmpp.jingle.stanzas.IceUdpTransportInfo;
import eu.siacs.conversations.xmpp.jingle.stanzas.JinglePacket; import eu.siacs.conversations.xmpp.jingle.stanzas.JinglePacket;
@ -36,9 +34,9 @@ public class JingleRtpConnection extends AbstractJingleConnection implements Web
final ImmutableMap.Builder<State, Collection<State>> transitionBuilder = new ImmutableMap.Builder<>(); final ImmutableMap.Builder<State, Collection<State>> transitionBuilder = new ImmutableMap.Builder<>();
transitionBuilder.put(State.NULL, ImmutableList.of(State.PROPOSED, State.SESSION_INITIALIZED)); transitionBuilder.put(State.NULL, ImmutableList.of(State.PROPOSED, State.SESSION_INITIALIZED));
transitionBuilder.put(State.PROPOSED, ImmutableList.of(State.ACCEPTED, State.PROCEED, State.REJECTED, State.RETRACTED)); transitionBuilder.put(State.PROPOSED, ImmutableList.of(State.ACCEPTED, State.PROCEED, State.REJECTED, State.RETRACTED));
transitionBuilder.put(State.PROCEED, ImmutableList.of(State.SESSION_INITIALIZED_PRE_APPROVED)); transitionBuilder.put(State.PROCEED, ImmutableList.of(State.SESSION_INITIALIZED_PRE_APPROVED, State.TERMINATED_SUCCESS));
transitionBuilder.put(State.SESSION_INITIALIZED, ImmutableList.of(State.SESSION_ACCEPTED, State.TERMINATED_CANCEL_OR_TIMEOUT)); transitionBuilder.put(State.SESSION_INITIALIZED, ImmutableList.of(State.SESSION_ACCEPTED, State.TERMINATED_CANCEL_OR_TIMEOUT, State.TERMINATED_DECLINED_OR_BUSY));
transitionBuilder.put(State.SESSION_INITIALIZED_PRE_APPROVED, ImmutableList.of(State.SESSION_ACCEPTED, State.TERMINATED_CANCEL_OR_TIMEOUT)); transitionBuilder.put(State.SESSION_INITIALIZED_PRE_APPROVED, ImmutableList.of(State.SESSION_ACCEPTED, State.TERMINATED_CANCEL_OR_TIMEOUT, State.TERMINATED_DECLINED_OR_BUSY));
transitionBuilder.put(State.SESSION_ACCEPTED, ImmutableList.of(State.TERMINATED_SUCCESS, State.TERMINATED_CONNECTIVITY_ERROR)); transitionBuilder.put(State.SESSION_ACCEPTED, ImmutableList.of(State.TERMINATED_SUCCESS, State.TERMINATED_CONNECTIVITY_ERROR));
VALID_TRANSITIONS = transitionBuilder.build(); VALID_TRANSITIONS = transitionBuilder.build();
} }
@ -130,6 +128,7 @@ public class JingleRtpConnection extends AbstractJingleConnection implements Web
this.webRTCWrapper.addIceCandidate(iceCandidate); this.webRTCWrapper.addIceCandidate(iceCandidate);
} else { } else {
this.pendingIceCandidates.push(iceCandidate); this.pendingIceCandidates.push(iceCandidate);
Log.d(Config.LOGTAG, id.account.getJid().asBareJid() + ": put ICE candidate on backlog");
} }
} }
} }
@ -162,11 +161,11 @@ public class JingleRtpConnection extends AbstractJingleConnection implements Web
if (transition(target)) { if (transition(target)) {
this.initiatorRtpContentMap = contentMap; this.initiatorRtpContentMap = contentMap;
if (target == State.SESSION_INITIALIZED_PRE_APPROVED) { if (target == State.SESSION_INITIALIZED_PRE_APPROVED) {
Log.d(Config.LOGTAG, "automatically accepting"); Log.d(Config.LOGTAG, id.account.getJid().asBareJid() + ": automatically accepting session-initiate");
sendSessionAccept(); sendSessionAccept();
} else { } else {
Log.d(Config.LOGTAG, "start ringing"); Log.d(Config.LOGTAG, id.account.getJid().asBareJid() + ": received not pre-approved session-initiate. start ringing");
//TODO start ringing startRinging();
} }
} else { } else {
Log.d(Config.LOGTAG, String.format("%s: received session-initiate while in state %s", id.account.getJid().asBareJid(), state)); Log.d(Config.LOGTAG, String.format("%s: received session-initiate while in state %s", id.account.getJid().asBareJid(), state));
@ -427,12 +426,16 @@ public class JingleRtpConnection extends AbstractJingleConnection implements Web
} }
case PROCEED: case PROCEED:
if (isInitiator()) { if (isInitiator()) {
return RtpEndUserState.CONNECTING; return RtpEndUserState.RINGING;
} else { } else {
return RtpEndUserState.ACCEPTING_CALL; return RtpEndUserState.ACCEPTING_CALL;
} }
case SESSION_INITIALIZED_PRE_APPROVED: case SESSION_INITIALIZED_PRE_APPROVED:
return RtpEndUserState.CONNECTING; if (isInitiator()) {
return RtpEndUserState.RINGING;
} else {
return RtpEndUserState.CONNECTING;
}
case SESSION_ACCEPTED: case SESSION_ACCEPTED:
final PeerConnection.PeerConnectionState state = webRTCWrapper.getState(); final PeerConnection.PeerConnectionState state = webRTCWrapper.getState();
if (state == PeerConnection.PeerConnectionState.CONNECTED) { if (state == PeerConnection.PeerConnectionState.CONNECTED) {
@ -483,21 +486,33 @@ public class JingleRtpConnection extends AbstractJingleConnection implements Web
case PROPOSED: case PROPOSED:
rejectCallFromProposed(); rejectCallFromProposed();
break; break;
case SESSION_INITIALIZED:
rejectCallFromSessionInitiate();
break;
default: default:
throw new IllegalStateException("Can not reject call from " + this.state); throw new IllegalStateException("Can not reject call from " + this.state);
} }
} }
public void endCall() { public void endCall() {
if (isInitiator() && isInState(State.SESSION_INITIALIZED)) { if (isInState(State.PROCEED)) {
Log.d(Config.LOGTAG, id.account.getJid().asBareJid() + ": ending call while in state PROCEED just means ending the connection");
webRTCWrapper.close();
jingleConnectionManager.finishConnection(this);
transitionOrThrow(State.TERMINATED_SUCCESS); //arguably this wasn't success; but not a real failure either
return;
}
if (isInitiator() && isInState(State.SESSION_INITIALIZED, State.SESSION_INITIALIZED_PRE_APPROVED)) {
webRTCWrapper.close(); webRTCWrapper.close();
sendSessionTerminate(Reason.CANCEL); sendSessionTerminate(Reason.CANCEL);
} else if (isInState(State.SESSION_INITIALIZED, State.SESSION_INITIALIZED_PRE_APPROVED, State.SESSION_ACCEPTED)) { return;
}
if (isInState(State.SESSION_INITIALIZED, State.SESSION_INITIALIZED_PRE_APPROVED, State.SESSION_ACCEPTED)) {
webRTCWrapper.close(); webRTCWrapper.close();
sendSessionTerminate(Reason.SUCCESS); sendSessionTerminate(Reason.SUCCESS);
} else { return;
throw new IllegalStateException("called 'endCall' while in state " + this.state);
} }
throw new IllegalStateException("called 'endCall' while in state " + this.state);
} }
private void setupWebRTC(final List<PeerConnection.IceServer> iceServers) { private void setupWebRTC(final List<PeerConnection.IceServer> iceServers) {
@ -519,6 +534,12 @@ public class JingleRtpConnection extends AbstractJingleConnection implements Web
jingleConnectionManager.finishConnection(this); jingleConnectionManager.finishConnection(this);
} }
private void rejectCallFromSessionInitiate() {
webRTCWrapper.close();
sendSessionTerminate(Reason.DECLINE);
xmppConnectionService.getNotificationService().cancelIncomingCallNotification();
}
private void sendJingleMessage(final String action) { private void sendJingleMessage(final String action) {
sendJingleMessage(action, id.with); sendJingleMessage(action, id.with);
} }
@ -534,7 +555,7 @@ public class JingleRtpConnection extends AbstractJingleConnection implements Web
private void acceptCallFromSessionInitialized() { private void acceptCallFromSessionInitialized() {
xmppConnectionService.getNotificationService().cancelIncomingCallNotification(); xmppConnectionService.getNotificationService().cancelIncomingCallNotification();
throw new IllegalStateException("accepting from this state has not been implemented yet"); sendSessionAccept();
} }
private synchronized boolean isInState(State... state) { private synchronized boolean isInState(State... state) {