Module: PusherFake::Server

Defined in:
lib/pusher-fake/server.rb,
lib/pusher-fake/server/application.rb,
lib/pusher-fake/server/chain_trap_handlers.rb

Overview

Socket and web server manager.

Defined Under Namespace

Modules: ChainTrapHandlers Classes: Application

Class Method Summary collapse

Class Method Details

.startObject

Start the servers.



14
15
16
17
18
19
20
21
# File 'lib/pusher-fake/server.rb', line 14

def start
  chain_trap_handlers

  EventMachine.run do
    start_web_server
    start_socket_server
  end
end

.start_socket_serverObject

Start the WebSocket server.



24
25
26
27
28
29
30
31
32
33
34
# File 'lib/pusher-fake/server.rb', line 24

def start_socket_server
  EventMachine::WebSocket.start(configuration.socket_options) do |socket|
    socket.onopen do
      connection = Connection.new(socket)
      connection.establish

      socket.onmessage { |data| connection.process(data) }
      socket.onclose   { Channel.remove(connection) }
    end
  end
end

.start_web_serverObject

Start the web server.



37
38
39
40
41
42
43
44
45
46
47
48
49
50
# File 'lib/pusher-fake/server.rb', line 37

def start_web_server
  options = configuration.web_options.dup
  host    = options.delete(:host)
  port    = options.delete(:port)

  Thin::Logging.silent = true
  Thin::Server.new(host, port, Application).tap do |server|
    options.each do |key, value|
      server.__send__(:"#{key}=", value)
    end

    server.start!
  end
end