Module: PusherFake::Server

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

Overview

Socket and web server manager.

Defined Under Namespace

Classes: Application

Class Method Summary collapse

Class Method Details

.startObject

Start the servers.


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

def start
  EventMachine.run do
    start_web_server
    start_socket_server
  end
end

.start_socket_serverObject

Start the WebSocket server.


21
22
23
24
25
26
27
28
29
30
31
# File 'lib/pusher-fake/server.rb', line 21

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.


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

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