class Capybara::Poltergeist::Server

Attributes

custom_host[R]
fixed_port[R]
socket[R]
timeout[R]

Public Class Methods

new(fixed_port = nil, timeout = nil, custom_host = nil) click to toggle source
# File lib/capybara/poltergeist/server.rb, line 7
def initialize(fixed_port = nil, timeout = nil, custom_host = nil)
  @fixed_port = fixed_port
  @timeout    = timeout
  @custom_host = custom_host
  start
end

Public Instance Methods

host() click to toggle source
# File lib/capybara/poltergeist/server.rb, line 18
def host
  @socket.host
end
port() click to toggle source
# File lib/capybara/poltergeist/server.rb, line 14
def port
  @socket.port
end
restart() click to toggle source
# File lib/capybara/poltergeist/server.rb, line 34
def restart
  stop
  start
end
send(command) click to toggle source
# File lib/capybara/poltergeist/server.rb, line 39
def send(command)
  receive_timeout = nil # default
  if command.name == 'visit'
    command.args.push(timeout) # set the client set visit timeout parameter
    receive_timeout = timeout + 5 # Add a couple of seconds to let the client timeout first
  end
  @socket.send(command.id, command.message, receive_timeout) or raise DeadClient.new(command.message)
end
start() click to toggle source
# File lib/capybara/poltergeist/server.rb, line 26
def start
  @socket = WebSocketServer.new(fixed_port, timeout, custom_host)
end
stop() click to toggle source
# File lib/capybara/poltergeist/server.rb, line 30
def stop
  @socket.close
end
timeout=(sec) click to toggle source
# File lib/capybara/poltergeist/server.rb, line 22
def timeout=(sec)
  @timeout = @socket.timeout = sec
end