2011-10-27 23:34:14 +01:00
|
|
|
module Capybara::Poltergeist
|
|
|
|
class Server
|
2013-01-31 20:44:55 +00:00
|
|
|
attr_reader :socket, :fixed_port, :timeout
|
2011-10-27 23:34:14 +01:00
|
|
|
|
2013-02-04 20:25:13 +00:00
|
|
|
def initialize(fixed_port = nil, timeout = nil)
|
2013-01-31 20:44:55 +00:00
|
|
|
@fixed_port = fixed_port
|
|
|
|
@timeout = timeout
|
2011-10-27 23:34:14 +01:00
|
|
|
start
|
|
|
|
end
|
|
|
|
|
2013-01-31 20:44:55 +00:00
|
|
|
def port
|
|
|
|
@socket.port
|
|
|
|
end
|
|
|
|
|
2012-01-13 13:10:30 +00:00
|
|
|
def timeout=(sec)
|
|
|
|
@timeout = @socket.timeout = sec
|
|
|
|
end
|
|
|
|
|
2011-10-27 23:34:14 +01:00
|
|
|
def start
|
2013-01-31 20:44:55 +00:00
|
|
|
@socket = WebSocketServer.new(fixed_port, timeout)
|
2011-10-27 23:34:14 +01:00
|
|
|
end
|
|
|
|
|
2012-02-29 13:51:11 +00:00
|
|
|
def stop
|
2012-01-13 13:10:30 +00:00
|
|
|
@socket.close
|
2012-02-29 13:51:11 +00:00
|
|
|
end
|
|
|
|
|
|
|
|
def restart
|
|
|
|
stop
|
|
|
|
start
|
2011-10-27 23:34:14 +01:00
|
|
|
end
|
|
|
|
|
|
|
|
def send(message)
|
2012-01-13 13:10:30 +00:00
|
|
|
@socket.send(message) or raise DeadClient.new(message)
|
2011-10-27 23:34:14 +01:00
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|