2017-05-30 08:45:27 +02:00
|
|
|
/**
|
|
|
|
*
|
|
|
|
* Copyright 2017 Florian Schmaus
|
|
|
|
*
|
|
|
|
* 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.
|
|
|
|
*/
|
|
|
|
package org.jivesoftware.smackx.jingle;
|
|
|
|
|
2017-06-18 16:47:49 +02:00
|
|
|
import org.jxmpp.jid.FullJid;
|
2017-05-30 08:45:27 +02:00
|
|
|
|
|
|
|
public class JingleSession {
|
|
|
|
|
2017-06-18 16:47:49 +02:00
|
|
|
protected final FullJid local;
|
2017-05-30 08:45:27 +02:00
|
|
|
|
2017-06-18 16:47:49 +02:00
|
|
|
protected final FullJid remote;
|
2017-05-30 08:45:27 +02:00
|
|
|
|
2017-06-18 16:47:49 +02:00
|
|
|
protected final Role role;
|
2017-05-30 08:45:27 +02:00
|
|
|
|
2017-06-18 16:47:49 +02:00
|
|
|
protected final String sid;
|
|
|
|
|
|
|
|
public JingleSession(FullJid initiator, FullJid responder, Role role, String sid) {
|
|
|
|
if (role == Role.initiator) {
|
|
|
|
this.local = initiator;
|
|
|
|
this.remote = responder;
|
|
|
|
} else {
|
|
|
|
this.local = responder;
|
|
|
|
this.remote = initiator;
|
|
|
|
}
|
2017-05-30 08:45:27 +02:00
|
|
|
this.sid = sid;
|
2017-06-18 16:47:49 +02:00
|
|
|
this.role = role;
|
|
|
|
}
|
|
|
|
|
|
|
|
public FullJid getInitiator() {
|
|
|
|
return isInitiator() ? local : remote;
|
|
|
|
}
|
|
|
|
|
|
|
|
public boolean isInitiator() {
|
|
|
|
return role == Role.initiator;
|
|
|
|
}
|
|
|
|
|
|
|
|
public FullJid getResponder() {
|
|
|
|
return isResponder() ? local : remote;
|
|
|
|
}
|
|
|
|
|
|
|
|
public boolean isResponder() {
|
|
|
|
return role == Role.responder;
|
|
|
|
}
|
|
|
|
|
|
|
|
public String getSessionId() {
|
|
|
|
return sid;
|
|
|
|
}
|
|
|
|
|
|
|
|
public FullJidAndSessionId getFullJidAndSessionId() {
|
|
|
|
return new FullJidAndSessionId(remote, sid);
|
2017-05-30 08:45:27 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public int hashCode() {
|
2017-06-18 16:47:49 +02:00
|
|
|
int hashCode = 31 + getInitiator().hashCode();
|
|
|
|
hashCode = 31 * hashCode + getResponder().hashCode();
|
|
|
|
hashCode = 31 * hashCode + getSessionId().hashCode();
|
2017-05-30 08:45:27 +02:00
|
|
|
return hashCode;
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public boolean equals(Object other) {
|
|
|
|
if (!(other instanceof JingleSession)) {
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
JingleSession otherJingleSession = (JingleSession) other;
|
2017-06-18 16:47:49 +02:00
|
|
|
return getInitiator().equals(otherJingleSession.getInitiator())
|
|
|
|
&& getResponder().equals(otherJingleSession.getResponder())
|
|
|
|
&& sid.equals(otherJingleSession.sid);
|
2017-05-30 08:45:27 +02:00
|
|
|
}
|
|
|
|
}
|