Presence presence = new Presence(type); presence.setTo(ParserUtils.getJidAttribute(parser, "to")); presence.setFrom(ParserUtils.getJidAttribute(parser, "from")); presence.setStanzaId(parser.getAttributeValue("", "id")); presence.setLanguage(language); switch (elementName) { case "status": presence.setStatus(parser.nextText()); break; case "priority": int priority = Integer.parseInt(parser.nextText()); presence.setPriority(priority); break; case "show": String modeText = parser.nextText(); if (StringUtils.isNotEmpty(modeText)) { presence.setMode(Presence.Mode.fromString(modeText)); } else { + presence.getFrom() + " with id '" + presence.getStanzaId() + "' which is invalid according to RFC6121 4.7.2.1"); presence.setError(parseError(parser)); break; default:
Roster roster = xmppConnection.getRoster(); Collection<RosterEntry> entries = roster.getEntries(); Presence presence; for(RosterEntry entry : entries) { presence = roster.getPresence(entry.getUser()); System.out.println(entry.getUser()); System.out.println(presence.getType().name()); System.out.println(presence.getStatus()); }
Map<Resourcepart, Presence> userPresences = getPresencesInternal(jid); if (userPresences == null) { Presence presence = new Presence(Presence.Type.unavailable); presence.setFrom(jid); return presence; if (!p.isAvailable()) { unavailable = p; continue; if (presence == null || p.getPriority() > presence.getPriority()) { presence = p; else if (p.getPriority() == presence.getPriority()) { Presence.Mode pMode = p.getMode(); Presence.Mode presenceMode = presence.getMode(); return unavailable.clone(); presence = new Presence(Presence.Type.unavailable); presence.setFrom(jid); return presence; return presence.clone();
/** * Creates a new presence update with a specified status, priority, and mode. * * @param type the type. * @param status a text message describing the presence update. * @param priority the priority of this presence update. * @param mode the mode type for this presence update. */ public Presence(Type type, String status, int priority, Mode mode) { // Ensure that the stanza ID is set by calling super(). super(); setType(type); setStatus(status); setPriority(priority); setMode(mode); }
public void sendSubscriptionRequest(BareJid jid) throws NotLoggedInException, NotConnectedException, InterruptedException { final XMPPConnection connection = getAuthenticatedConnectionOrThrow(); // Create a presence subscription packet and send. Presence presencePacket = new Presence(Presence.Type.subscribe); presencePacket.setTo(jid); connection.sendStanza(presencePacket); }
MucEnterConfiguration(Builder builder) { nickname = builder.nickname; password = builder.password; maxChars = builder.maxChars; maxStanzas = builder.maxStanzas; seconds = builder.seconds; since = builder.since; timeout = builder.timeout; if (builder.joinPresence == null) { joinPresence = new Presence(Presence.Type.available); } else { joinPresence = builder.joinPresence.clone(); } // Indicate the the client supports MUC joinPresence.addExtension(new MUCInitialPresence(password, maxChars, maxStanzas, seconds, since)); }
for (ChatRoom room : SparkManager.getChatManager().getChatContainer().getChatRooms()) { if (room instanceof GroupChatRoom) { int priority = presence.getPriority(); final Presence p = new Presence(presence.getType(), presence.getStatus(), priority, presence.getMode()); p.setTo(jid); try SparkManager.getConnection().sendStanza(p); Log.warning( "Unable to send stanza to " + p.getTo(), e );
connection.connect(); return true; } catch (XMPPException e) { e.printStackTrace(); connection.disconnect(); connection.disconnect(); Presence presence = new Presence(precenseType); presence.setStatus(status); connection.sendPacket(presence);
Presence presence = new Presence(Presence.Type.available); presence.setMode(presenceMode); presence.setTo(this.getWorkgroupJID()); presence.setStatus(status); presence.addExtension(new MetaData(this.metaData)); StanzaCollector collector = this.connection.createStanzaCollectorAndSend(new AndFilter(new StanzaTypeFilter(Presence.class), FromMatchesFilter.create(workgroupJID)), presence);
public void processPacket(Packet packet) { if(packet instanceof Presence){ Presence presence = (Presence)packet; if(entityJID.equals(presence.getFrom()) && roster.contains(presence.getFrom()) && presence.getType().equals(Presence.Type.subscribe)){ Presence response = new Presence(Presence.Type.subscribed); response.setTo(presence.getFrom()); response.setFrom(StringUtils.parseBareAddress(connection.getUser())); connection.sendPacket(response); } } } }
public static Presence copy(Presence presence) { if (presence == null) return null; Presence copy = new Presence(presence.getType()); copy.setMode(presence.getMode()); copy.setStatus(presence.getStatus()); copy.setPriority(presence.getPriority()); return copy; } }
/** * Changes the occupant's availability status within the room. The presence type * will remain available but with a new status that describes the presence update and * a new presence mode (e.g. Extended away). * * @param status a text message describing the presence update. * @param mode the mode type for the presence update. * @throws NotConnectedException * @throws InterruptedException * @throws MucNotJoinedException */ public void changeAvailabilityStatus(String status, Presence.Mode mode) throws NotConnectedException, InterruptedException, MucNotJoinedException { final EntityFullJid myRoomJid = this.myRoomJid; if (myRoomJid == null) { throw new MucNotJoinedException(this); } // Check that we already have joined the room before attempting to change the // availability status. if (!joined) { throw new MucNotJoinedException(this); } // We change the availability status by sending a presence packet to the room with the // new presence status and mode Presence joinPresence = new Presence(Presence.Type.available); joinPresence.setStatus(status); joinPresence.setMode(mode); joinPresence.setTo(myRoomJid); // Send join packet. connection.sendStanza(joinPresence); }
InterruptedException, NotLoggedInException { Presence presence = (Presence) stanza; Jid from = presence.getFrom(); SubscribeAnswer subscribeAnswer = null; switch (subscriptionMode) { response = new Presence(Presence.Type.subscribed); break; case Deny: response = new Presence(Presence.Type.unsubscribed); break; default: response.setTo(presence.getFrom()); connection.sendStanza(response);
presence = new Presence(Presence.Type.available); presence.setTo(workgroupJID); presence.addExtension(new StandardExtensionElement(AgentStatus.ELEMENT_NAME, AgentStatus.NAMESPACE)); StanzaCollector collector = this.connection.createStanzaCollectorAndSend(new AndFilter( new StanzaTypeFilter(Presence.class), FromMatchesFilter.create(workgroupJID)), presence); presence = new Presence(Presence.Type.unavailable); presence.setTo(workgroupJID); presence.addExtension(new StandardExtensionElement(AgentStatus.ELEMENT_NAME, AgentStatus.NAMESPACE)); connection.sendStanza(presence);
/** * Returns true if the workgroup is available for receiving new requests. The workgroup will be * available only when agents are available for this workgroup. * * @return true if the workgroup is available for receiving new requests. * @throws XMPPErrorException * @throws NoResponseException * @throws NotConnectedException * @throws InterruptedException */ public boolean isAvailable() throws NoResponseException, XMPPErrorException, NotConnectedException, InterruptedException { Presence directedPresence = new Presence(Presence.Type.available); directedPresence.setTo(workgroupJID); StanzaFilter typeFilter = new StanzaTypeFilter(Presence.class); StanzaFilter fromFilter = FromMatchesFilter.create(workgroupJID); StanzaCollector collector = connection.createStanzaCollectorAndSend(new AndFilter(fromFilter, typeFilter), directedPresence); Presence response = collector.nextResultOrThrow(); return Presence.Type.available == response.getType(); }
Occupant(Presence presence) { super(); MUCUser mucUser = (MUCUser) presence.getExtension("x", "http://jabber.org/protocol/muc#user"); MUCUser.Item item = mucUser.getItem(); this.jid = item.getJid(); this.affiliation = item.getAffiliation(); this.role = item.getRole(); // Get the nickname from the FROM attribute of the presence this.nick = StringUtils.parseResource(presence.getFrom()); }
XMPPConnection.addConnectionCreationListener(new ConnectionCreationListener() { @Override public void connectionCreated(Connection arg0) { Log.i(TAG, "receive xmpp connection : " + arg0); connection = arg0; roster = arg0.getRoster(); Collection<RosterEntry> entries = roster.getEntries(); Presence presence; Log.e(TAG, "user count" + entries.size()); for (RosterEntry entry : entries) { presence = roster.getPresence(entry.getUser()); Log.i(TAG, "" + entry.getUser()); Log.i(TAG, "" + presence.getType().name()); Log.i(TAG, "" + presence.getStatus()); } } });
public static Presence copyPresence(Presence presence) { return new Presence(presence.getType(), presence.getStatus(), presence.getPriority(), presence.getMode()); }
@Test public void setPresenceTypeTest() throws IOException, SAXException { Presence.Type type = Presence.Type.unavailable; Presence.Type type2 = Presence.Type.subscribe; StringBuilder controlBuilder = new StringBuilder(); controlBuilder.append("<presence") .append(" type=\"") .append(type) .append("\">") .append("</presence>"); String control = controlBuilder.toString(); Presence presenceTypeInConstructor = new Presence(type); presenceTypeInConstructor.setStanzaId(null); assertEquals(type, presenceTypeInConstructor.getType()); assertXMLEqual(control, presenceTypeInConstructor.toXML(StreamOpen.CLIENT_NAMESPACE).toString()); controlBuilder = new StringBuilder(); controlBuilder.append("<presence") .append(" type=\"") .append(type2) .append("\">") .append("</presence>"); control = controlBuilder.toString(); Presence presenceTypeSet = getNewPresence(); presenceTypeSet.setType(type2); assertEquals(type2, presenceTypeSet.getType()); assertXMLEqual(control, presenceTypeSet.toXML(StreamOpen.CLIENT_NAMESPACE).toString()); }
@Override public void processStanza(Stanza packet) { Presence presence = (Presence) packet; EntityFullJid from = presence.getFrom().asEntityFullJidIfPossible(); if (from == null) { LOGGER.warning("Presence with non full JID from: " + presence.toXML(null)); return; if (presence.getType() == Presence.Type.available) { AgentStatus agentStatus = presence.getExtension( AgentStatus.ELEMENT_NAME, AgentStatus.NAMESPACE); if (agentStatus == null) { else if (presence.getType() == Presence.Type.unavailable) { if (presenceMap.get(key) != null) { Map<Resourcepart, Presence> userPresences = presenceMap.get(key);