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(port:) ⇒ Server

Returns a new instance of Server.



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

def initialize(port:)
  @port = port
end

Instance Attribute Details

#portObject (readonly)

Returns the value of attribute port.



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

def port
  @port
end

Instance Method Details

#channel_repositoryObject



19
20
21
# File 'lib/action_channels/server.rb', line 19

def channel_repository
  @channel_repository ||= ChannelRepository.new
end

#process_client(client) ⇒ Object



23
24
25
26
27
28
# File 'lib/action_channels/server.rb', line 23

def process_client(client)
  client.on :message, callback_on_message(client)
  client.on :close, callback_on_close(client)

  client
end

#runObject



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

def run
  NIO::WebSocket.listen port: port do |client|
    process_client client
  end

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