本文整理汇总了Java中org.jivesoftware.smack.StanzaListener类的典型用法代码示例。如果您正苦于以下问题:Java StanzaListener类的具体用法?Java StanzaListener怎么用?Java StanzaListener使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
StanzaListener类属于org.jivesoftware.smack包,在下文中一共展示了StanzaListener类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: addStanzaIdAcknowledgedListener
import org.jivesoftware.smack.StanzaListener; //导入依赖的package包/类
/**
* Add a new Stanza ID acknowledged listener for the given ID.
* <p>
* The listener will be invoked if the stanza with the given ID was acknowledged by the server. It will
* automatically be removed after the listener was run.
* </p>
*
* @param id the stanza ID.
* @param listener the listener to invoke.
* @return the previous listener for this stanza ID or null.
* @throws StreamManagementNotEnabledException if Stream Management is not enabled.
*/
public StanzaListener addStanzaIdAcknowledgedListener(final String id, StanzaListener listener) throws StreamManagementNotEnabledException {
// Prevent users from adding callbacks that will never get removed
if (!smWasEnabledAtLeastOnce) {
throw new StreamManagementException.StreamManagementNotEnabledException();
}
// Remove the listener after max. 12 hours
final int removeAfterSeconds = Math.min(getMaxSmResumptionTime(), 12 * 60 * 60);
schedule(new Runnable() {
@Override
public void run() {
stanzaIdAcknowledgedListeners.remove(id);
}
}, removeAfterSeconds, TimeUnit.SECONDS);
return stanzaIdAcknowledgedListeners.put(id, listener);
}
示例2: MultiUserChatManager
import org.jivesoftware.smack.StanzaListener; //导入依赖的package包/类
private MultiUserChatManager(XMPPConnection connection) {
super(connection);
// Listens for all messages that include a MUCUser extension and fire the invitation
// listeners if the message includes an invitation.
StanzaListener invitationPacketListener = new StanzaListener() {
public void processPacket(Stanza packet) {
final Message message = (Message) packet;
// Get the MUCUser extension
final MUCUser mucUser = MUCUser.from(message);
// Check if the MUCUser extension includes an invitation
if (mucUser.getInvite() != null) {
// Fire event for invitation listeners
final MultiUserChat muc = getMultiUserChat(packet.getFrom());
for (final InvitationListener listener : invitationsListeners) {
listener.invitationReceived(connection(), muc, mucUser.getInvite().getFrom(),
mucUser.getInvite().getReason(), mucUser.getPassword(), message);
}
}
}
};
connection.addAsyncStanzaListener(invitationPacketListener, INVITATION_FILTER);
}
示例3: shouldConfirmReceivedDataPacket
import org.jivesoftware.smack.StanzaListener; //导入依赖的package包/类
/**
* Valid data packets should be confirmed.
*
* @throws Exception should not happen
*/
@Test
public void shouldConfirmReceivedDataPacket() throws Exception {
// verify data packet confirmation is of type RESULT
protocol.addResponse(null, Verification.requestTypeRESULT);
InBandBytestreamSession session = new InBandBytestreamSession(connection, initBytestream,
initiatorJID);
InputStream inputStream = session.getInputStream();
StanzaListener listener = Whitebox.getInternalState(inputStream, StanzaListener.class);
String base64Data = Base64.encode("Data");
DataPacketExtension dpe = new DataPacketExtension(sessionID, 0, base64Data);
Data data = new Data(dpe);
listener.processPacket(data);
protocol.verifyAll();
}
示例4: sendPushRegistration
import org.jivesoftware.smack.StanzaListener; //导入依赖的package包/类
private void sendPushRegistration(final String regId) {
IQ iq = PushRegistration.register(DEFAULT_PUSH_PROVIDER, regId);
try {
iq.setTo(JidCreate.from("push", mServer.getNetwork(), ""));
}
catch (XmppStringprepException e) {
Log.w(TAG, "error parsing JID: " + e.getCausingString(), e);
// report it because it's a big deal
ReportingManager.logException(e);
return;
}
sendIqWithReply(iq, true, new StanzaListener() {
@Override
public void processStanza(Stanza packet) throws NotConnectedException {
if (mPushService != null)
mPushService.setRegisteredOnServer(regId != null);
}
}, null);
}
示例5: sendPushUnregistration
import org.jivesoftware.smack.StanzaListener; //导入依赖的package包/类
private void sendPushUnregistration() {
IQ iq = PushRegistration.unregister(DEFAULT_PUSH_PROVIDER);
try {
iq.setTo(JidCreate.from("push", mServer.getNetwork(), ""));
}
catch (XmppStringprepException e) {
Log.w(TAG, "error parsing JID: " + e.getCausingString(), e);
// report it because it's a big deal
ReportingManager.logException(e);
return;
}
sendIqWithReply(iq, true, new StanzaListener() {
@Override
public void processStanza(Stanza packet) throws NotConnectedException {
if (mPushService != null)
mPushService.setRegisteredOnServer(false);
}
}, null);
}
示例6: addStanzaIdAcknowledgedListener
import org.jivesoftware.smack.StanzaListener; //导入依赖的package包/类
/**
* Add a new Stanza ID acknowledged listener for the given ID.
* <p>
* The listener will be invoked if the stanza with the given ID was acknowledged by the server. It will
* automatically be removed after the listener was run.
* </p>
*
* @param id the stanza ID.
* @param listener the listener to invoke.
* @return the previous listener for this stanza ID or null.
* @throws StreamManagementNotEnabledException if Stream Management is not enabled.
*/
public StanzaListener addStanzaIdAcknowledgedListener(final String id, StanzaListener listener) throws StreamManagementNotEnabledException {
// Prevent users from adding callbacks that will never get removed
if (!smWasEnabledAtLeastOnce) {
throw new StreamManagementException.StreamManagementNotEnabledException();
}
// Remove the listener after max. 12 hours
final int removeAfterSeconds = Math.min(getMaxSmResumptionTime(), 12 * 60 * 60);
schedule(new Runnable() {
@Override
public void run() {
stanzaIdAcknowledgedListeners.remove(id);
}
}, removeAfterSeconds, TimeUnit.SECONDS);
return stanzaIdAcknowledgedListeners.put(id, listener);
}
示例7: sendCarbonsEnabled
import org.jivesoftware.smack.StanzaListener; //导入依赖的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
* @throws NotConnectedException
*/
public void sendCarbonsEnabled(final boolean new_state) throws NotConnectedException {
IQ setIQ = carbonsEnabledIQ(new_state);
connection().sendIqWithResponseCallback(setIQ, new StanzaListener() {
public void processPacket(Stanza packet) {
enabled_state = new_state;
}
});
}
示例8: RosterExchangeManager
import org.jivesoftware.smack.StanzaListener; //导入依赖的package包/类
/**
* Creates a new roster exchange manager.
*
* @param connection an XMPPConnection which is used to send and receive messages.
*/
public RosterExchangeManager(XMPPConnection connection) {
weakRefConnection = new WeakReference<XMPPConnection>(connection);
// Listens for all roster exchange packets and fire the roster exchange listeners.
packetListener = new StanzaListener() {
public void processPacket(Stanza packet) {
Message message = (Message) packet;
RosterExchange rosterExchange =
(RosterExchange) message.getExtension(ELEMENT, NAMESPACE);
// Fire event for roster exchange listeners
fireRosterExchangeListeners(message.getFrom(), rosterExchange.getRosterEntries());
}
};
connection.addAsyncStanzaListener(packetListener, PACKET_FILTER);
}
示例9: ChatManager
import org.jivesoftware.smack.StanzaListener; //导入依赖的package包/类
private ChatManager(XMPPConnection connection) {
super(connection);
// Add a listener for all message packets so that we can deliver
// messages to the best Chat instance available.
connection.addSyncStanzaListener(new StanzaListener() {
public void processPacket(Stanza packet) {
Message message = (Message) packet;
Chat chat;
if (message.getThread() == null) {
chat = getUserChat(message.getFrom());
}
else {
chat = getThreadChat(message.getThread());
}
if(chat == null) {
chat = createChat(message);
}
// The chat could not be created, abort here
if (chat == null)
return;
deliverMessage(chat, message);
}
}, packetFilter);
INSTANCES.put(connection, this);
}
示例10: addItemEventListener
import org.jivesoftware.smack.StanzaListener; //导入依赖的package包/类
/**
* Register a listener for item publication events. This
* listener will get called whenever an item is published to
* this node.
*
* @param listener The handler for the event
*/
@SuppressWarnings("unchecked")
public void addItemEventListener(@SuppressWarnings("rawtypes") ItemEventListener listener)
{
StanzaListener conListener = new ItemEventTranslator(listener);
itemEventToListenerMap.put(listener, conListener);
con.addSyncStanzaListener(conListener, new EventContentFilter(EventElementType.items.toString(), "item"));
}
示例11: removeItemEventListener
import org.jivesoftware.smack.StanzaListener; //导入依赖的package包/类
/**
* Unregister a listener for publication events.
*
* @param listener The handler to unregister
*/
public void removeItemEventListener(@SuppressWarnings("rawtypes") ItemEventListener listener)
{
StanzaListener conListener = itemEventToListenerMap.remove(listener);
if (conListener != null)
con.removeSyncStanzaListener(conListener);
}
示例12: addConfigurationListener
import org.jivesoftware.smack.StanzaListener; //导入依赖的package包/类
/**
* 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)
{
StanzaListener conListener = new NodeConfigTranslator(listener);
configEventToListenerMap.put(listener, conListener);
con.addSyncStanzaListener(conListener, new EventContentFilter(EventElementType.configuration.toString()));
}
示例13: removeConfigurationListener
import org.jivesoftware.smack.StanzaListener; //导入依赖的package包/类
/**
* Unregister a listener for configuration events.
*
* @param listener The handler to unregister
*/
public void removeConfigurationListener(NodeConfigListener listener)
{
StanzaListener conListener = configEventToListenerMap .remove(listener);
if (conListener != null)
con.removeSyncStanzaListener(conListener);
}
示例14: addItemDeleteListener
import org.jivesoftware.smack.StanzaListener; //导入依赖的package包/类
/**
* Register an listener for item delete events. This listener
* gets called whenever an item is deleted from the node.
*
* @param listener The handler for the event
*/
public void addItemDeleteListener(ItemDeleteListener listener)
{
StanzaListener delListener = new ItemDeleteTranslator(listener);
itemDeleteToListenerMap.put(listener, delListener);
EventContentFilter deleteItem = new EventContentFilter(EventElementType.items.toString(), "retract");
EventContentFilter purge = new EventContentFilter(EventElementType.purge.toString());
con.addSyncStanzaListener(delListener, new OrFilter(deleteItem, purge));
}
示例15: removeItemDeleteListener
import org.jivesoftware.smack.StanzaListener; //导入依赖的package包/类
/**
* Unregister a listener for item delete events.
*
* @param listener The handler to unregister
*/
public void removeItemDeleteListener(ItemDeleteListener listener)
{
StanzaListener conListener = itemDeleteToListenerMap .remove(listener);
if (conListener != null)
con.removeSyncStanzaListener(conListener);
}