use of org.jivesoftware.smack.XMPPException in project Smack by igniterealtime.
the class JingleSession method setupListeners.
/**
* Setup the listeners that act on events coming from the lower level negotiators.
*/
public void setupListeners() {
JingleMediaListener jingleMediaListener = new JingleMediaListener() {
@Override
public void mediaClosed(PayloadType cand) {
}
@Override
public void mediaEstablished(PayloadType pt) throws NotConnectedException, InterruptedException {
if (isFullyEstablished()) {
Jingle jout = new Jingle(JingleActionEnum.SESSION_ACCEPT);
// Build up a response packet from each media manager.
for (ContentNegotiator contentNegotiator : contentNegotiators) {
if (contentNegotiator.getNegotiatorState() == JingleNegotiatorState.SUCCEEDED)
jout.addContent(contentNegotiator.getJingleContent());
}
// Send the "accept" and wait for the ACK
addExpectedId(jout.getStanzaId());
sendStanza(jout);
//triggerSessionEstablished();
}
}
};
JingleTransportListener jingleTransportListener = new JingleTransportListener() {
@Override
public void transportEstablished(TransportCandidate local, TransportCandidate remote) throws NotConnectedException, InterruptedException {
if (isFullyEstablished()) {
// CHECKSTYLE:OFF
// Indicate that this session is active.
setSessionState(JingleSessionStateActive.getInstance());
for (ContentNegotiator contentNegotiator : contentNegotiators) {
// CHECKSTYLE:ON
if (contentNegotiator.getNegotiatorState() == JingleNegotiatorState.SUCCEEDED)
contentNegotiator.triggerContentEstablished();
}
if (getSessionState().equals(JingleSessionStatePending.getInstance())) {
Jingle jout = new Jingle(JingleActionEnum.SESSION_ACCEPT);
// Build up a response packet from each media manager.
for (ContentNegotiator contentNegotiator : contentNegotiators) {
if (contentNegotiator.getNegotiatorState() == JingleNegotiatorState.SUCCEEDED)
jout.addContent(contentNegotiator.getJingleContent());
}
// Send the "accept" and wait for the ACK
addExpectedId(jout.getStanzaId());
sendStanza(jout);
}
}
}
@Override
public void transportClosed(TransportCandidate cand) {
}
@Override
public void transportClosedOnError(XMPPException e) {
}
};
addMediaListener(jingleMediaListener);
addTransportListener(jingleTransportListener);
}
use of org.jivesoftware.smack.XMPPException in project Smack by igniterealtime.
the class JingleSession method startOutgoing.
/**
* This is the starting point for intitiating a new session.
*
* @throws IllegalStateException
* @throws SmackException
* @throws InterruptedException
*/
public void startOutgoing() throws IllegalStateException, SmackException, InterruptedException {
updatePacketListener();
setSessionState(JingleSessionStatePending.getInstance());
Jingle jingle = new Jingle(JingleActionEnum.SESSION_INITIATE);
// Create a content negotiator for each media manager on the session.
for (JingleMediaManager mediaManager : getMediaManagers()) {
ContentNegotiator contentNeg = new ContentNegotiator(this, ContentNegotiator.INITIATOR, mediaManager.getName());
// Create the media negotiator for this content description.
contentNeg.setMediaNegotiator(new MediaNegotiator(this, mediaManager, mediaManager.getPayloads(), contentNeg));
JingleTransportManager transportManager = mediaManager.getTransportManager();
TransportResolver resolver = null;
try {
resolver = transportManager.getResolver(this);
} catch (XMPPException e) {
LOGGER.log(Level.WARNING, "exception", e);
}
if (resolver.getType().equals(TransportResolver.Type.rawupd)) {
contentNeg.setTransportNegotiator(new TransportNegotiator.RawUdp(this, resolver, contentNeg));
}
if (resolver.getType().equals(TransportResolver.Type.ice)) {
contentNeg.setTransportNegotiator(new TransportNegotiator.Ice(this, resolver, contentNeg));
}
addContentNegotiator(contentNeg);
}
// Give each of the content negotiators a chance to return a portion of the structure to make the Jingle packet.
for (ContentNegotiator contentNegotiator : contentNegotiators) {
jingle.addContent(contentNegotiator.getJingleContent());
}
// Save the session-initiate packet ID, so that we can respond to it.
sessionInitPacketID = jingle.getStanzaId();
sendStanza(jingle);
// Now setup to track the media negotiators, so that we know when (if) to send a session-accept.
setupListeners();
// Give each of the content negotiators a chance to start
// and return a portion of the structure to make the Jingle packet.
// Don't do this anymore. The problem is that the other side might not be ready.
// Later when we receive our first jingle packet from the other side we'll fire-up the negotiators
// before processing it. (See receivePacketAndRespond() above.
// for (ContentNegotiator contentNegotiator : contentNegotiators) {
// contentNegotiator.start();
// }
}
use of org.jivesoftware.smack.XMPPException in project Openfire by igniterealtime.
the class XMPPPresenceHandler method handlePresenceMode.
/**
* Handles incoming presence stanzas that relate to presence status / mode
* changes. Ignores others.
*
* @param presence
* the stanza
*/
private void handlePresenceMode(final org.jivesoftware.smack.packet.Presence presence) {
if (!session.getBuddyManager().isActivated()) {
session.getBuddyManager().storePendingStatus(session.getTransport().convertIDToJID(presence.getFrom()), ((XMPPTransport) session.getTransport()).convertXMPPStatusToGateway(presence.getType(), presence.getMode()), presence.getStatus());
} else {
// TODO: Need to handle resources and priorities!
try {
final XMPPBuddy xmppBuddy = session.getBuddyManager().getBuddy(session.getTransport().convertIDToJID(presence.getFrom()));
Log.debug("XMPP: Presence changed detected type " + presence.getType() + " and mode " + presence.getMode() + " for " + presence.getFrom());
xmppBuddy.setPresenceAndStatus(((XMPPTransport) session.getTransport()).convertXMPPStatusToGateway(presence.getType(), presence.getMode()), presence.getStatus());
if (JiveGlobals.getBooleanProperty("plugin.gateway." + session.getTransport().getType() + ".avatars", true)) {
PacketExtension pe = presence.getExtension("x", NameSpace.VCARD_TEMP_X_UPDATE);
if (pe != null) {
DefaultPacketExtension dpe = (DefaultPacketExtension) pe;
String hash = dpe.getValue("photo");
final String from = presence.getFrom();
if (hash != null) {
Avatar curAvatar = xmppBuddy.getAvatar();
if (curAvatar == null || !curAvatar.getLegacyIdentifier().equals(hash)) {
new Thread() {
@Override
public void run() {
VCard vcard = new VCard();
try {
vcard.load(session.conn, from);
xmppBuddy.setAvatar(new Avatar(xmppBuddy.getJID(), from, vcard.getAvatar()));
} catch (XMPPException e) {
Log.debug("XMPP: Failed to load XMPP avatar: ", e);
} catch (IllegalArgumentException e) {
Log.debug("XMPP: Got null avatar, ignoring.");
}
}
}.start();
}
}
}
}
} catch (NotFoundException e) {
Log.debug("XMPP: Received presence notification for contact that's not in the buddy manager of user " + session.getJID() + ". GTalk is known to do this occasionally: " + presence.getFrom());
// We cannot add this buddy to the buddy manager, as that would result into an auto-accept of the contact sending the data.
}
}
}
use of org.jivesoftware.smack.XMPPException in project Smack by igniterealtime.
the class PrivacyTest method testDenyActiveList.
/**
* Check when a client denies the use of the active list.
*/
public void testDenyActiveList() {
try {
PrivacyListManager privacyManager = PrivacyListManager.getInstanceFor(getConnection(0));
PrivacyClient client = new PrivacyClient(privacyManager);
privacyManager.addListener(client);
privacyManager.declineActiveList();
Thread.sleep(500);
try {
// The list should not exist and an error will be raised
privacyManager.getActiveList();
} catch (XMPPException xmppException) {
assertEquals(404, xmppException.getXMPPError().getCode());
}
assertEquals(null, null);
} catch (Exception e) {
e.printStackTrace();
fail(e.getMessage());
}
}
use of org.jivesoftware.smack.XMPPException in project Smack by igniterealtime.
the class PrivacyTest method testRemoveList.
/**
* Check when a client add a new list and then remove it.
*/
public void testRemoveList() {
try {
String listName = "testRemoveList";
PrivacyListManager privacyManager = PrivacyListManager.getInstanceFor(getConnection(0));
PrivacyClient client = new PrivacyClient(privacyManager);
privacyManager.addListener(client);
// Add the list that will be set as the Default
ArrayList<PrivacyItem> items = new ArrayList<PrivacyItem>();
PrivacyItem item = new PrivacyItem(PrivacyItem.Type.jid.name(), true, 1);
item.setValue(getConnection(0).getUser());
items.add(item);
privacyManager.createPrivacyList(listName, items);
Thread.sleep(500);
// Set the Default list
privacyManager.setDefaultListName(listName);
Thread.sleep(500);
privacyManager.deletePrivacyList(listName);
Thread.sleep(500);
try {
// The list should not exist and an error will be raised
privacyManager.getPrivacyList(listName);
} catch (XMPPException xmppException) {
assertEquals(404, xmppException.getXMPPError().getCode());
}
} catch (Exception e) {
e.printStackTrace();
fail(e.getMessage());
}
}
Aggregations