Java 类org.jivesoftware.smack.PacketListener 实例源码

项目:SmackStudy    文件:XMPPUtil.java   
/**
 * 加入聊天室
 * @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;
    }
}
项目:SmackStudy    文件:XMPPUtil.java   
/**
 * 加入聊天室
 * @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;
    }
}
项目:EIM    文件:MultiUserChat.java   
/**
 * 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);
}
项目:EIM    文件:PacketMultiplexListener.java   
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;
}
项目:iot-server-appliances    文件:XMPPCommunicationHandler.java   
/**
 * 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);
}
项目:iot-server-appliances    文件:XMPPCommunicationHandler.java   
/**
 * 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);
}
项目:androidPN-client.    文件:MultiUserChat.java   
/**
 * 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);
}
项目:androidPN-client.    文件:PacketMultiplexListener.java   
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;
}
项目:androidPN-client.    文件:CarbonManager.java   
/**
 * 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);
}
项目:iot-server-agents    文件:XMPPTransportHandler.java   
/**
 * 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);
}
项目:iot-server-agents    文件:XMPPTransportHandler.java   
/**
 * 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);
}
项目:iot-server-agents    文件:XMPPCommunicationHandler.java   
/**
 * 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);
}
项目:iot-server-agents    文件:XMPPCommunicationHandler.java   
/**
 * 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);
}
项目:olat    文件:ClientManagerImpl.java   
/**
 * @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));
}
项目:olat    文件:ClientManagerImpl.java   
/**
 * @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));
}
项目:olat    文件:GroupChatJoinTask.java   
/**
 * 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);
}
项目:olat    文件:GroupChatJoinTask.java   
/**
 * 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);

}
项目:olat    文件:ClientManagerImpl.java   
/**
 * @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));
}
项目:olat    文件:ClientManagerImpl.java   
/**
 * @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));
}
项目:olat    文件:GroupChatJoinTask.java   
/**
 * 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);
}
项目:olat    文件:GroupChatJoinTask.java   
/**
 * 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);

}
项目:xmppsupport_v2    文件:PacketMultiplexListener.java   
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;
}
项目:xmppsupport_v2    文件:RosterExchangeManager.java   
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);
}
项目:Fastpath-webchat    文件:ChatPoller.java   
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));
}
项目:SmackPlus    文件:XmppTransceiver.java   
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);
}
项目:java-bells    文件:MultiUserChat.java   
/**
 * 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);
}
项目:java-bells    文件:PacketMultiplexListener.java   
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;
}
项目:telegraph    文件:MultiUserChat.java   
/**
 * 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);
}
项目:telegraph    文件:PacketMultiplexListener.java   
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;
}
项目:NewCommunication-Android    文件:MultiUserChat.java   
/**
 * 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);
}
项目:NewCommunication-Android    文件:PacketMultiplexListener.java   
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;
}
项目:spark-svn-mirror    文件:ChatContainer.java   
/**
 * Removes the ChatRoom resources.
 *
 * @param room the room to remove.
 */
private void cleanupChatRoom(ChatRoom room) {
    if (room.isActive()) {
        room.leaveChatRoom();
        room.closeChatRoom();
    }

    final PacketListener listener = presenceMap.get(room.getRoomname());
    if (listener != null) {
        SparkManager.getConnection().removePacketListener(listener);
    }

    fireChatRoomClosed(room);
    room.removeMessageListener(this);

    // Remove mappings
    presenceMap.remove(room.getRoomname());

    chatRoomList.remove(room);

    room.getChatInputEditor().removeKeyListener(this);

    // Clear all Text :)
    room.getTranscriptWindow().cleanup();
}
项目:spark-svn-mirror    文件:JinglePlugin.java   
/**
 * Adds a presence listener to remove offline users from discovered features.
 */
private void addPresenceListener() {
    // Check presence changes
    SparkManager.getConnection().addPacketListener(new PacketListener() {
        public void processPacket(Packet packet) {
            Presence presence = (Presence)packet;
            if (!presence.isAvailable()) {
                String from = presence.getFrom();
                if (ModelUtil.hasLength(from)) {
                    // Remove from
                    jingleFeature.remove(from);
                }
            }


        }
    }, new PacketTypeFilter(Presence.class));
}
项目:communote-server    文件:XMPPPacketListenerTest.java   
/**
 * This method sends a message without an alias, the listener should send an error message back
 * to the sender.
 *
 * @param listener
 *            The listener.
 * @param connection
 *            The connection.
 * @throws NotConnectedException
 */
