RtpSessionActivity: throw instead of finish when session wasn’t found

This commit is contained in:
Daniel Gultsch 2020-05-28 09:22:58 +02:00
parent 63ba21a512
commit 59d1a2982e
2 changed files with 20 additions and 5 deletions

View file

@ -412,14 +412,12 @@ public class RtpSessionActivity extends XmppActivity implements XmppConnectionSe
final WeakReference<JingleRtpConnection> reference = xmppConnectionService.getJingleConnectionManager()
.findJingleRtpConnection(account, with, sessionId);
if (reference == null || reference.get() == null) {
Log.e(Config.LOGTAG,"failed to initialize activity with running rtp session. session not found");
finish();
return true;
throw new IllegalStateException("failed to initialize activity with running rtp session. session not found");
}
this.rtpConnectionReference = reference;
final RtpEndUserState currentState = requireRtpConnection().getEndUserState();
if (currentState == RtpEndUserState.ENDED) {
Log.e(Config.LOGTAG,"failed to initialize activity with running rtp session. session had ended");
reference.get().throwStateTransitionException();
finish();
return true;
}
@ -795,7 +793,7 @@ public class RtpSessionActivity extends XmppActivity implements XmppConnectionSe
try {
videoTrack.addSink(surfaceViewRenderer);
} catch (final IllegalStateException e) {
Log.e(Config.LOGTAG,"possible race condition on trying to display video track. ignoring",e);
Log.e(Config.LOGTAG, "possible race condition on trying to display video track. ignoring", e);
}
}

View file

@ -123,6 +123,7 @@ public class JingleRtpConnection extends AbstractJingleConnection implements Web
private final ArrayDeque<IceCandidate> pendingIceCandidates = new ArrayDeque<>();
private final Message message;
private State state = State.NULL;
private StateTransitionException stateTransitionException;
private Set<Media> proposedMedia;
private RtpContentMap initiatorRtpContentMap;
private RtpContentMap responderRtpContentMap;
@ -771,6 +772,13 @@ public class JingleRtpConnection extends AbstractJingleConnection implements Web
xmppConnectionService.sendIqPacket(id.account, jinglePacket.generateResponse(IqPacket.TYPE.RESULT), null);
}
public void throwStateTransitionException() {
final StateTransitionException exception = this.stateTransitionException;
if (exception != null) {
throw new IllegalStateException(String.format("Transition to %s did not call finish", exception.state), exception);
}
}
public RtpEndUserState getEndUserState() {
switch (this.state) {
case PROPOSED:
@ -983,6 +991,7 @@ public class JingleRtpConnection extends AbstractJingleConnection implements Web
final Collection<State> validTransitions = VALID_TRANSITIONS.get(this.state);
if (validTransitions != null && validTransitions.contains(target)) {
this.state = target;
this.stateTransitionException = new StateTransitionException(target);
if (runnable != null) {
runnable.run();
}
@ -1231,4 +1240,12 @@ public class JingleRtpConnection extends AbstractJingleConnection implements Web
private interface OnIceServersDiscovered {
void onIceServersDiscovered(List<PeerConnection.IceServer> iceServers);
}
private static class StateTransitionException extends Exception {
private final State state;
private StateTransitionException(final State state) {
this.state = state;
}
}
}