当前位置: 首页>>代码示例>>Java>>正文


Java PacketListener类代码示例

本文整理汇总了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;
    }
}
 
开发者ID:FanHuaRan,项目名称:SmackStudy,代码行数:26,代码来源:XMPPUtil.java

示例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;
    }
}
 
开发者ID:FanHuaRan,项目名称:SmackStudy,代码行数:30,代码来源:XMPPUtil.java

示例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);
}
 
开发者ID:ice-coffee,项目名称:EIM,代码行数:31,代码来源:MultiUserChat.java

示例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;
}
 
开发者ID:ice-coffee,项目名称:EIM,代码行数:22,代码来源:PacketMultiplexListener.java

示例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);
}
 
开发者ID:wso2-incubator,项目名称:iot-server-appliances,代码行数:29,代码来源:XMPPCommunicationHandler.java

示例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);
}
 
开发者ID:wso2-incubator,项目名称:iot-server-appliances,代码行数:30,代码来源:XMPPCommunicationHandler.java

示例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);
}
 
开发者ID:CJC-ivotten,项目名称:androidPN-client.,代码行数:24,代码来源:CarbonManager.java

示例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));
}
 
开发者ID:huihoo,项目名称:olat,代码行数:27,代码来源:ClientManagerImpl.java

示例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));
}
 
开发者ID:huihoo,项目名称:olat,代码行数:27,代码来源:ClientManagerImpl.java

示例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);
}
 
开发者ID:huihoo,项目名称:olat,代码行数:21,代码来源:GroupChatJoinTask.java

示例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);

}
 
开发者ID:huihoo,项目名称:olat,代码行数:21,代码来源:GroupChatJoinTask.java

示例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;
}
 
开发者ID:ikantech,项目名称:xmppsupport_v2,代码行数:22,代码来源:PacketMultiplexListener.java

示例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);
}
 
开发者ID:ikantech,项目名称:xmppsupport_v2,代码行数:17,代码来源:RosterExchangeManager.java

示例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));
}
 
开发者ID:igniterealtime,项目名称:Fastpath-webchat,代码行数:25,代码来源:ChatPoller.java

示例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);
}
 
开发者ID:bdkoepke,项目名称:SmackPlus,代码行数:18,代码来源:XmppTransceiver.java


注:本文中的org.jivesoftware.smack.PacketListener类示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。