CarrotChat v2.8.60.240131版本的 MD5 值为:2baf8b9f31830b86b5c5a85ae6b47e05
以下内容为反编译后的 AMPManager.java 源代码,内容仅作参考
package org.jivesoftware.smackx.amp;
import org.jivesoftware.smack.ConnectionCreationListener;
import org.jivesoftware.smack.SmackException;
import org.jivesoftware.smack.XMPPConnection;
import org.jivesoftware.smack.XMPPConnectionRegistry;
import org.jivesoftware.smack.XMPPException;
import org.jivesoftware.smackx.amp.packet.AMPExtension;
import org.jivesoftware.smackx.disco.ServiceDiscoveryManager;
public class AMPManager {
static {
XMPPConnectionRegistry.addConnectionCreationListener(new ConnectionCreationListener() {
@Override
public void connectionCreated(XMPPConnection xMPPConnection) {
AMPManager.setServiceEnabled(xMPPConnection, true);
}
});
}
public static boolean isActionSupported(XMPPConnection xMPPConnection, AMPExtension.Action action) throws SmackException.NoResponseException, XMPPException.XMPPErrorException, SmackException.NotConnectedException, InterruptedException {
return isFeatureSupportedByServer(xMPPConnection, "http://jabber.org/protocol/amp?action=" + action.toString());
}
public static boolean isConditionSupported(XMPPConnection xMPPConnection, String str) throws SmackException.NoResponseException, XMPPException.XMPPErrorException, SmackException.NotConnectedException, InterruptedException {
return isFeatureSupportedByServer(xMPPConnection, "http://jabber.org/protocol/amp?condition=" + str);
}
private static boolean isFeatureSupportedByServer(XMPPConnection xMPPConnection, String str) throws SmackException.NoResponseException, XMPPException.XMPPErrorException, SmackException.NotConnectedException, InterruptedException {
return ServiceDiscoveryManager.getInstanceFor(xMPPConnection).serverSupportsFeature(str);
}
public static boolean isServiceEnabled(XMPPConnection xMPPConnection) {
xMPPConnection.getXMPPServiceDomain();
return ServiceDiscoveryManager.getInstanceFor(xMPPConnection).includesFeature(AMPExtension.NAMESPACE);
}
public static synchronized void setServiceEnabled(XMPPConnection xMPPConnection, boolean z) {
synchronized (AMPManager.class) {
if (isServiceEnabled(xMPPConnection) == z) {
return;
}
if (z) {
ServiceDiscoveryManager.getInstanceFor(xMPPConnection).addFeature(AMPExtension.NAMESPACE);
} else {
ServiceDiscoveryManager.getInstanceFor(xMPPConnection).removeFeature(AMPExtension.NAMESPACE);
}
}
}
}