本文整理匯總了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);
}