private void processMessageWithoutAlias(PacketListener listener, XMPPConnection connection)
        throws NotConnectedException {
    Message message = new Message();
    String sender = user.getAlias() + ".global" + USER_SUFFIX;
    message.setFrom(sender);
    message.setThread(blog.getNameIdentifier() + ".global" + BLOG_SUFFIX);
    message.setBody("Empty");
    listener.processPacket(message);
    Packet packet = connection.getLastPacket();
    Assert.assertEquals(packet.getTo(), sender);
    Assert.assertTrue(((Message) packet).getBody().contains("To post to a topic"));
}
项目:communote-server    文件:XMPPPacketListenerTest.java   
/**
 * Test for
 * {@link XMPPMessagePacketListener#processPacket(org.jivesoftware.smack.packet.Packet)}.
 * 
 * @throws NotConnectedException
 */
@Test
public void testProcessPacket() throws NotConnectedException {
    XMPPConnection connection = new XMPPConnection();
    PacketListener listener = new XMPPMessagePacketListener(connection, new MockNoteService());
    processNonMessagePacket(listener, connection);
    processMessageWithoutAlias(listener, connection);
}
项目:Smack    文件:EntityCapsTest.java   
/**
 * Test if entity caps actually prevent a disco info request and reply
 * 
 * @throws XMPPException
 * 
 */
public void testPreventDiscoInfo() throws XMPPException {
    con0.addPacketSendingListener(new PacketListener() {

        @Override
        public void processPacket(Packet packet) {
            discoInfoSend = true;
        }

    }, new AndFilter(new StanzaTypeFilter(DiscoverInfo.class), new IQTypeFilter(IQ.Type.get)));

    // add a bogus feature so that con1 ver won't match con0's
    sdm1.addFeature(DISCOVER_TEST_FEATURE);

    dropCapsCache();
    // discover that
    DiscoverInfo info = sdm0.discoverInfo(con1.getUser());
    // that discovery should cause a disco#info
    assertTrue(discoInfoSend);
    assertTrue(info.containsFeature(DISCOVER_TEST_FEATURE));
    discoInfoSend = false;

    // discover that
    info = sdm0.discoverInfo(con1.getUser());
    // that discovery shouldn't cause a disco#info
    assertFalse(discoInfoSend);
    assertTrue(info.containsFeature(DISCOVER_TEST_FEATURE));
}
项目:EIM    文件:MultiUserChat.java   
protected void finalize() throws Throwable {
    try {
        if (connection != null) {
            roomListenerMultiplexor.removeRoom(room);
            // Remove all the PacketListeners added to the connection by this chat
            for (PacketListener connectionListener : connectionListeners) {
                connection.removePacketListener(connectionListener);
            }
        }
    }
    catch (Exception e) {
        // Do nothing
    }
    super.finalize();
}
项目:EIM    文件:Node.java   
/**
 * Unregister a listener for publication events.
 * 
 * @param listener The handler to unregister
 */
public void removeItemEventListener(ItemEventListener listener)
{
    PacketListener conListener = itemEventToListenerMap.remove(listener);

    if (conListener != null)
        con.removePacketListener(conListener);
}
项目:EIM    文件:Node.java   
/**
 * Register a listener for configuration events.  This listener
 * will get called whenever the node's configuration changes.
 * 
 * @param listener The handler for the event
 */
public void addConfigurationListener(NodeConfigListener listener)
{
    PacketListener conListener = new NodeConfigTranslator(listener); 
    configEventToListenerMap.put(listener, conListener);
    con.addPacketListener(conListener, new EventContentFilter(EventElementType.configuration.toString()));
}
项目:EIM    文件:Node.java   
/**
 * Unregister a listener for configuration events.
 * 
 * @param listener The handler to unregister
 */
public void removeConfigurationListener(NodeConfigListener listener)
{
    PacketListener conListener = configEventToListenerMap .remove(listener);

    if (conListener != null)
        con.removePacketListener(conListener);
}