Search in sources :

Example 1 with WebSocketFactory

use of org.jivesoftware.smack.websocket.impl.WebSocketFactory in project Smack by igniterealtime.

the class XmppConnectionDescriptor method buildWebsocketDescriptor.

public static XmppConnectionDescriptor<ModularXmppClientToServerConnection, ModularXmppClientToServerConnectionConfiguration, ModularXmppClientToServerConnectionConfiguration.Builder> buildWebsocketDescriptor(String nickname, Class<? extends WebSocketFactory> factoryClass) throws InstantiationException, IllegalAccessException, IllegalArgumentException, InvocationTargetException, NoSuchMethodException, SecurityException {
    WebSocketFactory factory;
    try {
        Field instanceField = factoryClass.getField("INSTANCE");
        factory = (WebSocketFactory) instanceField.get(null);
    } catch (NoSuchFieldException | IllegalArgumentException | IllegalAccessException e) {
        factory = factoryClass.getConstructor().newInstance();
    }
    WebSocketFactory finalFactory = factory;
    return XmppConnectionDescriptor.buildWith(ModularXmppClientToServerConnection.class, ModularXmppClientToServerConnectionConfiguration.class, ModularXmppClientToServerConnectionConfiguration.Builder.class).withNickname(nickname).applyExtraConfguration(cb -> {
        cb.removeAllModules();
        ModularXmppClientToServerConnectionModuleDescriptor webSocketModuleDescriptor = XmppWebSocketTransportModuleDescriptor.getBuilder(cb).setWebSocketFactory(finalFactory).build();
        cb.addModule(webSocketModuleDescriptor);
    }).build();
}
Also used : Arrays(java.util.Arrays) XmppWebSocketTransportModuleDescriptor(org.jivesoftware.smack.websocket.XmppWebSocketTransportModuleDescriptor) Collection(java.util.Collection) Field(java.lang.reflect.Field) Constructor(java.lang.reflect.Constructor) InvocationTargetException(java.lang.reflect.InvocationTargetException) ArrayList(java.util.ArrayList) ConnectionConfiguration(org.jivesoftware.smack.ConnectionConfiguration) List(java.util.List) Consumer(org.jivesoftware.smack.util.Consumer) AbstractXMPPConnection(org.jivesoftware.smack.AbstractXMPPConnection) Modifier(java.lang.reflect.Modifier) ModularXmppClientToServerConnectionConfiguration(org.jivesoftware.smack.c2s.ModularXmppClientToServerConnectionConfiguration) ModularXmppClientToServerConnectionModuleDescriptor(org.jivesoftware.smack.c2s.ModularXmppClientToServerConnectionModuleDescriptor) Method(java.lang.reflect.Method) Collections(java.util.Collections) XMPPConnection(org.jivesoftware.smack.XMPPConnection) ModularXmppClientToServerConnection(org.jivesoftware.smack.c2s.ModularXmppClientToServerConnection) WebSocketFactory(org.jivesoftware.smack.websocket.impl.WebSocketFactory) Field(java.lang.reflect.Field) ModularXmppClientToServerConnectionModuleDescriptor(org.jivesoftware.smack.c2s.ModularXmppClientToServerConnectionModuleDescriptor) ModularXmppClientToServerConnectionConfiguration(org.jivesoftware.smack.c2s.ModularXmppClientToServerConnectionConfiguration) WebSocketFactory(org.jivesoftware.smack.websocket.impl.WebSocketFactory) ModularXmppClientToServerConnection(org.jivesoftware.smack.c2s.ModularXmppClientToServerConnection)

Aggregations

Constructor (java.lang.reflect.Constructor)1 Field (java.lang.reflect.Field)1 InvocationTargetException (java.lang.reflect.InvocationTargetException)1 Method (java.lang.reflect.Method)1 Modifier (java.lang.reflect.Modifier)1 ArrayList (java.util.ArrayList)1 Arrays (java.util.Arrays)1 Collection (java.util.Collection)1 Collections (java.util.Collections)1 List (java.util.List)1 AbstractXMPPConnection (org.jivesoftware.smack.AbstractXMPPConnection)1 ConnectionConfiguration (org.jivesoftware.smack.ConnectionConfiguration)1 XMPPConnection (org.jivesoftware.smack.XMPPConnection)1 ModularXmppClientToServerConnection (org.jivesoftware.smack.c2s.ModularXmppClientToServerConnection)1 ModularXmppClientToServerConnectionConfiguration (org.jivesoftware.smack.c2s.ModularXmppClientToServerConnectionConfiguration)1 ModularXmppClientToServerConnectionModuleDescriptor (org.jivesoftware.smack.c2s.ModularXmppClientToServerConnectionModuleDescriptor)1 Consumer (org.jivesoftware.smack.util.Consumer)1 XmppWebSocketTransportModuleDescriptor (org.jivesoftware.smack.websocket.XmppWebSocketTransportModuleDescriptor)1 WebSocketFactory (org.jivesoftware.smack.websocket.impl.WebSocketFactory)1