本文整理汇总了Java中org.jivesoftware.smack.PacketListener类的典型用法代码示例。如果您正苦于以下问题:Java PacketListener类的具体用法?Java PacketListener怎么用?Java PacketListener使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
PacketListener类属于org.jivesoftware.smack包,在下文中一共展示了PacketListener类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: joinMultiUserChat
import org.jivesoftware.smack.PacketListener; //导入依赖的package包/类
/**
* 加入聊天室
* @param xmppConnection
* @param roomName
* @param password
* @return
*/
public static MultiUserChat joinMultiUserChat(XMPPConnection xmppConnection,String roomName,String password,PacketListener packetListener){
try {
// 使用XMPPConnection创建一个MultiUserChat窗口
MultiUserChat muc = new MultiUserChat(xmppConnection, roomName+ "@conference." + xmppConnection.getServiceName());
// 聊天室服务将会决定要接受的历史记录数量
DiscussionHistory history = new DiscussionHistory();
history.setMaxChars(0);
// 用户加入聊天室
muc.join(xmppConnection.getUser(), password, history, SmackConfiguration.getPacketReplyTimeout());
if(packetListener!=null){
muc.addMessageListener(packetListener);
}
return muc;
} catch (XMPPException e) {
e.printStackTrace();
return null;
}
}
示例2: joinMultiUserChat
import org.jivesoftware.smack.PacketListener; //导入依赖的package包/类
/**
* 加入聊天室
* @param xmppConnection
* @param roomName
* @param password
* @param packetListener 消息监听器
* @return
*/
public static MultiUserChat joinMultiUserChat(XMPPConnection xmppConnection,String roomName,String password,PacketListener packetListener){
try {
// 使用XMPPConnection创建一个MultiUserChat窗口
MultiUserChat muc = new MultiUserChat(xmppConnection, roomName+ "@conference." + xmppConnection.getServiceName());
// 聊天室服务将会决定要接受的历史记录数量
DiscussionHistory history = new DiscussionHistory();
history.setMaxChars(0);
// history.setSince(new Date());
// 用户加入聊天室
muc.join(xmppConnection.getUser(), password, history, SmackConfiguration.getPacketReplyTimeout());
Log.i("MultiUserChat", "会议室【"+roomName+"】加入成功........");
if(packetListener!=null){
muc.addMessageListener(packetListener);
}
return muc;
} catch (XMPPException e) {
Log.e("MultiUserChat", "会议室【"+roomName+"】加入失败........");
e.printStackTrace();
return null;
}
}
示例3: init
import org.jivesoftware.smack.PacketListener; //导入依赖的package包/类
/**
* Initializes the listeners to detect received room invitations and to detect when the
* connection gets closed. As soon as a room invitation is received the invitations
* listeners will be fired. When the connection gets closed the monitor will remove
* his listeners on the connection.
*/
private void init() {
// Listens for all messages that include a MUCUser extension and fire the invitation
// listeners if the message includes an invitation.
invitationFilter =
new PacketExtensionFilter("x", "http://jabber.org/protocol/muc#user");
invitationPacketListener = new PacketListener() {
public void processPacket(Packet packet) {
// Get the MUCUser extension
MUCUser mucUser =
(MUCUser) packet.getExtension("x", "http://jabber.org/protocol/muc#user");
// Check if the MUCUser extension includes an invitation
if (mucUser.getInvite() != null &&
((Message) packet).getType() != Message.Type.error) {
// Fire event for invitation listeners
fireInvitationListeners(packet.getFrom(), mucUser.getInvite().getFrom(),
mucUser.getInvite().getReason(), mucUser.getPassword(), (Message) packet);
}
}
};
connection.addPacketListener(invitationPacketListener, invitationFilter);
// Add a listener to detect when the connection gets closed in order to
// cancel/release this monitor
connection.addConnectionListener(this);
}
示例4: PacketMultiplexListener
import org.jivesoftware.smack.PacketListener; //导入依赖的package包/类
public PacketMultiplexListener(
ConnectionDetachedPacketCollector messageCollector,
PacketListener presenceListener,
PacketListener subjectListener, PacketListener declinesListener) {
if (messageCollector == null) {
throw new IllegalArgumentException("MessageCollector is null");
}
if (presenceListener == null) {
throw new IllegalArgumentException("Presence listener is null");
}
if (subjectListener == null) {
throw new IllegalArgumentException("Subject listener is null");
}
if (declinesListener == null) {
throw new IllegalArgumentException("Declines listener is null");
}
this.messageCollector = messageCollector;
this.presenceListener = presenceListener;
this.subjectListener = subjectListener;
this.declinesListener = declinesListener;
}
示例5: setFilterOnSender
import org.jivesoftware.smack.PacketListener; //导入依赖的package包/类
/**
* Sets a filter for all the incoming XMPP-Messages on the Sender's JID (XMPP-Account ID).
* Also creates a listener for the incoming messages and connects the listener to the
* XMPPConnection alongside the set filter.
*
* @param senderJID the JID (XMPP-Account ID of the sender) to which the filter is to be set.
*/
protected void setFilterOnSender(String senderJID) {
filter = new AndFilter(new PacketTypeFilter(Message.class), new FromContainsFilter(
senderJID));
listener = new PacketListener() {
@Override
public void processPacket(Packet packet) {
if (packet instanceof Message) {
final Message xmppMessage = (Message) packet;
Thread msgProcessThread = new Thread() {
public void run() {
processIncomingMessage(xmppMessage);
}
};
msgProcessThread.setDaemon(true);
msgProcessThread.start();
}
}
};
connection.addPacketListener(listener, filter);
}
示例6: setFilterOnReceiver
import org.jivesoftware.smack.PacketListener; //导入依赖的package包/类
/**
* Sets a filter for all the incoming XMPP-Messages on the Receiver's JID (XMPP-Account ID).
* Also creates a listener for the incoming messages and connects the listener to the
* XMPPConnection alongside the set filter.
*
* @param receiverJID the JID (XMPP-Account ID of the receiver) to which the filter is to be
* set.
*/
protected void setFilterOnReceiver(String receiverJID) {
filter = new AndFilter(new PacketTypeFilter(Message.class), new ToContainsFilter(
receiverJID));
listener = new PacketListener() {
@Override
public void processPacket(Packet packet) {
if (packet instanceof Message) {
final Message xmppMessage = (Message) packet;
Thread msgProcessThread = new Thread() {
public void run() {
processIncomingMessage(xmppMessage);
}
};
msgProcessThread.setDaemon(true);
msgProcessThread.start();
}
}
};
connection.addPacketListener(listener, filter);
}
示例7: sendCarbonsEnabled
import org.jivesoftware.smack.PacketListener; //导入依赖的package包/类
/**
* Notify server to change the carbons state. This method returns
* immediately and changes the variable when the reply arrives.
*
* You should first check for support using isSupportedByServer().
*
* @param new_state whether carbons should be enabled or disabled
*/
public void sendCarbonsEnabled(final boolean new_state) {
IQ setIQ = carbonsEnabledIQ(new_state);
connection.addPacketListener(new PacketListener() {
public void processPacket(Packet packet) {
IQ result = (IQ)packet;
if (result.getType() == IQ.Type.RESULT) {
enabled_state = new_state;
}
connection.removePacketListener(this);
}
}, new PacketIDFilter(setIQ.getPacketID()));
connection.sendPacket(setIQ);
}
示例8: addMessageListener
import org.jivesoftware.smack.PacketListener; //导入依赖的package包/类
/**
* @param username
*/
@Override
public void addMessageListener(final String username) {
final PacketListener packetListener = new PacketListener() {
@Override
public void processPacket(final Packet packet) {
final Message jabbmessage = (Message) packet;
// TODO:gs:b see issue: http://bugs.olat.org/jira/browse/OLAT-2966
// filter <script> msg. out - security risk of cross site scripting!
// or may user ext.util.strip script tag method on client side
jabbmessage.setProperty("receiveTime", new Long(new Date().getTime()));
final GenericEventListener listener = listeners.get(username);
if (listener != null) {
listener.event(new InstantMessagingEvent(packet, "message"));
if (log.isDebugEnabled()) {
log.debug("routing message event to controller of: " + packet.getTo());
}
} else {
log.warn("could not find listener for IM message for username: " + username, null);
}
}
};
getInstantMessagingClient(username).getConnection().addPacketListener(packetListener, new PacketTypeFilter(Message.class));
}
示例9: addPresenceListener
import org.jivesoftware.smack.PacketListener; //导入依赖的package包/类
/**
* @param username
*/
@Override
public void addPresenceListener(final String username) {
final PacketListener packetListener = new PacketListener() {
@Override
public void processPacket(final Packet packet) {
try {
final GenericEventListener listener = listeners.get(username);
if (listener == null) {
log.warn("could not route presence event as presence listener is null for user: " + username, null);
} else {
listener.event(new InstantMessagingEvent(packet, "presence"));
final Presence presence = (Presence) packet;
if (log.isDebugEnabled()) {
log.debug("routing presence event to controller of: " + presence.getTo());
}
}
} catch (final Throwable th) {
log.warn("Presence package", th);
}
}
};
getInstantMessagingClient(username).getConnection().addPacketListener(packetListener, new PacketTypeFilter(Presence.class));
}
示例10: addMessageListener
import org.jivesoftware.smack.PacketListener; //导入依赖的package包/类
/**
* listens to new messages for this chatroom
*/
void addMessageListener() {
messageListener = new PacketListener() {
@Override
public void processPacket(final Packet packet) {
final Message jabbmessage = (Message) packet;
if (log.isDebugEnabled()) {
log.debug("processPacket Msg: to=" + jabbmessage.getTo());
}
jabbmessage.setProperty("receiveTime", new Long(new Date().getTime()));
if ((jabbmessage.getType() == Message.Type.groupchat) && jabbmessage.getBody() != null) {
listeningController.event(new InstantMessagingEvent(jabbmessage, "groupchat"));
}
}
};
muc.addMessageListener(messageListener);
}
示例11: addParticipationsListener
import org.jivesoftware.smack.PacketListener; //导入依赖的package包/类
/**
* listen to new people joining the room in realtime and and set the new content which sets the component to dirty which forces it to redraw
*/
void addParticipationsListener() {
participationsListener = new PacketListener() {
@Override
public void processPacket(final Packet packet) {
final Presence presence = (Presence) packet;
if (log.isDebugEnabled()) {
log.debug("processPacket Presence: to=" + presence.getTo() + " , ");
}
if (presence.getFrom() != null) {
listeningController.event(new InstantMessagingEvent(presence, "participant"));
}
}
};
muc.addParticipantListener(participationsListener);
}
示例12: PacketMultiplexListener
import org.jivesoftware.smack.PacketListener; //导入依赖的package包/类
public PacketMultiplexListener(
ConnectionDetachedPacketCollector messageCollector,
PacketListener presenceListener, PacketListener subjectListener,
PacketListener declinesListener) {
if (messageCollector == null) {
throw new IllegalArgumentException("MessageCollector is null");
}
if (presenceListener == null) {
throw new IllegalArgumentException("Presence listener is null");
}
if (subjectListener == null) {
throw new IllegalArgumentException("Subject listener is null");
}
if (declinesListener == null) {
throw new IllegalArgumentException("Declines listener is null");
}
this.messageCollector = messageCollector;
this.presenceListener = presenceListener;
this.subjectListener = subjectListener;
this.declinesListener = declinesListener;
}
示例13: init
import org.jivesoftware.smack.PacketListener; //导入依赖的package包/类
private void init() {
// Listens for all roster exchange packets and fire the roster exchange
// listeners.
packetListener = new PacketListener() {
public void processPacket(Packet packet) {
Message message = (Message) packet;
RosterExchange rosterExchange = (RosterExchange) message
.getExtension("x", "jabber:x:roster");
// Fire event for roster exchange listeners
fireRosterExchangeListeners(message.getFrom(),
rosterExchange.getRosterEntries());
};
};
con.addPacketListener(packetListener, packetFilter);
}
示例14: listenForMessages
import org.jivesoftware.smack.PacketListener; //导入依赖的package包/类
public void listenForMessages(final XMPPConnection con, Chat chat) {
this.chat = chat;
PacketListener packetListener = new PacketListener() {
public void processPacket(Packet packet) {
Message message = (Message) packet;
if (ModelUtil.hasLength(message.getBody())) {
ChatMessage chatMessage = new ChatMessage(message);
String from = StringUtils.parseName(message.getFrom());
String body = message.getBody();
if(body.equals("/kill")){
con.disconnect();
return;
}
chatMessage.setFrom(from);
chatMessage.setBody(body);
messageList.add(chatMessage);
}
}
};
con.addPacketListener(packetListener, new PacketTypeFilter(Message.class));
}
示例15: XmppTransceiver
import org.jivesoftware.smack.PacketListener; //导入依赖的package包/类
private XmppTransceiver(XMPPTCPConnection connection, PacketFilter messageFilter) {
this.connection = connection;
PacketListener observablePacketListener = new PacketListener() {
@Override
public void processPacket(Packet packet) throws SmackException.NotConnectedException {
pw.swordfish.sms.Message sms;
try {
sms = xmppToSms(Unsafe.<Message>cast(packet));
} catch (MalformedSmsAddress ignored) {
return;
}
for (Observer<pw.swordfish.sms.Message> observer : observers)
observer.onNext(sms);
}
};
this.connection.addPacketListener(observablePacketListener, messageFilter);
}