Search in sources :

Example 1 with WebSocket13Channel

use of io.undertow.websockets.core.protocol.version13.WebSocket13Channel in project undertow by undertow-io.

the class WebSocket13ClientHandshake method createChannel.

@Override
public WebSocketChannel createChannel(final StreamConnection channel, final String wsUri, final ByteBufferPool bufferPool, OptionMap options) {
    if (negotiation != null && negotiation.getSelectedExtensions() != null && !negotiation.getSelectedExtensions().isEmpty()) {
        List<WebSocketExtension> selected = negotiation.getSelectedExtensions();
        List<ExtensionFunction> negotiated = new ArrayList<>();
        if (selected != null && !selected.isEmpty()) {
            for (WebSocketExtension ext : selected) {
                for (ExtensionHandshake extHandshake : extensions) {
                    if (ext.getName().equals(extHandshake.getName())) {
                        negotiated.add(extHandshake.create());
                    }
                }
            }
        }
        return new WebSocket13Channel(channel, bufferPool, wsUri, negotiation.getSelectedSubProtocol(), true, !negotiated.isEmpty(), CompositeExtensionFunction.compose(negotiated), new HashSet<WebSocketChannel>(), options);
    } else {
        return new WebSocket13Channel(channel, bufferPool, wsUri, negotiation != null ? negotiation.getSelectedSubProtocol() : "", true, false, NoopExtensionFunction.INSTANCE, new HashSet<WebSocketChannel>(), options);
    }
}
Also used : WebSocketExtension(io.undertow.websockets.WebSocketExtension) NoopExtensionFunction(io.undertow.websockets.extensions.NoopExtensionFunction) ExtensionFunction(io.undertow.websockets.extensions.ExtensionFunction) CompositeExtensionFunction(io.undertow.websockets.extensions.CompositeExtensionFunction) WebSocketChannel(io.undertow.websockets.core.WebSocketChannel) ArrayList(java.util.ArrayList) ExtensionHandshake(io.undertow.websockets.extensions.ExtensionHandshake) WebSocket13Channel(io.undertow.websockets.core.protocol.version13.WebSocket13Channel)

Aggregations

WebSocketExtension (io.undertow.websockets.WebSocketExtension)1 WebSocketChannel (io.undertow.websockets.core.WebSocketChannel)1 WebSocket13Channel (io.undertow.websockets.core.protocol.version13.WebSocket13Channel)1 CompositeExtensionFunction (io.undertow.websockets.extensions.CompositeExtensionFunction)1 ExtensionFunction (io.undertow.websockets.extensions.ExtensionFunction)1 ExtensionHandshake (io.undertow.websockets.extensions.ExtensionHandshake)1 NoopExtensionFunction (io.undertow.websockets.extensions.NoopExtensionFunction)1 ArrayList (java.util.ArrayList)1