diff --git a/documentation/extensions/index.md b/documentation/extensions/index.md index a65ebe861..9ab21ed36 100644 --- a/documentation/extensions/index.md +++ b/documentation/extensions/index.md @@ -67,6 +67,7 @@ Experimental Smack Extensions and currently supported XEPs by Smack (smack-exper |---------------------------------------------|----------------------------------------------------------|----------------------------------------------------------------------------------------------------------| | Message Carbons | [XEP-0280](http://xmpp.org/extensions/xep-0280.html) | Keep all IM clients for a user engaged in a conversation, by carbon-copy outbound messages to all interested resources. | [HTTP over XMPP transport](hoxt.html) | [XEP-0332](http://xmpp.org/extensions/xep-0332.html) | Allows to transport HTTP communication over XMPP peer-to-peer networks. | +| Client State Indication | [XEP-0352](http://xmpp.org/extensions/xep-0352.html) | A way for the client to indicate its active/inactive state. | Legacy Smack Extensions and currently supported XEPs by Smack (smack-legacy) diff --git a/smack-experimental/src/main/java/org/jivesoftware/smackx/csi/ClientStateIndicationManager.java b/smack-experimental/src/main/java/org/jivesoftware/smackx/csi/ClientStateIndicationManager.java new file mode 100644 index 000000000..f7d2f9bc4 --- /dev/null +++ b/smack-experimental/src/main/java/org/jivesoftware/smackx/csi/ClientStateIndicationManager.java @@ -0,0 +1,49 @@ +/** + * + * Copyright © 2014 Florian Schmaus + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package org.jivesoftware.smackx.csi; + +import org.jivesoftware.smack.SmackException.NotConnectedException; +import org.jivesoftware.smack.XMPPConnection; +import org.jivesoftware.smackx.csi.packet.ClientStateIndication; + +/** + * + * @see XEP-0352: Client State Indication + * + */ +public class ClientStateIndicationManager { + + public static void active(XMPPConnection connection) throws NotConnectedException { + throwIaeIfNotSupported(connection); + connection.send(ClientStateIndication.Active.INSTANCE); + } + + public static void inactive(XMPPConnection connection) throws NotConnectedException { + throwIaeIfNotSupported(connection); + connection.send(ClientStateIndication.Inactive.INSTANCE); + } + + public static boolean isSupported(XMPPConnection connection) { + return connection.hasFeature(ClientStateIndication.Feature.ELEMENT, ClientStateIndication.NAMESPACE); + } + + private static void throwIaeIfNotSupported(XMPPConnection connection) { + if (!isSupported(connection)) { + throw new IllegalArgumentException("Client State Indication not supported by server"); + } + } +} diff --git a/smack-experimental/src/main/java/org/jivesoftware/smackx/csi/packet/ClientStateIndication.java b/smack-experimental/src/main/java/org/jivesoftware/smackx/csi/packet/ClientStateIndication.java new file mode 100644 index 000000000..790a90259 --- /dev/null +++ b/smack-experimental/src/main/java/org/jivesoftware/smackx/csi/packet/ClientStateIndication.java @@ -0,0 +1,98 @@ +/** + * + * Copyright © 2014 Florian Schmaus + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package org.jivesoftware.smackx.csi.packet; + +import org.jivesoftware.smack.packet.FullStreamElement; +import org.jivesoftware.smack.packet.PacketExtension; + +/** + * + * @see XEP-0352: Client State Indication + * + */ +public class ClientStateIndication { + public static final String NAMESPACE = "urn:xmpp:csi:0"; + + public static class Active extends FullStreamElement { + public static final Active INSTANCE = new Active(); + public static final String ELEMENT = "active"; + + private Active() { + } + + @Override + public String getNamespace() { + return NAMESPACE; + } + + @Override + public String getElementName() { + return ELEMENT; + } + + @Override + public String toXML() { + return '<' + ELEMENT + " xmlns='" + NAMESPACE + "'/>"; + } + } + + public static class Inactive extends FullStreamElement { + public static final Inactive INSTANCE = new Inactive(); + public static final String ELEMENT = "inactive"; + + private Inactive() { + } + + @Override + public String getNamespace() { + return NAMESPACE; + } + + @Override + public String getElementName() { + return ELEMENT; + } + + @Override + public String toXML() { + return '<' + ELEMENT + " xmlns='" + NAMESPACE + "'/>"; + } + } + + public static class Feature implements PacketExtension { + public static final Feature INSTANCE = new Feature(); + public static final String ELEMENT = "csi"; + + private Feature() { + } + + @Override + public String getElementName() { + return ELEMENT; + } + + @Override + public String toXML() { + return '<' + ELEMENT + " xmlns='" + NAMESPACE + "'/>"; + } + + @Override + public String getNamespace() { + return NAMESPACE; + } + } +} diff --git a/smack-experimental/src/main/java/org/jivesoftware/smackx/csi/provider/ClientStateIndicationFeatureProvider.java b/smack-experimental/src/main/java/org/jivesoftware/smackx/csi/provider/ClientStateIndicationFeatureProvider.java new file mode 100644 index 000000000..2facb7047 --- /dev/null +++ b/smack-experimental/src/main/java/org/jivesoftware/smackx/csi/provider/ClientStateIndicationFeatureProvider.java @@ -0,0 +1,36 @@ +/** + * + * Copyright © 2014 Florian Schmaus + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package org.jivesoftware.smackx.csi.provider; + +import java.io.IOException; + +import org.jivesoftware.smack.SmackException; +import org.jivesoftware.smack.packet.PacketExtension; +import org.jivesoftware.smack.provider.StreamFeatureProvider; +import org.jivesoftware.smackx.csi.packet.ClientStateIndication; +import org.xmlpull.v1.XmlPullParser; +import org.xmlpull.v1.XmlPullParserException; + +public class ClientStateIndicationFeatureProvider implements StreamFeatureProvider { + + @Override + public PacketExtension parseStreamFeature(XmlPullParser parser) + throws XmlPullParserException, IOException, SmackException { + return ClientStateIndication.Feature.INSTANCE; + } + +} diff --git a/smack-experimental/src/main/resources/org.jivesoftware.smackx/experimental.providers b/smack-experimental/src/main/resources/org.jivesoftware.smackx/experimental.providers index 88b82db76..4aff6fcf3 100644 --- a/smack-experimental/src/main/resources/org.jivesoftware.smackx/experimental.providers +++ b/smack-experimental/src/main/resources/org.jivesoftware.smackx/experimental.providers @@ -31,4 +31,11 @@ org.jivesoftware.smackx.carbons.provider.CarbonManagerProvider + + + csi + urn:xmpp:csi:0 + org.jivesoftware.smackx.csi.provider.ClientStateIndicationFeatureProvider + +