Class: WebSocket::ChannelInitializer

Inherits:
Server::ChannelInitializer
  • Object
show all
Defined in:
lib/websocket/channel_initializer.rb

Overview

The ChannelInitializer class programmatically specifies the configuration for the channel pipeline that will handle requests of the server.

Constant Summary collapse

HTTP_OBJECT_AGGREGATOR_BUFFER_BYTES_SIZE =
65_536

Instance Method Summary collapse

Constructor Details

#initialize(channel_group, options = {}) ⇒ ChannelInitializer

Returns a new instance of ChannelInitializer.



35
36
37
# File 'lib/websocket/channel_initializer.rb', line 35

def initialize(channel_group, options = {})
  super(channel_group, options)
end

Instance Method Details

#initChannel(channel) ⇒ Object

rubocop: disable Metrics/AbcSize rubocop: disable Metrics/MethodLength



41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
# File 'lib/websocket/channel_initializer.rb', line 41

def initChannel(channel)
  pipeline = channel.pipeline
  pipeline.addLast(ssl_handler(channel)) if ssl?
  pipeline.addLast(HttpServerCodec.new)
  pipeline.addLast(HttpObjectAggregator.new(HTTP_OBJECT_AGGREGATOR_BUFFER_BYTES_SIZE))
  pipeline.addLast(ChunkedWriteHandler.new)
  pipeline.addLast(IdleStateHandler.new(idle_reading, idle_writing, 0))
  pipeline.addLast(WebSocket::IdleHandler.new)
  pipeline.addLast(WebSocketServerCompressionHandler.new)
  pipeline.addLast(WebSocketServerProtocolHandler.new(web_socket_path, nil, true))
  pipeline.addLast(SslCipherInspector.new) if !ssl_context.nil? && inspect_ssl?
  pipeline.addLast(HttpStaticFileServerHandler.new(@options))
  add_user_handlers(pipeline)
  pipeline.addLast(default_handler)
end