Class: ActionChannels::Server

Inherits:
Object
  • Object
show all
Defined in:
lib/action_channels/server.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(options) ⇒ Server

Returns a new instance of Server.



5
6
7
8
# File 'lib/action_channels/server.rb', line 5

def initialize(options)
  @port = options.fetch(:port)
  @channel_repository = ChannelRepository.new options.fetch(:channels, [])
end

Instance Attribute Details

#channel_repositoryObject (readonly)

Returns the value of attribute channel_repository.



3
4
5
# File 'lib/action_channels/server.rb', line 3

def channel_repository
  @channel_repository
end

#portObject (readonly)

Returns the value of attribute port.



3
4
5
# File 'lib/action_channels/server.rb', line 3

def port
  @port
end

Instance Method Details

#process_client(client) ⇒ Object



18
19
20
21
22
23
24
25
# File 'lib/action_channels/server.rb', line 18

def process_client(client)
  client.on :message, callback_on_message(client)
  client.on :close, callback_on_close(client)
  client.on :error, callback_on_error(client)
  client.on :io_error, callback_on_io_error(client)

  client
end

#runObject



10
11
12
13
14
15
16
# File 'lib/action_channels/server.rb', line 10

def run
  NIO::WebSocket.listen port: port do |driver|
    process_client Driver.new(driver)
  end

  ActionChannels.logger.info "Server started on port: #{port}"
end