parse 'accept' messages

This commit is contained in:
Daniel Gultsch 2020-04-08 12:17:46 +02:00
parent 9edadc9835
commit f7d1e02d4b
2 changed files with 41 additions and 7 deletions

View File

@ -77,6 +77,19 @@ public class JingleConnectionManager extends AbstractConnectionManager {
if (sessionId == null) { if (sessionId == null) {
return; return;
} }
if ("accept".equals(message.getName())) {
for (AbstractJingleConnection connection : connections.values()) {
if (connection instanceof JingleRtpConnection) {
final JingleRtpConnection rtpConnection = (JingleRtpConnection) connection;
final AbstractJingleConnection.Id id = connection.getId();
if (id.account == account && id.sessionId.equals(sessionId)) {
rtpConnection.deliveryMessage(from, message);
return;
}
}
}
return;
}
final boolean carbonCopy = from.asBareJid().equals(account.getJid().asBareJid()); final boolean carbonCopy = from.asBareJid().equals(account.getJid().asBareJid());
final Jid with; final Jid with;
if (account.getJid().asBareJid().equals(from.asBareJid())) { if (account.getJid().asBareJid().equals(from.asBareJid())) {

View File

@ -239,11 +239,28 @@ public class JingleRtpConnection extends AbstractJingleConnection implements Web
case "reject": case "reject":
receiveReject(from, message); receiveReject(from, message);
break; break;
case "accept":
receiveAccept(from, message);
break;
default: default:
break; break;
} }
} }
private void receiveAccept(Jid from, Element message) {
final boolean originatedFromMyself = from.asBareJid().equals(id.account.getJid().asBareJid());
if (originatedFromMyself) {
if (transition(State.ACCEPTED)) {
this.xmppConnectionService.getNotificationService().cancelIncomingCallNotification();
this.jingleConnectionManager.finishConnection(this);
} else {
Log.d(Config.LOGTAG,id.account.getJid().asBareJid()+": unable to transition to accept because already in state="+this.state);
}
} else {
Log.d(Config.LOGTAG,id.account.getJid().asBareJid()+": ignoring 'accept' from "+from);
}
}
private void receiveReject(Jid from, Element message) { private void receiveReject(Jid from, Element message) {
final boolean originatedFromMyself = from.asBareJid().equals(id.account.getJid().asBareJid()); final boolean originatedFromMyself = from.asBareJid().equals(id.account.getJid().asBareJid());
//reject from another one of my clients //reject from another one of my clients
@ -381,6 +398,8 @@ public class JingleRtpConnection extends AbstractJingleConnection implements Web
return RtpEndUserState.CONNECTING; return RtpEndUserState.CONNECTING;
} else if (state == PeerConnection.PeerConnectionState.CLOSED) { } else if (state == PeerConnection.PeerConnectionState.CLOSED) {
return RtpEndUserState.ENDING_CALL; return RtpEndUserState.ENDING_CALL;
} else if (state == PeerConnection.PeerConnectionState.FAILED) {
return RtpEndUserState.CONNECTIVITY_ERROR;
} else { } else {
return RtpEndUserState.ENDING_CALL; return RtpEndUserState.ENDING_CALL;
} }
@ -452,10 +471,8 @@ public class JingleRtpConnection extends AbstractJingleConnection implements Web
private void acceptCallFromProposed() { private void acceptCallFromProposed() {
transitionOrThrow(State.PROCEED); transitionOrThrow(State.PROCEED);
xmppConnectionService.getNotificationService().cancelIncomingCallNotification(); xmppConnectionService.getNotificationService().cancelIncomingCallNotification();
//Note that Movim needs 'accept', correct is 'proceed' https://github.com/movim/movim/issues/916 this.sendJingleMessage("accept", id.account.getJid().asBareJid());
this.sendJingleMessage("proceed"); this.sendJingleMessage("proceed");
//TODO send `accept` to self
} }
private void rejectCallFromProposed() { private void rejectCallFromProposed() {
@ -466,9 +483,13 @@ public class JingleRtpConnection extends AbstractJingleConnection implements Web
} }
private void sendJingleMessage(final String action) { private void sendJingleMessage(final String action) {
sendJingleMessage(action, id.with);
}
private void sendJingleMessage(final String action, final Jid to) {
final MessagePacket messagePacket = new MessagePacket(); final MessagePacket messagePacket = new MessagePacket();
messagePacket.setType(MessagePacket.TYPE_CHAT); //we want to carbon copy those messagePacket.setType(MessagePacket.TYPE_CHAT); //we want to carbon copy those
messagePacket.setTo(id.with); messagePacket.setTo(to);
messagePacket.addChild(action, Namespace.JINGLE_MESSAGE).setAttribute("id", id.sessionId); messagePacket.addChild(action, Namespace.JINGLE_MESSAGE).setAttribute("id", id.sessionId);
Log.d(Config.LOGTAG, messagePacket.toString()); Log.d(Config.LOGTAG, messagePacket.toString());
xmppConnectionService.sendMessagePacket(id.account, messagePacket); xmppConnectionService.sendMessagePacket(id.account, messagePacket);