2017-07-21 23:05:46 +02:00
|
|
|
/**
|
|
|
|
*
|
|
|
|
* Copyright 2017 Paul Schaub
|
|
|
|
*
|
|
|
|
* Licensed under the Apache License, Version 2.0 (the "License");
|
|
|
|
* you may not use this file except in compliance with the License.
|
|
|
|
* You may obtain a copy of the License at
|
|
|
|
*
|
|
|
|
* http://www.apache.org/licenses/LICENSE-2.0
|
|
|
|
*
|
|
|
|
* Unless required by applicable law or agreed to in writing, software
|
|
|
|
* distributed under the License is distributed on an "AS IS" BASIS,
|
|
|
|
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
|
|
* See the License for the specific language governing permissions and
|
|
|
|
* limitations under the License.
|
|
|
|
*/
|
2017-08-04 23:05:59 +02:00
|
|
|
package org.jivesoftware.smackx.jingle.component;
|
2017-07-19 15:17:12 +02:00
|
|
|
|
|
|
|
import java.util.ArrayList;
|
|
|
|
import java.util.HashMap;
|
|
|
|
import java.util.List;
|
|
|
|
import java.util.concurrent.ConcurrentHashMap;
|
|
|
|
import java.util.logging.Level;
|
|
|
|
import java.util.logging.Logger;
|
|
|
|
|
|
|
|
import org.jivesoftware.smack.SmackException;
|
2017-07-28 14:02:32 +02:00
|
|
|
import org.jivesoftware.smack.XMPPConnection;
|
2017-07-19 15:17:12 +02:00
|
|
|
import org.jivesoftware.smack.XMPPException;
|
|
|
|
import org.jivesoftware.smack.packet.IQ;
|
2017-07-28 00:55:44 +02:00
|
|
|
import org.jivesoftware.smack.util.Async;
|
2017-07-27 17:35:16 +02:00
|
|
|
import org.jivesoftware.smackx.jingle.JingleDescriptionManager;
|
2017-07-21 23:05:46 +02:00
|
|
|
import org.jivesoftware.smackx.jingle.JingleManager;
|
2017-07-27 17:35:16 +02:00
|
|
|
import org.jivesoftware.smackx.jingle.element.JingleAction;
|
|
|
|
import org.jivesoftware.smackx.jingle.element.JingleContentElement;
|
2017-07-21 23:05:46 +02:00
|
|
|
import org.jivesoftware.smackx.jingle.element.JingleElement;
|
|
|
|
import org.jivesoftware.smackx.jingle.element.JingleReasonElement;
|
|
|
|
import org.jivesoftware.smackx.jingle.exception.UnsupportedDescriptionException;
|
|
|
|
import org.jivesoftware.smackx.jingle.exception.UnsupportedSecurityException;
|
|
|
|
import org.jivesoftware.smackx.jingle.exception.UnsupportedTransportException;
|
2017-07-27 17:35:16 +02:00
|
|
|
import org.jivesoftware.smackx.jingle.util.Role;
|
2017-07-19 15:17:12 +02:00
|
|
|
|
|
|
|
import org.jxmpp.jid.FullJid;
|
|
|
|
|
|
|
|
/**
|
2017-07-21 23:05:46 +02:00
|
|
|
* Class that represents a Jingle session.
|
2017-07-19 15:17:12 +02:00
|
|
|
*/
|
2017-07-21 23:51:06 +02:00
|
|
|
public class JingleSession {
|
|
|
|
private static final Logger LOGGER = Logger.getLogger(JingleSession.class.getName());
|
2017-07-19 15:17:12 +02:00
|
|
|
|
2017-07-21 23:51:06 +02:00
|
|
|
private final ConcurrentHashMap<String, JingleContent> contents = new ConcurrentHashMap<>();
|
2017-07-29 19:31:16 +02:00
|
|
|
private final ConcurrentHashMap<String, JingleContent> proposedContents = new ConcurrentHashMap<>();
|
2017-07-19 15:17:12 +02:00
|
|
|
private final JingleManager jingleManager;
|
|
|
|
|
|
|
|
private final FullJid initiator, responder;
|
|
|
|
private final Role role;
|
|
|
|
private final String sessionId;
|
|
|
|
|
2017-07-28 14:02:32 +02:00
|
|
|
public enum SessionState {
|
|
|
|
fresh, //pre-session-inititate
|
|
|
|
pending, //pre-session-accept
|
|
|
|
active, //pre-session-terminate
|
|
|
|
ended //post-session-terminate
|
|
|
|
}
|
|
|
|
|
|
|
|
private SessionState sessionState;
|
|
|
|
|
2017-07-21 23:51:06 +02:00
|
|
|
public JingleSession(JingleManager manager, FullJid initiator, FullJid responder, Role role, String sessionId) {
|
2017-07-19 15:17:12 +02:00
|
|
|
this.jingleManager = manager;
|
|
|
|
this.initiator = initiator;
|
|
|
|
this.responder = responder;
|
|
|
|
this.role = role;
|
|
|
|
this.sessionId = sessionId;
|
2017-07-28 14:02:32 +02:00
|
|
|
this.sessionState = SessionState.fresh;
|
2017-07-19 15:17:12 +02:00
|
|
|
}
|
|
|
|
|
2017-07-21 23:51:06 +02:00
|
|
|
public static JingleSession fromSessionInitiate(JingleManager manager, JingleElement initiate)
|
2017-07-19 15:17:12 +02:00
|
|
|
throws UnsupportedSecurityException, UnsupportedDescriptionException, UnsupportedTransportException {
|
|
|
|
if (initiate.getAction() != JingleAction.session_initiate) {
|
|
|
|
throw new IllegalArgumentException("Jingle-Action MUST be 'session-initiate'.");
|
|
|
|
}
|
|
|
|
|
2017-08-04 22:48:33 +02:00
|
|
|
JingleSession session = new JingleSession(manager, initiate.getInitiator(), manager.getConnection().getUser().asFullJidOrThrow(), Role.responder, initiate.getSid());
|
2017-07-19 15:17:12 +02:00
|
|
|
List<JingleContentElement> initiateContents = initiate.getContents();
|
|
|
|
|
|
|
|
for (JingleContentElement content : initiateContents) {
|
2017-08-03 23:01:55 +02:00
|
|
|
session.addContent(content, manager);
|
2017-07-19 15:17:12 +02:00
|
|
|
}
|
|
|
|
|
2017-07-28 14:02:32 +02:00
|
|
|
session.sessionState = SessionState.pending;
|
|
|
|
|
2017-07-19 15:17:12 +02:00
|
|
|
return session;
|
|
|
|
}
|
|
|
|
|
2017-07-28 14:02:32 +02:00
|
|
|
public void initiate(XMPPConnection connection) throws SmackException.NotConnectedException, InterruptedException, XMPPException.XMPPErrorException, SmackException.NoResponseException {
|
2017-07-29 19:31:16 +02:00
|
|
|
if (this.sessionState != SessionState.fresh) {
|
|
|
|
throw new IllegalStateException("Session is not in fresh state.");
|
|
|
|
}
|
|
|
|
|
2017-07-28 14:02:32 +02:00
|
|
|
connection.createStanzaCollectorAndSend(createSessionInitiate()).nextResultOrThrow();
|
|
|
|
this.sessionState = SessionState.pending;
|
|
|
|
}
|
|
|
|
|
2017-07-29 19:31:16 +02:00
|
|
|
public void accept(XMPPConnection connection) throws SmackException.NotConnectedException, InterruptedException, XMPPException.XMPPErrorException, SmackException.NoResponseException {
|
|
|
|
if (this.sessionState != SessionState.pending) {
|
|
|
|
throw new IllegalStateException("Session is not in pending state.");
|
|
|
|
}
|
|
|
|
|
2017-07-29 22:21:36 +02:00
|
|
|
for (JingleContent content : contents.values()) {
|
|
|
|
content.onAccept(connection);
|
|
|
|
}
|
|
|
|
|
2017-07-29 19:31:16 +02:00
|
|
|
connection.createStanzaCollectorAndSend(createSessionAccept()).nextResultOrThrow();
|
|
|
|
this.sessionState = SessionState.active;
|
|
|
|
}
|
|
|
|
|
2017-07-27 00:12:42 +02:00
|
|
|
public JingleElement createSessionInitiate() {
|
|
|
|
if (role != Role.initiator) {
|
|
|
|
throw new IllegalStateException("Sessions role is not initiator.");
|
|
|
|
}
|
|
|
|
|
|
|
|
List<JingleContentElement> contentElements = new ArrayList<>();
|
|
|
|
for (JingleContent c : contents.values()) {
|
|
|
|
contentElements.add(c.getElement());
|
|
|
|
}
|
|
|
|
|
|
|
|
return JingleElement.createSessionInitiate(getInitiator(), getResponder(), getSessionId(), contentElements);
|
|
|
|
}
|
|
|
|
|
2017-07-29 19:31:16 +02:00
|
|
|
public JingleElement createSessionAccept() {
|
|
|
|
if (role != Role.responder) {
|
|
|
|
throw new IllegalStateException("Sessions role is not responder.");
|
|
|
|
}
|
|
|
|
|
|
|
|
List<JingleContentElement> contentElements = new ArrayList<>();
|
|
|
|
for (JingleContent c : contents.values()) {
|
|
|
|
contentElements.add(c.getElement());
|
|
|
|
}
|
|
|
|
|
|
|
|
return JingleElement.createSessionAccept(getInitiator(), getResponder(), getSessionId(), contentElements);
|
|
|
|
}
|
|
|
|
|
2017-07-19 15:17:12 +02:00
|
|
|
public IQ handleJingleRequest(JingleElement request) {
|
|
|
|
switch (request.getAction()) {
|
2017-07-29 19:31:16 +02:00
|
|
|
case content_modify:
|
|
|
|
case description_info:
|
|
|
|
case security_info:
|
|
|
|
case session_info:
|
|
|
|
case transport_accept:
|
|
|
|
case transport_info:
|
|
|
|
case transport_reject:
|
|
|
|
case transport_replace:
|
|
|
|
return getSoleAffectedContentOrThrow(request).handleJingleRequest(request, jingleManager.getConnection());
|
2017-07-19 15:17:12 +02:00
|
|
|
case content_accept:
|
|
|
|
return handleContentAccept(request);
|
|
|
|
case content_add:
|
|
|
|
return handleContentAdd(request);
|
|
|
|
case content_reject:
|
|
|
|
return handleContentReject(request);
|
|
|
|
case content_remove:
|
|
|
|
return handleContentRemove(request);
|
|
|
|
case session_accept:
|
|
|
|
return handleSessionAccept(request);
|
|
|
|
case session_initiate:
|
|
|
|
return handleSessionInitiate(request);
|
|
|
|
case session_terminate:
|
|
|
|
return handleSessionTerminate(request);
|
|
|
|
default:
|
2017-07-29 19:31:16 +02:00
|
|
|
throw new AssertionError("Illegal jingle action: " + request.getAction());
|
2017-07-19 15:17:12 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2017-07-29 19:31:16 +02:00
|
|
|
/* ############## Processed in this class ############## */
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Handle incoming session-accept stanza.
|
|
|
|
* @param request session-accept stanza.
|
|
|
|
* @return result.
|
|
|
|
*/
|
|
|
|
private IQ handleSessionAccept(final JingleElement request) {
|
|
|
|
this.sessionState = SessionState.active;
|
2017-07-28 00:55:44 +02:00
|
|
|
|
2017-07-29 19:31:16 +02:00
|
|
|
for (final JingleContent content : contents.values()) {
|
|
|
|
Async.go(new Runnable() {
|
|
|
|
@Override
|
|
|
|
public void run() {
|
|
|
|
content.handleSessionAccept(request, jingleManager.getConnection());
|
2017-07-28 00:55:44 +02:00
|
|
|
}
|
2017-07-29 19:31:16 +02:00
|
|
|
});
|
|
|
|
}
|
|
|
|
|
|
|
|
return IQ.createResultIQ(request);
|
|
|
|
}
|
|
|
|
|
|
|
|
private IQ handleSessionInitiate(JingleElement request) {
|
|
|
|
JingleDescription<?> description = getSoleContentOrThrow().getDescription();
|
|
|
|
JingleDescriptionManager descriptionManager = jingleManager.getDescriptionManager(description.getNamespace());
|
|
|
|
|
|
|
|
if (descriptionManager == null) {
|
|
|
|
LOGGER.log(Level.WARNING, "Unsupported description type: " + description.getNamespace());
|
|
|
|
return JingleElement.createSessionTerminate(getPeer(), getSessionId(), JingleReasonElement.Reason.unsupported_applications);
|
|
|
|
}
|
|
|
|
|
|
|
|
descriptionManager.notifySessionInitiate(this);
|
2017-07-19 15:17:12 +02:00
|
|
|
|
|
|
|
return IQ.createResultIQ(request);
|
|
|
|
}
|
|
|
|
|
|
|
|
private IQ handleSessionTerminate(JingleElement request) {
|
2017-07-28 14:02:32 +02:00
|
|
|
this.sessionState = SessionState.ended;
|
2017-07-19 15:17:12 +02:00
|
|
|
JingleReasonElement reason = request.getReason();
|
2017-07-19 23:15:17 +02:00
|
|
|
|
2017-07-19 15:17:12 +02:00
|
|
|
if (reason == null) {
|
|
|
|
throw new AssertionError("Reason MUST not be null! (I guess)...");
|
|
|
|
}
|
2017-07-19 23:15:17 +02:00
|
|
|
|
2017-07-28 00:55:44 +02:00
|
|
|
//TODO: Inform client.
|
|
|
|
jingleManager.removeSession(this);
|
|
|
|
|
2017-07-19 15:17:12 +02:00
|
|
|
return IQ.createResultIQ(request);
|
|
|
|
}
|
|
|
|
|
2017-07-29 19:31:16 +02:00
|
|
|
private IQ handleContentAccept(final JingleElement request) {
|
|
|
|
for (JingleContentElement a : request.getContents()) {
|
|
|
|
final JingleContent accepted = proposedContents.get(a.getName());
|
|
|
|
|
|
|
|
if (accepted == null) {
|
|
|
|
throw new AssertionError("Illegal content name!");
|
|
|
|
}
|
|
|
|
|
|
|
|
proposedContents.remove(accepted.getName());
|
|
|
|
contents.put(accepted.getName(), accepted);
|
2017-07-19 15:17:12 +02:00
|
|
|
|
2017-07-29 19:31:16 +02:00
|
|
|
Async.go(new Runnable() {
|
|
|
|
@Override
|
|
|
|
public void run() {
|
|
|
|
accepted.handleContentAccept(request, jingleManager.getConnection());
|
|
|
|
}
|
|
|
|
});
|
2017-07-28 14:02:32 +02:00
|
|
|
}
|
2017-07-29 19:31:16 +02:00
|
|
|
|
|
|
|
return IQ.createResultIQ(request);
|
2017-07-19 15:17:12 +02:00
|
|
|
}
|
|
|
|
|
2017-07-29 19:31:16 +02:00
|
|
|
private IQ handleContentAdd(JingleElement request) {
|
|
|
|
final JingleContent proposed = getSoleProposedContentOrThrow(request);
|
|
|
|
|
|
|
|
final JingleDescriptionManager descriptionManager = jingleManager.getDescriptionManager(proposed.getDescription().getNamespace());
|
2017-07-27 23:59:26 +02:00
|
|
|
|
|
|
|
if (descriptionManager == null) {
|
2017-07-29 19:31:16 +02:00
|
|
|
throw new AssertionError("DescriptionManager is null: " + proposed.getDescription().getNamespace());
|
2017-07-27 23:59:26 +02:00
|
|
|
}
|
|
|
|
|
2017-07-29 19:31:16 +02:00
|
|
|
Async.go(new Runnable() {
|
|
|
|
@Override
|
|
|
|
public void run() {
|
|
|
|
descriptionManager.notifyContentAdd(JingleSession.this, proposed);
|
|
|
|
}
|
|
|
|
});
|
2017-07-27 23:59:26 +02:00
|
|
|
|
|
|
|
return IQ.createResultIQ(request);
|
2017-07-19 15:17:12 +02:00
|
|
|
}
|
|
|
|
|
2017-07-29 19:31:16 +02:00
|
|
|
private IQ handleContentReject(JingleElement request) {
|
|
|
|
for (JingleContentElement r : request.getContents()) {
|
|
|
|
final JingleContent rejected = proposedContents.get(r.getName());
|
|
|
|
|
|
|
|
if (rejected == null) {
|
|
|
|
throw new AssertionError("Illegal content name!");
|
|
|
|
}
|
|
|
|
|
|
|
|
proposedContents.remove(rejected.getName());
|
2017-07-19 15:17:12 +02:00
|
|
|
|
2017-07-29 19:31:16 +02:00
|
|
|
/*
|
|
|
|
Async.go(new Runnable() {
|
|
|
|
@Override
|
|
|
|
public void run() {
|
|
|
|
rejected.handleContentReject(request, jingleManager.getConnection());
|
|
|
|
}
|
|
|
|
});
|
|
|
|
*/
|
2017-07-19 15:17:12 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
return IQ.createResultIQ(request);
|
|
|
|
}
|
|
|
|
|
2017-07-29 19:31:16 +02:00
|
|
|
private IQ handleContentRemove(final JingleElement request) {
|
|
|
|
for (JingleContentElement r : request.getContents()) {
|
|
|
|
final JingleContent removed = contents.get(r.getName());
|
2017-07-19 15:17:12 +02:00
|
|
|
|
2017-07-29 19:31:16 +02:00
|
|
|
if (removed == null) {
|
|
|
|
throw new AssertionError("Illegal content name!");
|
2017-07-19 15:17:12 +02:00
|
|
|
}
|
|
|
|
|
2017-07-29 19:31:16 +02:00
|
|
|
contents.remove(removed.getName());
|
2017-07-19 15:17:12 +02:00
|
|
|
|
2017-07-29 19:31:16 +02:00
|
|
|
Async.go(new Runnable() {
|
|
|
|
@Override
|
|
|
|
public void run() {
|
|
|
|
removed.handleContentRemove(JingleSession.this, jingleManager.getConnection());
|
|
|
|
}
|
|
|
|
});
|
2017-07-19 15:17:12 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
return IQ.createResultIQ(request);
|
|
|
|
}
|
|
|
|
|
2017-07-29 19:31:16 +02:00
|
|
|
/* ############## Processed further down ############## */
|
2017-07-19 15:17:12 +02:00
|
|
|
|
2017-07-29 19:31:16 +02:00
|
|
|
private IQ handleContentModify(final JingleElement request) {
|
|
|
|
final JingleContent content = getSoleAffectedContentOrThrow(request);
|
2017-07-19 15:17:12 +02:00
|
|
|
|
2017-07-29 19:31:16 +02:00
|
|
|
Async.go(new Runnable() {
|
|
|
|
@Override
|
|
|
|
public void run() {
|
|
|
|
content.handleContentModify(request, jingleManager.getConnection());
|
2017-07-19 15:17:12 +02:00
|
|
|
}
|
2017-07-29 19:31:16 +02:00
|
|
|
});
|
2017-07-19 15:17:12 +02:00
|
|
|
|
|
|
|
return IQ.createResultIQ(request);
|
|
|
|
}
|
|
|
|
|
2017-07-29 19:31:16 +02:00
|
|
|
private IQ handleDescriptionInfo(final JingleElement request) {
|
|
|
|
final JingleContent content = getSoleAffectedContentOrThrow(request);
|
2017-07-19 15:17:12 +02:00
|
|
|
|
2017-07-29 19:31:16 +02:00
|
|
|
Async.go(new Runnable() {
|
|
|
|
@Override
|
|
|
|
public void run() {
|
|
|
|
content.handleDescriptionInfo(request, jingleManager.getConnection());
|
2017-07-28 00:55:44 +02:00
|
|
|
}
|
2017-07-29 19:31:16 +02:00
|
|
|
});
|
2017-07-28 00:55:44 +02:00
|
|
|
|
|
|
|
return IQ.createResultIQ(request);
|
2017-07-19 15:17:12 +02:00
|
|
|
}
|
|
|
|
|
2017-07-29 19:31:16 +02:00
|
|
|
private IQ handleSecurityInfo(final JingleElement request) {
|
|
|
|
final JingleContent content = getSoleAffectedContentOrThrow(request);
|
|
|
|
Async.go(new Runnable() {
|
|
|
|
@Override
|
|
|
|
public void run() {
|
|
|
|
content.handleSecurityInfo(request, jingleManager.getConnection());
|
|
|
|
}
|
|
|
|
});
|
2017-07-19 15:17:12 +02:00
|
|
|
|
2017-07-29 19:31:16 +02:00
|
|
|
return IQ.createResultIQ(request);
|
2017-07-19 15:17:12 +02:00
|
|
|
}
|
|
|
|
|
2017-07-29 19:31:16 +02:00
|
|
|
private IQ handleSessionInfo(final JingleElement request) {
|
|
|
|
final JingleContent content = getSoleAffectedContentOrThrow(request);
|
|
|
|
Async.go(new Runnable() {
|
|
|
|
@Override
|
|
|
|
public void run() {
|
|
|
|
content.handleSessionInfo(request, jingleManager.getConnection());
|
|
|
|
}
|
|
|
|
});
|
|
|
|
|
|
|
|
return IQ.createResultIQ(request);
|
2017-07-19 15:17:12 +02:00
|
|
|
}
|
|
|
|
|
2017-07-29 19:31:16 +02:00
|
|
|
private IQ handleTransportAccept(final JingleElement request) {
|
|
|
|
final JingleContent content = getSoleAffectedContentOrThrow(request);
|
|
|
|
Async.go(new Runnable() {
|
|
|
|
@Override
|
|
|
|
public void run() {
|
|
|
|
content.handleTransportAccept(request, jingleManager.getConnection());
|
|
|
|
}
|
|
|
|
});
|
2017-07-19 15:17:12 +02:00
|
|
|
|
2017-07-29 19:31:16 +02:00
|
|
|
return IQ.createResultIQ(request);
|
|
|
|
}
|
2017-07-19 15:17:12 +02:00
|
|
|
|
2017-07-29 19:31:16 +02:00
|
|
|
private IQ handleTransportInfo(final JingleElement request) {
|
|
|
|
final JingleContent content = getSoleAffectedContentOrThrow(request);
|
|
|
|
Async.go(new Runnable() {
|
|
|
|
@Override
|
|
|
|
public void run() {
|
|
|
|
content.handleTransportInfo(request, jingleManager.getConnection());
|
2017-07-19 15:17:12 +02:00
|
|
|
}
|
2017-07-29 19:31:16 +02:00
|
|
|
});
|
2017-07-19 15:17:12 +02:00
|
|
|
|
2017-07-29 19:31:16 +02:00
|
|
|
return IQ.createResultIQ(request);
|
|
|
|
}
|
2017-07-19 15:17:12 +02:00
|
|
|
|
2017-07-29 19:31:16 +02:00
|
|
|
private IQ handleTransportReject(final JingleElement request) {
|
|
|
|
final JingleContent content = getSoleAffectedContentOrThrow(request);
|
|
|
|
Async.go(new Runnable() {
|
|
|
|
@Override
|
|
|
|
public void run() {
|
|
|
|
content.handleTransportReject(request, jingleManager.getConnection());
|
2017-07-19 15:17:12 +02:00
|
|
|
}
|
2017-07-29 19:31:16 +02:00
|
|
|
});
|
2017-07-19 15:17:12 +02:00
|
|
|
|
2017-07-29 19:31:16 +02:00
|
|
|
return IQ.createResultIQ(request);
|
|
|
|
}
|
2017-07-19 15:17:12 +02:00
|
|
|
|
2017-07-29 19:31:16 +02:00
|
|
|
private IQ handleTransportReplace(final JingleElement request) {
|
|
|
|
final JingleContent content = getSoleAffectedContentOrThrow(request);
|
|
|
|
Async.go(new Runnable() {
|
|
|
|
@Override
|
|
|
|
public void run() {
|
|
|
|
content.handleTransportReplace(request, jingleManager.getConnection());
|
2017-07-19 15:17:12 +02:00
|
|
|
}
|
2017-07-29 19:31:16 +02:00
|
|
|
});
|
2017-07-19 15:17:12 +02:00
|
|
|
|
|
|
|
return IQ.createResultIQ(request);
|
|
|
|
}
|
|
|
|
|
2017-07-29 19:31:16 +02:00
|
|
|
/* ################ Other getters and setters ############### */
|
2017-07-19 15:17:12 +02:00
|
|
|
|
|
|
|
public FullJid getInitiator() {
|
|
|
|
return initiator;
|
|
|
|
}
|
|
|
|
|
|
|
|
public FullJid getResponder() {
|
|
|
|
return responder;
|
|
|
|
}
|
|
|
|
|
|
|
|
public FullJid getPeer() {
|
|
|
|
return role == Role.initiator ? responder : initiator;
|
|
|
|
}
|
|
|
|
|
|
|
|
public FullJid getOurJid() {
|
|
|
|
return role == Role.initiator ? initiator : responder;
|
|
|
|
}
|
|
|
|
|
2017-07-22 00:26:50 +02:00
|
|
|
public boolean isInitiator() {
|
|
|
|
return role == Role.initiator;
|
|
|
|
}
|
|
|
|
|
|
|
|
public boolean isResponder() {
|
|
|
|
return role == Role.responder;
|
|
|
|
}
|
|
|
|
|
2017-07-19 15:17:12 +02:00
|
|
|
public String getSessionId() {
|
|
|
|
return sessionId;
|
|
|
|
}
|
|
|
|
|
|
|
|
public JingleManager getJingleManager() {
|
|
|
|
return jingleManager;
|
|
|
|
}
|
|
|
|
|
2017-07-21 23:51:06 +02:00
|
|
|
private HashMap<JingleContentElement, JingleContent> getAffectedContents(JingleElement request) {
|
|
|
|
HashMap<JingleContentElement, JingleContent> map = new HashMap<>();
|
2017-07-19 15:17:12 +02:00
|
|
|
for (JingleContentElement e : request.getContents()) {
|
2017-07-21 23:51:06 +02:00
|
|
|
JingleContent c = contents.get(e.getName());
|
2017-07-19 15:17:12 +02:00
|
|
|
if (c == null) {
|
|
|
|
throw new AssertionError("Unknown content: " + e.getName());
|
|
|
|
}
|
|
|
|
map.put(e, c);
|
|
|
|
}
|
|
|
|
return map;
|
|
|
|
}
|
2017-07-28 14:02:32 +02:00
|
|
|
|
2017-07-29 19:31:16 +02:00
|
|
|
private JingleContent getSoleAffectedContentOrThrow(JingleElement request) {
|
|
|
|
if (request.getContents().size() != 1) {
|
|
|
|
throw new AssertionError("More/less than 1 content in request!");
|
|
|
|
}
|
|
|
|
|
|
|
|
JingleContent content = contents.get(request.getContents().get(0).getName());
|
|
|
|
if (content == null) {
|
|
|
|
throw new AssertionError("Illegal content name!");
|
|
|
|
}
|
|
|
|
|
|
|
|
return content;
|
|
|
|
}
|
|
|
|
|
|
|
|
private JingleContent getSoleProposedContentOrThrow(JingleElement request) {
|
|
|
|
if (request.getContents().size() != 1) {
|
|
|
|
throw new AssertionError("More/less than 1 content in request!");
|
|
|
|
}
|
|
|
|
|
|
|
|
return JingleContent.fromElement(request.getContents().get(0));
|
|
|
|
}
|
|
|
|
|
|
|
|
public void addContent(JingleContent content) {
|
|
|
|
contents.put(content.getName(), content);
|
|
|
|
content.setParent(this);
|
|
|
|
}
|
|
|
|
|
2017-08-03 23:01:55 +02:00
|
|
|
public void addContent(JingleContentElement content, JingleManager manager)
|
2017-07-29 19:31:16 +02:00
|
|
|
throws UnsupportedSecurityException, UnsupportedTransportException, UnsupportedDescriptionException {
|
|
|
|
addContent(JingleContent.fromElement(content));
|
|
|
|
}
|
|
|
|
|
|
|
|
public ConcurrentHashMap<String, JingleContent> getContents() {
|
|
|
|
return contents;
|
|
|
|
}
|
|
|
|
|
|
|
|
public JingleContent getContent(String name) {
|
|
|
|
return contents.get(name);
|
|
|
|
}
|
|
|
|
|
|
|
|
public JingleContent getSoleContentOrThrow() {
|
|
|
|
if (contents.isEmpty()) {
|
|
|
|
return null;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (contents.size() > 1) {
|
|
|
|
throw new IllegalStateException();
|
|
|
|
}
|
|
|
|
|
|
|
|
return contents.values().iterator().next();
|
|
|
|
}
|
|
|
|
|
2017-07-28 14:02:32 +02:00
|
|
|
public SessionState getSessionState() {
|
|
|
|
return sessionState;
|
|
|
|
}
|
2017-07-27 23:31:04 +02:00
|
|
|
}
|