mirror of
https://codeberg.org/Mercury-IM/Smack
synced 2024-11-29 17:52:06 +01:00
Add support for XEP-0352: Client State Indication
SMACK-607
This commit is contained in:
parent
a2ffaeca1f
commit
b78a711ebd
5 changed files with 191 additions and 0 deletions
|
@ -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.
|
| 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. |
|
| [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)
|
Legacy Smack Extensions and currently supported XEPs by Smack (smack-legacy)
|
||||||
|
|
|
@ -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 <a href="http://xmpp.org/extensions/xep-0352.html">XEP-0352: Client State Indication</a>
|
||||||
|
*
|
||||||
|
*/
|
||||||
|
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");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
|
@ -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 <a href="http://xmpp.org/extensions/xep-0352.html">XEP-0352: Client State Indication</a>
|
||||||
|
*
|
||||||
|
*/
|
||||||
|
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;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
|
@ -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;
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
|
@ -31,4 +31,11 @@
|
||||||
<className>org.jivesoftware.smackx.carbons.provider.CarbonManagerProvider</className>
|
<className>org.jivesoftware.smackx.carbons.provider.CarbonManagerProvider</className>
|
||||||
</extensionProvider>
|
</extensionProvider>
|
||||||
|
|
||||||
|
<!-- XEP-0352 Client State Indication -->
|
||||||
|
<streamFeatureProvider>
|
||||||
|
<elementName>csi</elementName>
|
||||||
|
<namespace>urn:xmpp:csi:0</namespace>
|
||||||
|
<className>org.jivesoftware.smackx.csi.provider.ClientStateIndicationFeatureProvider</className>
|
||||||
|
</streamFeatureProvider>
|
||||||
|
|
||||||
</smackProviders>
|
</smackProviders>
|
||||||
|
|
Loading…
Reference in a new issue