/** * 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. */ public void changeAvailabilityStatus(String status, Presence.Mode mode) { if (nickname == null || nickname.equals("")) { throw new IllegalArgumentException("Nickname must not be null or blank."); } // Check that we already have joined the room before attempting to change the // availability status. if (!joined) { throw new IllegalStateException( "Must be logged into the room to change the " + "availability status."); } // 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(room + "/" + nickname); // Invoke presence interceptors so that extra information can be dynamically added for (PacketInterceptor packetInterceptor : presenceInterceptors) { packetInterceptor.interceptPacket(joinPresence); } // Send join packet. connection.sendPacket(joinPresence); }
/** * 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. */ public void changeAvailabilityStatus(String status, Presence.Mode mode) { if (nickname == null || nickname.equals("")) { throw new IllegalArgumentException( "Nickname must not be null or blank."); } // Check that we already have joined the room before attempting to // change the // availability status. if (!joined) { throw new IllegalStateException( "Must be logged into the room to change the " + "availability status."); } // 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(room + "/" + nickname); // Invoke presence interceptors so that extra information can be // dynamically added for (PacketInterceptor packetInterceptor : presenceInterceptors) { packetInterceptor.interceptPacket(joinPresence); } // Send join packet. connection.sendPacket(joinPresence); }
@Before public void setUp() throws Exception { connection = createMock(MyXMPPConnection.class); connectionListenerCapture = new Capture<ConnectionListener>(); interceptorCapture = new Capture<PacketInterceptor>(); listenerCapture = new Capture<PacketListener>(); packetCapture = new Capture<Packet>(CaptureType.ALL); connection.addConnectionListener(capture(connectionListenerCapture)); expectLastCall().anyTimes(); connection.addPacketListener(capture(listenerCapture), anyObject(PacketFilter.class)); expectLastCall().anyTimes(); connection.addPacketInterceptor(capture(interceptorCapture), anyObject(PacketFilter.class)); expectLastCall().anyTimes(); connection.sendPacket(capture(packetCapture)); expectLastCall().anyTimes(); Roster roster = createNiceMock(Roster.class); expect(connection.getRoster()).andStubReturn(roster); replay(connection, roster); handler = new XmppStreamHandler(connection); // Set max queue size to 10 and acks at 10/2 = 5 handler.setMaxOutgoingQueueSize(10); listener = listenerCapture.getValue(); interceptor = interceptorCapture.getValue(); }
/** * Initialize VCardManager. */ public VCardManager() { // Initialize parser parser = new MXParser(); try { parser.setFeature(XmlPullParser.FEATURE_PROCESS_NAMESPACES, true); } catch (XmlPullParserException e) { Log.error(e); } imageFile = new File(SparkManager.getUserDirectory(), "personal.png"); // Initialize vCard. personalVCard = new VCard(); // Set VCard Storage vcardStorageDirectory = new File(SparkManager.getUserDirectory(), "vcards"); vcardStorageDirectory.mkdirs(); // Set the current user directory. contactsDir = new File(SparkManager.getUserDirectory(), "contacts"); contactsDir.mkdirs(); initializeUI(); // Intercept all presence packets being sent and append vcard information. PacketFilter presenceFilter = new PacketTypeFilter(Presence.class); SparkManager.getConnection().addPacketInterceptor(new PacketInterceptor() { public void interceptPacket(Packet packet) { Presence newPresence = (Presence)packet; VCardUpdateExtension update = new VCardUpdateExtension(); JabberAvatarExtension jax = new JabberAvatarExtension(); PacketExtension updateExt = newPresence.getExtension(update.getElementName(), update.getNamespace()); PacketExtension jabberExt = newPresence.getExtension(jax.getElementName(), jax.getNamespace()); if (updateExt != null) { newPresence.removeExtension(updateExt); } if (jabberExt != null) { newPresence.removeExtension(jabberExt); } if (personalVCard != null) { byte[] bytes = personalVCard.getAvatar(); if (bytes != null && bytes.length > 0) { update.setPhotoHash(personalVCard.getAvatarHash()); jax.setPhotoHash(personalVCard.getAvatarHash()); newPresence.addExtension(update); newPresence.addExtension(jax); } } } }, presenceFilter); editor = new VCardEditor(); // Start Listener startQueueListener(); }
/** * Adds a new {@link PacketInterceptor} that will be invoked every time a new presence * is going to be sent by this MultiUserChat to the server. Packet interceptors may * add new extensions to the presence that is going to be sent to the MUC service. * * @param presenceInterceptor the new packet interceptor that will intercept presence packets. */ public void addPresenceInterceptor(PacketInterceptor presenceInterceptor) { presenceInterceptors.add(presenceInterceptor); }
/** * Removes a {@link PacketInterceptor} that was being invoked every time a new presence * was being sent by this MultiUserChat to the server. Packet interceptors may * add new extensions to the presence that is going to be sent to the MUC service. * * @param presenceInterceptor the packet interceptor to remove. */ public void removePresenceInterceptor(PacketInterceptor presenceInterceptor) { presenceInterceptors.remove(presenceInterceptor); }
/** * Adds a new {@link PacketInterceptor} that will be invoked every time a * new presence is going to be sent by this MultiUserChat to the server. * Packet interceptors may add new extensions to the presence that is going * to be sent to the MUC service. * * @param presenceInterceptor * the new packet interceptor that will intercept presence * packets. */ public void addPresenceInterceptor(PacketInterceptor presenceInterceptor) { presenceInterceptors.add(presenceInterceptor); }
/** * Removes a {@link PacketInterceptor} that was being invoked every time a * new presence was being sent by this MultiUserChat to the server. Packet * interceptors may add new extensions to the presence that is going to be * sent to the MUC service. * * @param presenceInterceptor * the packet interceptor to remove. */ public void removePresenceInterceptor(PacketInterceptor presenceInterceptor) { presenceInterceptors.remove(presenceInterceptor); }