Module: WebSocket
Constant Summary collapse
- LOG_SIZE =
100
Instance Method Summary collapse
-
#port ⇒ Object
return unused port.
- #run ⇒ Object
Instance Method Details
#port ⇒ Object
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 |
#run ⇒ Object
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.(&) socket.onerror(&onerror) end end |