本文整理汇总了Java中org.jivesoftware.smack.PacketInterceptor类的典型用法代码示例。如果您正苦于以下问题:Java PacketInterceptor类的具体用法?Java PacketInterceptor怎么用?Java PacketInterceptor使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
PacketInterceptor类属于org.jivesoftware.smack包,在下文中一共展示了PacketInterceptor类的14个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的Java代码示例。
示例1: leave
import org.jivesoftware.smack.PacketInterceptor; //导入依赖的package包/类
/**
* Leave the chat room.
*/
public synchronized void leave() {
// If not joined already, do nothing.
if (!joined) {
return;
}
// We leave a room by sending a presence packet where the "to"
// field is in the form "[email protected]/nickname"
Presence leavePresence = new Presence(Presence.Type.unavailable);
leavePresence.setTo(room + "/" + nickname);
// Invoke presence interceptors so that extra information can be dynamically added
for (PacketInterceptor packetInterceptor : presenceInterceptors) {
packetInterceptor.interceptPacket(leavePresence);
}
connection.sendPacket(leavePresence);
// Reset occupant information.
occupantsMap.clear();
nickname = null;
joined = false;
userHasLeft();
}
开发者ID:ice-coffee,项目名称:EIM,代码行数:24,代码来源:MultiUserChat.java
示例2: changeAvailabilityStatus
import org.jivesoftware.smack.PacketInterceptor; //导入依赖的package包/类
/**
* 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);
}
开发者ID:ice-coffee,项目名称:EIM,代码行数:33,代码来源:MultiUserChat.java
示例3: leave
import org.jivesoftware.smack.PacketInterceptor; //导入依赖的package包/类
/**
* Leave the chat room.
*/
public synchronized void leave() {
// If not joined already, do nothing.
if (!joined) {
return;
}
// We leave a room by sending a presence packet where the "to"
// field is in the form "[email protected]/nickname"
Presence leavePresence = new Presence(Presence.Type.unavailable);
leavePresence.setTo(room + "/" + nickname);
// Invoke presence interceptors so that extra information can be
// dynamically added
for (PacketInterceptor packetInterceptor : presenceInterceptors) {
packetInterceptor.interceptPacket(leavePresence);
}
connection.sendPacket(leavePresence);
// Reset occupant information.
occupantsMap.clear();
nickname = null;
joined = false;
userHasLeft();
}
开发者ID:ikantech,项目名称:xmppsupport_v2,代码行数:25,代码来源:MultiUserChat.java
示例4: changeAvailabilityStatus
import org.jivesoftware.smack.PacketInterceptor; //导入依赖的package包/类
/**
* 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);
}
开发者ID:ikantech,项目名称:xmppsupport_v2,代码行数:40,代码来源:MultiUserChat.java
示例5: setUp
import org.jivesoftware.smack.PacketInterceptor; //导入依赖的package包/类
@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();
}
开发者ID:prive,项目名称:prive-android,代码行数:28,代码来源:XmppStreamHandlerTest.java
示例6: create
import org.jivesoftware.smack.PacketInterceptor; //导入依赖的package包/类
/**
* Creates the room according to some default configuration, assign the requesting user
* as the room owner, and add the owner to the room but not allow anyone else to enter
* the room (effectively "locking" the room). The requesting user will join the room
* under the specified nickname as soon as the room has been created.<p>
*
* To create an "Instant Room", that means a room with some default configuration that is
* available for immediate access, the room's owner should send an empty form after creating
* the room. {@link #sendConfigurationForm(Form)}<p>
*
* To create a "Reserved Room", that means a room manually configured by the room creator
* before anyone is allowed to enter, the room's owner should complete and send a form after
* creating the room. Once the completed configutation form is sent to the server, the server
* will unlock the room. {@link #sendConfigurationForm(Form)}
*
* @param nickname the nickname to use.
* @throws XMPPException if the room couldn't be created for some reason
* (e.g. room already exists; user already joined to an existant room or
* 405 error if the user is not allowed to create the room)
*/
public synchronized void create(String nickname) throws XMPPException {
if (nickname == null || nickname.equals("")) {
throw new IllegalArgumentException("Nickname must not be null or blank.");
}
// If we've already joined the room, leave it before joining under a new
// nickname.
if (joined) {
throw new IllegalStateException("Creation failed - User already joined the room.");
}
// We create a room by sending a presence packet to [email protected]e/nick
// and signal support for MUC. The owner will be automatically logged into the room.
Presence joinPresence = new Presence(Presence.Type.available);
joinPresence.setTo(room + "/" + nickname);
// Indicate the the client supports MUC
joinPresence.addExtension(new MUCInitialPresence());
// Invoke presence interceptors so that extra information can be dynamically added
for (PacketInterceptor packetInterceptor : presenceInterceptors) {
packetInterceptor.interceptPacket(joinPresence);
}
// Wait for a presence packet back from the server.
PacketFilter responseFilter =
new AndFilter(
new FromMatchesFilter(room + "/" + nickname),
new PacketTypeFilter(Presence.class));
PacketCollector response = connection.createPacketCollector(responseFilter);
// Send create & join packet.
connection.sendPacket(joinPresence);
// Wait up to a certain number of seconds for a reply.
Presence presence =
(Presence) response.nextResult(SmackConfiguration.getPacketReplyTimeout());
// Stop queuing results
response.cancel();
if (presence == null) {
throw new XMPPException("No response from server.");
}
else if (presence.getError() != null) {
throw new XMPPException(presence.getError());
}
// Whether the room existed before or was created, the user has joined the room
this.nickname = nickname;
joined = true;
userHasJoined();
// Look for confirmation of room creation from the server
MUCUser mucUser = getMUCUserExtension(presence);
if (mucUser != null && mucUser.getStatus() != null) {
if ("201".equals(mucUser.getStatus().getCode())) {
// Room was created and the user has joined the room
return;
}
}
// We need to leave the room since it seems that the room already existed
leave();
throw new XMPPException("Creation failed - Missing acknowledge of room creation.");
}
开发者ID:ice-coffee,项目名称:EIM,代码行数:78,代码来源:MultiUserChat.java
示例7: changeNickname
import org.jivesoftware.smack.PacketInterceptor; //导入依赖的package包/类
/**
* Changes the occupant's nickname to a new nickname within the room. Each room occupant
* will receive two presence packets. One of type "unavailable" for the old nickname and one
* indicating availability for the new nickname. The unavailable presence will contain the new
* nickname and an appropriate status code (namely 303) as extended presence information. The
* status code 303 indicates that the occupant is changing his/her nickname.
*
* @param nickname the new nickname within the room.
* @throws XMPPException if the new nickname is already in use by another occupant.
*/
public void changeNickname(String nickname) throws XMPPException {
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
// nickname.
if (!joined) {
throw new IllegalStateException("Must be logged into the room to change nickname.");
}
// We change the nickname by sending a presence packet where the "to"
// field is in the form "[email protected]/nickname"
// We don't have to signal the MUC support again
Presence joinPresence = new Presence(Presence.Type.available);
joinPresence.setTo(room + "/" + nickname);
// Invoke presence interceptors so that extra information can be dynamically added
for (PacketInterceptor packetInterceptor : presenceInterceptors) {
packetInterceptor.interceptPacket(joinPresence);
}
// Wait for a presence packet back from the server.
PacketFilter responseFilter =
new AndFilter(
new FromMatchesFilter(room + "/" + nickname),
new PacketTypeFilter(Presence.class));
PacketCollector response = connection.createPacketCollector(responseFilter);
// Send join packet.
connection.sendPacket(joinPresence);
// Wait up to a certain number of seconds for a reply.
Presence presence =
(Presence) response.nextResult(SmackConfiguration.getPacketReplyTimeout());
// Stop queuing results
response.cancel();
if (presence == null) {
throw new XMPPException("No response from server.");
}
else if (presence.getError() != null) {
throw new XMPPException(presence.getError());
}
this.nickname = nickname;
}
开发者ID:ice-coffee,项目名称:EIM,代码行数:52,代码来源:MultiUserChat.java
示例8: create
import org.jivesoftware.smack.PacketInterceptor; //导入依赖的package包/类
/**
* Creates the room according to some default configuration, assign the requesting user
* as the room owner, and add the owner to the room but not allow anyone else to enter
* the room (effectively "locking" the room). The requesting user will join the room
* under the specified nickname as soon as the room has been created.<p>
*
* To create an "Instant Room", that means a room with some default configuration that is
* available for immediate access, the room's owner should send an empty form after creating
* the room. {@link #sendConfigurationForm(Form)}<p>
*
* To create a "Reserved Room", that means a room manually configured by the room creator
* before anyone is allowed to enter, the room's owner should complete and send a form after
* creating the room. Once the completed configutation form is sent to the server, the server
* will unlock the room. {@link #sendConfigurationForm(Form)}
*
* @param nickname the nickname to use.
* @throws XMPPException if the room couldn't be created for some reason
* (e.g. room already exists; user already joined to an existant room or
* 405 error if the user is not allowed to create the room)
*/
public synchronized void create(String nickname) throws XMPPException {
if (nickname == null || nickname.equals("")) {
throw new IllegalArgumentException("Nickname must not be null or blank.");
}
// If we've already joined the room, leave it before joining under a new
// nickname.
if (joined) {
throw new IllegalStateException("Creation failed - User already joined the room.");
}
// We create a room by sending a presence packet to [email protected]/nick
// and signal support for MUC. The owner will be automatically logged into the room.
Presence joinPresence = new Presence(Presence.Type.available);
joinPresence.setTo(room + "/" + nickname);
// Indicate the the client supports MUC
joinPresence.addExtension(new MUCInitialPresence());
// Invoke presence interceptors so that extra information can be dynamically added
for (PacketInterceptor packetInterceptor : presenceInterceptors) {
packetInterceptor.interceptPacket(joinPresence);
}
// Wait for a presence packet back from the server.
PacketFilter responseFilter =
new AndFilter(
new FromMatchesFilter(room + "/" + nickname),
new PacketTypeFilter(Presence.class));
PacketCollector response = connection.createPacketCollector(responseFilter);
// Send create & join packet.
connection.sendPacket(joinPresence);
// Wait up to a certain number of seconds for a reply.
Presence presence =
(Presence) response.nextResult(SmackConfiguration.getPacketReplyTimeout());
// Stop queuing results
response.cancel();
if (presence == null) {
throw new XMPPException("No response from server.");
}
else if (presence.getError() != null) {
throw new XMPPException(presence.getError());
}
// Whether the room existed before or was created, the user has joined the room
this.nickname = nickname;
joined = true;
userHasJoined();
// Look for confirmation of room creation from the server
MUCUser mucUser = getMUCUserExtension(presence);
if (mucUser != null && mucUser.getStatus() != null) {
if ("201".equals(mucUser.getStatus().getCode())) {
// Room was created and the user has joined the room
return;
}
}
// We need to leave the room since it seems that the room already existed
leave();
throw new XMPPException("Creation failed - Missing acknowledge of room creation.");
}
开发者ID:CJC-ivotten,项目名称:androidPN-client.,代码行数:78,代码来源:MultiUserChat.java
示例9: changeNickname
import org.jivesoftware.smack.PacketInterceptor; //导入依赖的package包/类
/**
* Changes the occupant's nickname to a new nickname within the room. Each
* room occupant will receive two presence packets. One of type
* "unavailable" for the old nickname and one indicating availability for
* the new nickname. The unavailable presence will contain the new nickname
* and an appropriate status code (namely 303) as extended presence
* information. The status code 303 indicates that the occupant is changing
* his/her nickname.
*
* @param nickname
* the new nickname within the room.
* @throws XMPPException
* if the new nickname is already in use by another occupant.
*/
public void changeNickname(String nickname) throws XMPPException {
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
// nickname.
if (!joined) {
throw new IllegalStateException(
"Must be logged into the room to change nickname.");
}
// We change the nickname by sending a presence packet where the "to"
// field is in the form "[email protected]/nickname"
// We don't have to signal the MUC support again
Presence joinPresence = new Presence(Presence.Type.available);
joinPresence.setTo(room + "/" + nickname);
// Invoke presence interceptors so that extra information can be
// dynamically added
for (PacketInterceptor packetInterceptor : presenceInterceptors) {
packetInterceptor.interceptPacket(joinPresence);
}
// Wait for a presence packet back from the server.
PacketFilter responseFilter = new AndFilter(new FromMatchesFilter(room
+ "/" + nickname), new PacketTypeFilter(Presence.class));
PacketCollector response = connection
.createPacketCollector(responseFilter);
// Send join packet.
connection.sendPacket(joinPresence);
// Wait up to a certain number of seconds for a reply.
Presence presence = (Presence) response.nextResult(SmackConfiguration
.getPacketReplyTimeout());
// Stop queuing results
response.cancel();
if (presence == null) {
throw new XMPPException("No response from server.");
} else if (presence.getError() != null) {
throw new XMPPException(presence.getError());
}
this.nickname = nickname;
}
开发者ID:ikantech,项目名称:xmppsupport_v2,代码行数:58,代码来源:MultiUserChat.java
示例10: VCardManager
import org.jivesoftware.smack.PacketInterceptor; //导入依赖的package包/类
/**
* 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();
}
开发者ID:visit,项目名称:spark-svn-mirror,代码行数:67,代码来源:VCardManager.java
示例11: addPresenceInterceptor
import org.jivesoftware.smack.PacketInterceptor; //导入依赖的package包/类
/**
* 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);
}
开发者ID:ice-coffee,项目名称:EIM,代码行数:11,代码来源:MultiUserChat.java
示例12: removePresenceInterceptor
import org.jivesoftware.smack.PacketInterceptor; //导入依赖的package包/类
/**
* 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);
}
开发者ID:ice-coffee,项目名称:EIM,代码行数:11,代码来源:MultiUserChat.java
示例13: addPresenceInterceptor
import org.jivesoftware.smack.PacketInterceptor; //导入依赖的package包/类
/**
* 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);
}
开发者ID:ikantech,项目名称:xmppsupport_v2,代码行数:14,代码来源:MultiUserChat.java
示例14: removePresenceInterceptor
import org.jivesoftware.smack.PacketInterceptor; //导入依赖的package包/类
/**
* 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);
}
开发者ID:ikantech,项目名称:xmppsupport_v2,代码行数:13,代码来源:MultiUserChat.java
注:本文中的org.jivesoftware.smack.PacketInterceptor类示例整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。 |
请发表评论