Module: WebSocket

Extended by:
WebSocket
Included in:
WebSocket
Defined in:
lib/webtail/web_socket.rb

Constant Summary collapse

LOG_SIZE =
100

Instance Method Summary collapse

Instance Method Details

#portObject

return unused port



20
21
22
23
24
25
26
27
# File 'lib/webtail/web_socket.rb', line 20

def port
  @port ||= begin
    s = ::TCPServer.open(0)
    port = s.addr[1]
    s.close
    port
  end
end

#runObject



6
7
8
9
10
11
12
13
14
15
16
17
# File 'lib/webtail/web_socket.rb', line 6

def run
  Webtail.channel.subscribe do |msg|
    logs << msg
    logs.shift if logs.size > LOG_SIZE
  end

  EM::WebSocket.start(:host => "127.0.0.1", :port => port) do |socket|
    socket.onopen(&onopen(socket))
    socket.onmessage(&onmessage)
    socket.onerror(&onerror)
  end
end